Create image_mysql in a Java application

Source: Internet
Author: User
You do not have to read all the images from the file. you can create your own images. To create your own Image, the most flexible method is to use a BufferedImage object, which is a subclass of the Image class and stores the Image data in an accessible buffer. It also supports various methods for storing pixel data: Using or without the alpha channel, Synthesize images

You do not have to read all the images from the file-you can create your own images. To create your own Image, the most flexible method is to use a BufferedImage object, which is a subclass of the Image class and stores the Image data in an accessible buffer. It also supports various methods for storing pixel data: Using or without alpha channels, different color models, and various precision of color components. The ColorModel class provides a flexible way to define various color models and use them with BufferedImage objects. To understand the basic knowledge of color models, we will only use one default color model, the color component consists of an RGB value and a buffer type (storing an 8-bit RGB color value plus an alpha channel. This buffer type is specified by the constant TYPE_INT_ARGB in the BufferedImage class, which means that each pixel uses an int value. The value of each pixel is stored in 8 bytes as an alpha component plus an RGB color component. We can create a BufferedImage object of this type with the given width and height. the code statement is as follows:

Int width = 200;
Int height = 300;
BufferedImage image = new BufferedImage (width,
Height, BufferedImage. TYPE_INT_ARGB );

This code creates a BufferedImage object that represents an image of 200 pixels in width and 300 pixels in height. To apply this image, we need to have a graphical context, and the createGraphics () method of the BufferedImage object returns a Graphics2D object related to the image:

Int width = 200;
Graphics2D g2D = image. createGraphics ();

Operations on g2D objects modify the pixels of the BufferedImage object image. With this object, you are now fully capable of applying the BufferedImage object. You can draw shapes, images, GeneralPath objects, or anything else, and set alpha composite objects for the graphic context. You also have all the affinsic deformation capabilities provided by Graphics2D objects.

To obtain a single pixel from a BufferedImage object, you can call its getRGB () method and provide the x and y coordinates of the pixel as the int type parameter. This pixel is returned in the int type in the TYPE_INT_ARGB format. it consists of four 8-bit values (representing the alpha value and the RGB color component) and a 32-bit character. GetRGB () also has an overloaded version, which returns a pixel array from some image data. You can also set a single pixel by calling the setRGB () method. The first two parameters are the coordinates of the pixel, and the third parameter is the value to be set. the type is int. This method also has a version that can set the value of the pixel array.

Now we have completed pixel operations. Next we will create an applet that will make the BufferedImage object animated on the Wrox logo background. Our example also demonstrates how to make the image local transparent. The basic content of the applet is as follows:

Import java. awt .*;
Import java. awt. image .*;
Import java. awt. geom .*;
Import javax. swing .*;

Public class ImageDrawDemo extends JApplet
{
// The init () method to initialize everything...
// The start () method to start the animation...
// The stop () method to stop the animation...
// The ImagePanel class defining the panel displaying the animation...
// Data members for the applet...
}

   Create an image

A child image is a small image that can be drawn in a static image to create an animation. To create an animation effect, you only need to draw a child image at different positions and directions over time. Of course, the deformation of the coordinate system can simplify a lot. Games often use sub-graphics-because you only need to draw sub-graphics on a static background, you can greatly reduce the time occupied by the animation processor. Our interest in using BufferedImage objects means that we will no longer focus on the best technology to reduce processor time, but focus on understanding how to create and use images within a program.

Our BufferedImage object looks like the image in 1:

Figure 1. BufferedImage subgraph

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.