#ff0000 20  2006 . - #000655 MIDP 2.0:     , , drawRGB()
#000655 
#def       ,     .     : 
  ,    . 
     . 
  drawRGB(). 
     . 
  Image  . 
  . 

,  MIDP 2.0      ,       . 
ARGB Image

MIDP 2.0        ,   ,     .      . ,    ,   : 
8 :(A)  ,   
8 :(R) 
8 :(R) 
8 :(R) 

       1	1	1	1	1	1	1	1	0	0	0	0	0	0	0	0	0	1	0	1	0	1	0	1	1	0	1	0	1	0	1	0
      .      8 .   ( 8 )      0000 0000 (Ox00),  - 0101 0101 (Ox55),  - 1010 1010 (OxAA).  ,          0  255. 
 

        ARGB . RGB -  ,    ,  A -  ,    .       1111 1111 (OxFF),   - 0000 0000 (Ox00).           . 

        ARGB .         ,      ,   . 

public void paint(Graphics g)
{
     ...
     int x = 0, y = 0; //    
     int width = 35, height = 35; //  
     //    
     if(pixelArray == null) pixelArray = new int[width * height];
     //    ( )
     for(int i = 0; i < pixelArray.length; i++)
          pixelArray[i] = 0xffff0000;
     g.drawRGB(pixelArray, 0, width, x, y, width, height, false);
     g.drawRect(x, y, width, height); //   ()
     
     //    
     x = 35;
     y = 35;
     for(int i = 0; i < pixelArray.length; i++)
          pixelArray[i] = 0x7fff0000;
     g.drawRGB(pixelArray, 0, width, x, y, width, height, true);
     g.drawRect(x, y, width, height); //   ()

     //    
     x = 70;
     y = 70;
     for(int i = 0; i < pixelArray.length; i++)
          pixelArray[i] = 0x00ff0000;
     g.drawRGB(pixelArray, 0, width, x, y, width, height, true);
     g.drawRect(x, y, width, height); //   ()
}
 drawRGB()

 drawRGB()   MIDP 2.0.     ,     .    : 

drawRGB(int[] rgbData, //  ARGB 
        int offset, //     
                      //  
        int scanlength, //    
        int x, // x   
        int y, // y   
        int width, // 
        int height, // 
        boolean processAlpha) //false    

 scanlength  processAlpha  .        ,      .      scanlength  35.      ,        ,     processAlpha  false;   , processAlpha    true. 
 ARGB 

      .      10x10 . 
   , ,    ,    .        . 
     ,      . 
            : 

//     
int ballWidth = 10, ballHeight = 10;
if(pixelArray == null) pixelArray = new int[ballWidth * ballHeight];

    .     ,    ,    - . 

//   
int i = 0;
int j = 0;
for(; i < ballWidth; i++)
pixelArray[i] = 0x00000000; // Black, transparent
// 
for(j = 0; j < 3; i++, j++)
pixelArray[i] = 0x00000000; //    
pixelArray[i++] = 0xffff0000; // 255, 0, 0
pixelArray[i++] = 0xffd30000; // 211, 0, 0
pixelArray[i++] = 0xffff0000; // 255, 0, 0
pixelArray[i++] = 0xffdb0000; // 219, 0, 0
pixelArray[i++] = 0xff870000; // 135, 0, 0
pixelArray[i++] = 0x00000000; //   
pixelArray[i++] = 0x00000000; //   
// 
for(j = 0; j < 2; i++, j++) //   
pixelArray[i] = 0x00000000;
pixelArray[i++] = 0xffc30000; // 195, 0, 0
for(j = 0; j < 6; i++, j++) // 255, 0, 0
pixelArray[i] = 0xffff0000;
pixelArray[i++] = 0x00000000; //   
//  
pixelArray[i++] = 0x00000000; //   
pixelArray[i++] = 0xff800000; // 128, 0, 0
for(j = 0; j < 7; i++, j++) // 255, 0, 0
pixelArray[i] = 0xffff0000;
pixelArray[i++] = 0xff870000; // 135, 0, 0
//  
pixelArray[i++] = 0x00000000; //   
pixelArray[i++] = 0xffd30000; // 211, 0, 0
for(j = 0; j < 7; i++, j++) // 255, 0, 0
pixelArray[i] = 0xffff0000;
pixelArray[i++] = 0xffdb0000; // 219, 0, 0
//  
pixelArray[i++] = 0x00000000; //   
for(j = 0; j < 9; i++, j++) // 255, 0, 0
pixelArray[i] = 0xffff0000;
//  
pixelArray[i++] = 0x00000000; //   
pixelArray[i++] = 0xffd30000; // 211, 0, 0
for(j = 0; j < 7; i++, j++) // 255, 0, 0
pixelArray[i] = 0xffff0000;
pixelArray[i++] = 0xffdb0000; // 219, 0, 0
//  
pixelArray[i++] = 0x00000000; //   
pixelArray[i++] = 0xff800000; // 128, 0, 0
for(j = 0; j < 7; i++, j++) // 255, 0, 0
pixelArray[i] = 0xffff0000;
pixelArray[i++] = 0xff870000; // 135, 0, 0
//  
for(j = 0; j < 2; i++, j++) //   
pixelArray[i] = 0x00000000;
pixelArray[i++] = 0xffc30000; // 195, 0, 0
for(j = 0; j < 6; i++, j++) // 255, 0, 0
pixelArray[i] = 0xffff0000;
pixelArray[i++] = 0x00000000; //   
//  
for(j = 0; j < 3; i++, j++)
pixelArray[i] = 0x00000000; //   
pixelArray[i++] = 0xffff0000; // 255, 0, 0
pixelArray[i++] = 0xffd30000; // 211, 0, 0
pixelArray[i++] = 0xffff0000; // 255, 0, 0
pixelArray[i++] = 0xffdb0000; // 219, 0, 0
pixelArray[i++] = 0xff870000; // 135, 0, 0
pixelArray[i++] = 0x00000000; //   
pixelArray[i++] = 0x00000000; //   

          drawRGB()   paint() 

