Usage of bufferedimage in Java

Source: Internet
Author: User

1. The package used Public Static voidMain (string[] args) {//TODO auto-generated Method Stub       intwidth = 100; intHeight = 100; //1. Create a BufferedImage object with no transparent colorBufferedImage bimage=Newbufferedimage (width, height, bufferedimage.type_int_rgb); //2. Create a BufferedImage object with transparent colorBimage=Newbufferedimage (width, height, bufferedimage.type_int_argb); //3. Create a BufferedImage object that is compatible with the screengraphicsenvironment GE=graphicsenvironment. getlocalgraphicsenvironment (); GraphicsDevice GS=Ge.getdefaultscreendevice (); GraphicsConfiguration GC=gs.getdefaultconfiguration (); //Create An image this does not support transparencyBimage=gc.createcompatibleimage (width, height, transparency.opaque); //Create an image that supports transparent pixelsBimage=gc.createcompatibleimage (width, height, transparency.bitmask); //Create an image that supports arbitrary levels of transparencyBimage=gc.createcompatibleimage (width, height, transparency.translucent); }   //4. Of course we can also create a BufferedImage object in the graphical context   Public voidPaint (Graphics g) {graphics2d g2d=(graphics2d) G; intwidth = 100; intHeight = 100; //Create An image this does not support transparencyBufferedImage bimage=g2d.getdeviceconfiguration (). Createcompatibleimage (width, height, transparency.opaque); //Create an image that supports transparent pixelsBimage=g2d.getdeviceconfiguration (). Createcompatibleimage (width, height, transparency.bitmask); //Create an image that supports arbitrary levels of transparencyBimage=g2d.getdeviceconfiguration (). Createcompatibleimage (width, height, transparency.translucent); }}2. Image clipping using BufferedImage: Public Static voidMain (string[] args) {Try {   //loading from a specific filebufferedimage Bi= Imageio.read (NewFile ("C:\\test.jpg")); Bi.getsubimage (0, 0, 10, 10); } Catch(IOException e) {e.printstacktrace (); }2How to fetch the bufferedimagebufferedimage image= Imageio.read (NewFile ("1.gif"));3.BufferedImage---->byte[]imageio.write (BufferedImage image,string format,outputstream out); The method can solve the problem well; The parameter image represents the obtained bufferedimage The format of the parameter, such as "GIF", and so on, the parameter out represents the output stream, if it is to be converted into a byte array, the output stream is bytearrayoutputstream, and after execution, only Tobytearray () is needed to get byte[];4. Display BufferedImage Public voidPaint (Graphics g) {Super. Paint (g);    G.drawimage (image); //image is bufferedimage type}

Usage of bufferedimage in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.