51,402
社区成员




public class RawConvert
{
public static void main(String args[])
{
String path = args[0];
try{
File fl = new File(path);
if(fl.isFile()){
InputStream fip = new FileInputStream(fl);
DataInputStream fis = new DataInputStream(fip);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int num = 0;
byte[] ima = null;
int w = 426;
int h = 408;
while((num = fis.read(buf)) != -1) {
bos.write(buf,0,num);
}
ima = bos.toByteArray();
int[] bof = {0,1,2,3};
int[] bits = {4,4,4,4};
DataBuffer duf = new DataBufferByte(ima,ima.length);
WritableRaster ras = Raster.createInterleavedRaster(duf,w,h,4 * w,4,bof,null);
ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.TYPE_RGB),bits,true,false,3,DataBuffer.TYPE_BYTE);
BufferedImage img = new BufferedImage(cm,ras,false,null);
System.out.println(img);
ImageIO.write(img,"PNG",new File(path + ".png"));
fis.close();
fip.close();
}
catch(FileNotFoundException e1){
System.out.println("File Not Found:" + e1);
}
catch(IOException e2){
System.out.println("File Canot Read:" + e2);
}
catch(NullPointerException e3){
System.out.println("Null Parame:" + e3);
}
catch(Exception e4){
System.out.println("Unknow Error:" + e4);
}
}
}