J2ME interpolation algorithm to realize image zooming and narrowing

Source: Internet
Author: User
Tags transparent color

Some time ago contacted some digital image processing problems, under the guidance of 1 senior, in the J2ME platform, completed some basic 2D image processing algorithm. As a summary of this knowledge, decided to write out these algorithms, and friends to explore together. This article first introduces the realization of image amplification, the program is based on the Nokia S40 machine for the platform implementation.

1, the realization of the basic idea of graphic scaling:

The transformation of the image is simply to transform each point coordinate of the source image into the new coordinate of the corresponding point in the target image, but it will cause a problem that the coordinates of the target point are not usually integers. So we need to compute the points that the build is not mapped to when we do the magnification transformation, and we need to remove some points when narrowing the transformation. Here we adopt the simplest interpolation algorithm: "Nearest neighbor Method". As the name implies, is the coordinate of the non-integer rounding, take the most recent integer points.

Look at one of the following pictures to enlarge the example, the left image is the original image, the right image is magnified 1 time times. The number inside, the information that represents the pixel in the

1 2 1 1 2 2

5 4 5 5 4 4

2, for the image pixel operation:

Get image Image Pixel information:

The standard midp1.0 does not provide a function for capturing the pixel information of the image, and for the Nokia machine, we can use the API provided by the Nokia SDK to get the pixel information. The specific procedures are as follows:

g = image.getGraphics()
DirectGraphics dg = DirectUtils.getDirectGraphics(g);
dg.getPixels(short[] pixels, int offset, int scanlength, int x,int y, int width, int height, int format)

Parameter introduction:

short[] Pixels: An array for receiving pixel information

int offset: The place to use in this article, add 0 to the

int Scanlength: Add the width of the picture just fine

int x: Add 0

int Y: Tim 0

int width: Picture width

int height: Picture height

int format:444, which represents the graphics format, as if the Nokia S40 machines are in the 444 format to represent RGB color. Is red, green, blue each with 4-bit, as for can represent transparent color ARGB 4444 format, should be the machine hardware implementation.

To find out more about the Nokia SDK, you can view the Help documentation for the Nokia SDK.

To generate an image image using an array of pixel information:

Image = Image.createimage (W, h);

g = Image.getgraphics ()

Directgraphics dg = Directutils.getdirectgraphics (g);

Dg.drawpixels (short[] pixels,boolean transparency, int offset, int scanlength, int x, int y, int width,int height, int man ipulation, int format)

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.