×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    3

    getPixels() returns pixels for wrong Graphicsobject

    Ive tried to make a new Image by using the getPixels() and drawPixels()-methods.
    1. First I read in my picture from a file. 2. Then I draw it to a mutable Image on which I use the getPixels()-method.
    3. Thirdly I create another mutable Image on which I use the drawPixels()-method.
    The problem is that what gets drawn on the third Image is whats on the Graphicsobject in the paint()-method. Ie whats been drawn to the screen, and not my read picturefile.

    //First I create a mutable Image img2
    img1=Image.createImage("/test.png");
    w = img1.getWidth();
    h = img1.getHeight();
    img2 = Image.createImage(w,h);
    Graphics g2 = img2.getGraphics();
    g2.drawImage(img1,0,0,g2.TOP|g2.LEFT);

    //Then I put the pixels in an shortarray
    short[] pixels = new short[w*h];
    DirectGraphics dg2 = DirectUtils.getDirectGraphics(g2);
    dg2.getPixels(pixels,0,w,0,0,w,h,4444);

    //And thirdly I draw the pixels to img3
    img3 = Image.createImage(w,h);
    Graphics g3 = img3.getgraphics();
    DirectGraphics dg3 = DirectUtils.getDirectGraphics(g3);
    dg3.drawPixels(pixels,false,0,w,0,0,w,h,0,4444);

    Ive tried with different pixelformats and accordingly with different kinds of getPixels()-methods but it never works as I want. It does read in the right picture and draws it to img2, but I think the appears in the calling of getPixels(). Ive made it work by painting my picture to the screen and then gotten the pixels from there but I want to do it offscreen.
    Can anyone shed some light on this please. Is it possible? Im clueless.

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    2
    Did you tried the code on real phones, or only in emulators? Btw: the 7210 emulator don't have this problem... nor the 7210 phone.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×