The last time we talked about how to process an image into a translucent effect, the following shows the effect of a change from transparency to opacity.
Import java. Io. ioexception;
Import javax. microedition. lcdui. Canvas;
Import javax. microedition. lcdui. graphics;
Import javax. microedition. lcdui. image;
/**
* @ Author Liu Jun
* @ Version 1.0
*/
Public class TCanvas extends canvas implements runnable {
Image image; // the image to be processed
Int argb [];
Int A = 0; // set the initial transparency value of the pixel to 0, and then add this value continuously in the thread.
Public TCanvas (){
Super ();
Try {
Image = image. createimage ("/test.png"); // import the image
} Catch (ioexception e ){
E. printstacktrace ();
}
Argb = new int [image. getwidth () * image. getheight ()];
Image. getrgb (argb, 0, image. getwidth (), image. getwidth (), image. getheight (); // obtain the argb value of the image.
Int temp;
For (INT I = 0; I <argb. length; I ++)
{
Argb [I] = (a <24) | (argb [I] & 0x00ffffff); // modify the maximum value of 2 bits
}
Thread t = new thread (this );
T. Start ();
}
Protected void paint (Graphics g ){
G. setcolor (0 xffffff );
G. fillrect (0, 0, getwidth (), getheight ());
G. setcolor (0 );
G. drawimage (image, 0, 0, graphics. Top | graphics. Left );
G. drawrgb (argb, 0, image. getwidth (), 0,100, image. getwidth (), image. getheight (), true); // draw a pixel array
G. drawstring (a + "", 10, 90, graphics. Top | graphics. Left );
}
Public void run ()
{
While (A <1, 256)
{
// Change the pixel content
For (INT I = 0; I <argb. length; I ++)
{
Argb [I] = (a <24) | (argb [I] & 0x00ffffff); // modify the maximum value of 2 bits
}
Repaint (); // repaint the screen
A ++;
Try {
Thread. Sleep (100 );
} Catch (interruptedexception e ){
E. printstacktrace ();
}
}
}
}