做网站要学会什么,商丘企业网站服务,动态图表网站,建筑产业大数据综合服务平台我们使用从一些开源项目复制的这个类来读取TGA文件.它真的很老了.它只能处理具有最基本编码的Targa文件.试试看.public class TargaReader{public static Image getImage(String fileName) throws IOException{File f new File(fileName);byte[] buf new byte[(int)f.length(…我们使用从一些开源项目复制的这个类来读取TGA文件.它真的很老了.它只能处理具有最基本编码的Targa文件.试试看.public class TargaReader{public static Image getImage(String fileName) throws IOException{File f new File(fileName);byte[] buf new byte[(int)f.length()];BufferedInputStream bis new BufferedInputStream(new FileInputStream(f));bis.read(buf);bis.close();return decode(buf);}private static int offset;private static int btoi(byte b){int a b;return (a0?256a:a);}private static int read(byte[] buf){return btoi(buf[offset]);}public static Image decode(byte[] buf) throws IOException{offset 0;// Reading headerfor (int i0;i12;i)read(buf);int width read(buf)(read(buf)8);int height read(buf)(read(buf)8);read(buf);read(buf);// Reading dataint n width*height;int[] pixels new int[n];int idx0;while (n0){int nb read(buf);if ((nb0x80)0){for (int i0;inb;i){int b read(buf);int g read(buf);int r read(buf);pixels[idx] 0xff000000 | (r16) | (g8) | b;}}else{nb 0x7f;int b read(buf);int g read(buf);int r read(buf);int v 0xff000000 | (r16) | (g8) | b;for (int i0;inb;i)pixels[idx] v;}n-nb1;}BufferedImage bimg new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);bimg.setRGB(0,0,width,height,pixels,0,width);return bimg;}}