private int ballX = 50, ballY = 80;
...
public void paint(Graphics g)
{
     ...
          g.drawRGB(pixelArray, 0, ballWidth, ballX, ballY, ballWidth, ballHeight, true);
     ...
} 

.     processAlpha  drawRGB()  true.       ,     . 
  Image  ARGB 

       ,           Image        .

int ballWidth = 10, ballHeight = 10;
//    ARGB 
if(pixelArray == null) pixelArray = new int[ballWidth * ballHeight];

//    (.  )
int i = 0, j = 0;
for(; i < ballWidth; i++)
     pixelArray[i] = 0x00000000; //   
...

//   Image   ARGB .
Image rgbImage;
int ballX = 50, ballY = 80;
rgbImage = Image.createRGBImage(pixelArray, ballWidth, ballHeight, true);

//    ,  
//    Image.
g.drawImage(rgbImage, 0, 0, Graphics.LEFT | Graphics.TOP);

      Image,   ARGB . ,  ChoiceGroup  List   ,      Image . 
  ARGB 

    ARGB  -        .   .         .    ARGB .       . 
,  ARGB   ,     ( Timer)     .  ,        . 
     ,         . 
DrawRGB_MIDlet.java -   

/*--------------------------------------------------
* DrawRGB_MIDlet
*-------------------------------------------------*/
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class DrawRGB_MIDlet extends MIDlet
{
   private Display display;
   private DrawRGB_Canvas rgbImage;

   public DrawRGB_MIDlet()
      {
      //   canvas
      rgbImage = new DrawRGB_Canvas(this);
      display = Display.getDisplay(this);
      }
   public void startApp()
      {
      display.setCurrent(rgbImage);
      }
   public void pauseApp()
      {
      }
   public void destroyApp(boolean unconditional)
      {
      }
   public void exitMIDlet()
      {
      destroyApp(true);
      notifyDestroyed();
   } 
}
DrawRGB_Canvas.java -       

/*--------------------------------------------------
* DrawRGB_Canvas
*-------------------------------------------------*/
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.util.*;
public class DrawRGB_Canvas extends Canvas implements CommandListener
   {
   private int[] pixelArray; //  
   private Image image = null; //  
   private int boxWidth = 127, boxHeight = 167, //  
   pixelArraySize, //    
   displayWidth, displayHeight, //  
   randomPixel; //  
   private Command cmExit; //  
   private Random random; //    
   private Timer tm; // 
   private TimerTask tt; //   
   private boolean initComplete = false; //    
   DrawRGB_MIDlet midlet; //   

   public DrawRGB_Canvas (DrawRGB_MIDlet midlet)
      {
      this.midlet = midlet;
      // 
      cmExit = new Command("Exit", Command.EXIT, 0);
      addCommand(cmExit);
      setCommandListener(this);

      displayWidth = getWidth();
      displayHeight = getHeight();
      pixelArraySize = boxWidth * boxHeight;
      //    
      random = new java.util.Random();
      //   
      try
      {
           image = Image.createImage("/seagull.png");
           }
      catch (java.io.IOException e)
      {
           System.err.println("Unable to locate or read .png file");
           }
      //    
      createBox();
      //  
      tm = new Timer();
      tt = new DrawTask();
      tm.scheduleAtFixedRate(tt, 0, 1);
      }
   /*--------------------------------------------------
   *  ,  
   *-------------------------------------------------*/
   private void createBox()
      {
      int red, green, blue, alpha;
      long tmp;
      //  
      if(pixelArray == null)
      {
           pixelArray = new int[pixelArraySize];
           //  
           red = (random.nextInt() >>> 1) % 256;
           green = (random.nextInt() >>> 1) % 256;
           blue = (random.nextInt() >>> 1) % 256;
           alpha = 0xff; // 
           //     
           tmp = (alpha << 24) | (red << 16) | (green << 8) | blue;
           //   
           for (int i = 0; i < pixelArraySize; i++)
           pixelArray[i] = (int) tmp;
         }
      }
   /*--------------------------------------------------
   *      
   *   
   *-------------------------------------------------*/
   private void updateDisplay()
      {
      //     
      randomPixel = (random.nextInt() >>> 1) % (pixelArraySize);
      //   50 
      //  ,      
      for (int i = randomPixel, j = 0; j < 50 && i < (pixelArraySize); j++, i++)
      pixelArray[i] = 0x00000000;
      }
   /*--------------------------------------------------
   *  
   *-------------------------------------------------*/
   public void paint(Graphics g)
      {
      if (initComplete == false)
         {
           //  .
           g.setColor(255, 255, 255);
           g.fillRect(0, 0, displayWidth, displayHeight);
           initComplete = true;
           }
      //   
      if (image != null)
      g.drawImage(image, 0, 0, Graphics.LEFT | Graphics.TOP);
      //   
      g.drawRGB(pixelArray, 0, boxWidth, 0, 0, boxWidth, boxHeight, true);
      }
   /*--------------------------------------------------
   *   ,  .
   *-------------------------------------------------*/
   protected void keyPressed(int keyCode)
      {
      tt.cancel();
      //      
      for (int i = 0; i < (pixelArraySize);i++)
      pixelArray[i] = 0x00000000;
      repaint();
      }
   /*--------------------------------------------------
   * DrawTask 
   *-------------------------------------------------*/
   private class DrawTask extends TimerTask
      {
      public final void run()
      {
         updateDisplay();
         repaint();
         }
      }
}


          . ,      ,    .