[Translation] Implementing pictures with MIDP 2.0 gradual effect

xiaoxiao2021-03-06  133

May 2004

Implementing pictures with MIDP 2.0 gradual effect

Original source: http://developer.sonyericsson.com/site/global/techsupport/tipstrickscode/java/p_java_0501.jsp

Translator: clapton_xpathotmaildotcom in August 2004

This article describes how to render a gradient effect by changing an alpha value of the image, and then attached an example MIDlet code after the article.

The Image class in MIDP 2.0 has a new method, getRGB (...), which converts Image's alpha and RGB values ​​into an INT array. We can use this method and the obtained array to change the alpha value of the picture.

INT in J2ME is 4 Bytes, and each pixel in the image is described in the argb value, each value can be 0-255. If the alpha value is 0, the corresponding pixels are transparent, and vice versa if the Alpha value is 255, the pixels are completely opaque.

The color of each pixel can be used using the AND '&' operator from the INT array. We can first get the color of the pixel, then attach the gradient effect we want to get.

Ff = 11111111 = 2550xffffffff - alpha = 255, red = 255 Green = 255, Blue = 255 (0xfffffff & 0x00ffff) = 0x00fffffff

The above code we can get the RGB color value of the int array, the Alpha value is 0.

Now that we have an alpha value of 0 RGB color values, we only need to attach new alpha values ​​there.

If we want to set the alpha value of the color to 255, we need to use the left-right operator.

Method: (00000000 00000000 0000000000 11111111) TO (11111111 00000000 0000000000000000) Use the shift left '<<' Operator. (0xff << 24) = 0xff000000.

Clapton_XPathotmaildotcom

With this method we can change the alpha value of the color or achieve the cover effect.

Use Image GetRGB (...) method to get the Argb value of all pixels of the image and put an Int array. Change the alpha value of each value (pixel) in the array with the following Blend method. Create a new image from the int array we modified by Image. Below is an example of using getRGB and CreaterGbImage methods:

Public static void blend (int = raw.length; // start loop through all the pixels in the image. for (int i = 0; I I int a = 0; int color = RAW [I] & 0x00fffffff); // Get The Colorof The Pixel. A = AlphaValue; // Set The Alpha Value We Want To Use 0-255.

A = (a << 24); // Left shift the alpha value 24 bits. // if color = 0000000000 11111111 1111111110000000 (0xffff00 = yellow) // and alpha = 01111111000000000000000000000 // THEN C a = 011111111 11111111 11111111 00000000 // and the Pixel Will Be Blended. Color = a; RAW [i] = color;}} Download Source Code >>

转载请注明原文地址:https://www.9cbs.com/read-127475.html

New Post(0)