当前位置: 技术问答>java相关
如何把BufferedImage 图像存储到磁盘啊?急
来源: 互联网 发布时间:2015-07-18
本文导语: 谢谢了! | public void saveImage(Image pImage,String ofileDirAndName) throws IOException { BufferedImage bimg = null; int w = pImage.getWidth(null); int h = pImage.getHeight(null); ...
谢谢了!
|
public void saveImage(Image pImage,String ofileDirAndName) throws IOException
{
BufferedImage bimg = null;
int w = pImage.getWidth(null);
int h = pImage.getHeight(null);
int [] pixels = new int[w * h];
PixelGrabber pg = new PixelGrabber(pImage,0, 0, w, h,pixels, 0, w);
try {
pg.grabPixels();
}
catch(InterruptedException e) {
e.printStackTrace();
}
//System.out.println("mStrUserPath:"+mStrUserPath);
File userDir = new File(this.mStrUserPath);
File snapShotDir = new File(userDir,"快照图象");
System.out.println("2");
this.bout= new ByteArrayOutputStream();System.out.println("3");
//---need a BufferedImage for JPEG Codec.
//---BufferedImage is a subclass of Image.
BufferedImage bufferedImage= new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
bufferedImage.setRGB(0,0,w,h,pixels,0,w);
//---sharpen the image.
float[] sharpKernel = { 0.0f, -1.0f, 0.0f,
-1.0f, 5.0f, -1.0f,
0.0f, -1.0f, 0.0f };System.out.println("5");
BufferedImageOp sharpen= new ConvolveOp( new Kernel(3, 3, sharpKernel), ConvolveOp.EDGE_NO_OP, null);
BufferedImage sharp= sharpen.filter( bufferedImage, null );
//---create an encoder object for the BufferedImage.
JPEGEncodeParam jpegParam= JPEGCodec.getDefaultJPEGEncodeParam( sharp );
jpegParam.setQuality( 1.0f, false );
JPEGImageEncoder jpeg= JPEGCodec.createJPEGEncoder( bout, jpegParam );
//---encode the BufferedImage.
jpeg.encode( bufferedImage );
this.bout.writeTo(new FileOutputStream(ofileDirAndName));
}
分来分来。
{
BufferedImage bimg = null;
int w = pImage.getWidth(null);
int h = pImage.getHeight(null);
int [] pixels = new int[w * h];
PixelGrabber pg = new PixelGrabber(pImage,0, 0, w, h,pixels, 0, w);
try {
pg.grabPixels();
}
catch(InterruptedException e) {
e.printStackTrace();
}
//System.out.println("mStrUserPath:"+mStrUserPath);
File userDir = new File(this.mStrUserPath);
File snapShotDir = new File(userDir,"快照图象");
System.out.println("2");
this.bout= new ByteArrayOutputStream();System.out.println("3");
//---need a BufferedImage for JPEG Codec.
//---BufferedImage is a subclass of Image.
BufferedImage bufferedImage= new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
bufferedImage.setRGB(0,0,w,h,pixels,0,w);
//---sharpen the image.
float[] sharpKernel = { 0.0f, -1.0f, 0.0f,
-1.0f, 5.0f, -1.0f,
0.0f, -1.0f, 0.0f };System.out.println("5");
BufferedImageOp sharpen= new ConvolveOp( new Kernel(3, 3, sharpKernel), ConvolveOp.EDGE_NO_OP, null);
BufferedImage sharp= sharpen.filter( bufferedImage, null );
//---create an encoder object for the BufferedImage.
JPEGEncodeParam jpegParam= JPEGCodec.getDefaultJPEGEncodeParam( sharp );
jpegParam.setQuality( 1.0f, false );
JPEGImageEncoder jpeg= JPEGCodec.createJPEGEncoder( bout, jpegParam );
//---encode the BufferedImage.
jpeg.encode( bufferedImage );
this.bout.writeTo(new FileOutputStream(ofileDirAndName));
}
分来分来。
|
去sun找相关的文章,有一个GIFEncoder,可以做gif输出
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。