Pixel-Level Image Processing in midp2.0 (2)

Source: Internet
Author: User

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 ();
}
}
}
}

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.