JAVA

자바 이미지생성, 이미지 버퍼, 이미지 메모리 생성 관련

AlrepondTech 2020. 9. 18. 03:11
반응형

 

 

 

 

 

=================================

=================================

=================================

 

 

 

 

 

 

출처: http://www.exampledepot.com/egs/java.awt.image/CreateBuf.html

Creating a Buffered Image

A buffered image is a type of image whose pixels can be modified. For example, you can draw on a buffered image and then draw the resulting buffered image on the screen or save it to a file. A buffered image supports many formats for storing pixels. Although a buffered image of any format can be drawn on the screen, it is best to choose a format that is the most compatible with the screen to allow efficient drawing. This example demonstrates several ways of creating a buffered image.

If the buffered image will not be drawn, it can simply be constructed with a specific format; TYPE_INT_RGB andTYPE_INT_ARGB are typically used. See BufferedImage for a list of available formats.

See also Creating a Buffered Image from an Image.

int width = 100;
int height = 100;

// Create buffered image that does not support transparency
BufferedImage bimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

// Create a buffered image that supports transparency
bimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

 

These examples create buffered images that are compatible with the screen:

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gs.getDefaultConfiguration();

// Create an image that does not support transparency
bimage = gc.createCompatibleImage(width, height, Transparency.OPAQUE);

// Create an image that supports transparent pixels
bimage = gc.createCompatibleImage(width, height, Transparency.BITMASK);

// Create an image that supports arbitrary levels of transparency
bimage = gc.createCompatibleImage(width, height, Transparency.TRANSLUCENT);

 

A screen compatible buffered image can also be created from a graphics context:

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D)g;
    int width = 100;
    int height = 100;

    // Create an image that does not support transparency
    BufferedImage bimage = g2d.getDeviceConfiguration().createCompatibleImage(
        width, height, Transparency.OPAQUE);

    // Create an image that supports transparent pixels
    bimage = g2d.getDeviceConfiguration().createCompatibleImage(
        width, height, Transparency.BITMASK);

    // Create an image that supports arbitrary levels of transparency
    bimage = g2d.getDeviceConfiguration().createCompatibleImage(
        width, height, Transparency.TRANSLUCENT);
}

 

 

 

반응형

 

728x90

 

 

 

One last way of creating a buffered image is using Component.createImage(). This method can be used only if the component is visible on the screen. Also, this method returns buffered images that do not support transparent pixels.

BufferedImage bimage = (BufferedImage)component.createImage(width, height);
if (bimage == null) {
    // The component is not visible on the screen
}

Related examples

Converting a Buffered Image to an Image

Creating a Buffered Image from an Array of Color-Indexed Pixel Values

Creating a Buffered Image from an Image

Drawing on a Buffered Image

Getting and Setting Pixels in a Buffered Image

Scaling, Shearing, Translating, and Rotating a Buffered Image

Comments

18 Feb 2011 - 2:52am by hanguyen (not verified)

Thanks for your example.

I have one question if you dont mind: How to create a BufferedImage along with metadata?

Thanks.

23 Jun 2011 - 11:19pm by donita (not verified)

is that a complete program....?

8 Aug 2011 - 1:39am by Anonymous (not verified)

wtf

1 Oct 2011 - 10:56pm by ...lost in translation... (not verified)

please post relevant information not advertisements....

23 Nov 2011 - 4:11am by elc (not verified)

thx!

18 Jan 2012 - 11:33pm by business loans (not verified)

This is great that we are able to get the loans and this opens new chances.

15 Apr 2012 - 8:15am by credit loans (not verified)

The loan seem to be useful for guys, which want to ground their business. By the way, that's not really hard to get a consolidation loan.

 

 

=================================

=================================

=================================

 

 

 

반응형