Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Mar 2003
    Location
    Malaysia-Johor-Pontian Kecil
    Posts
    163

    Graphics.copyArea() vs Image.getRGB() / Graphics.drawRGB() ?

    Hi,

    It's the code below:
    import javax.microedition.lcdui.*;

    public class TestCanvas extends Canvas {
    public TestCanvas() {
    super();
    }

    public void paint(Graphics g) {
    g.setColor(255, 255, 255);
    g.fillRect(0, 0, getWidth(), getHeight());

    // System.out.println("TestCanvas--paint()--Original x: " + g.getTranslateX());
    // System.out.println("TestCanvas--paint()--Original y: " + g.getTranslateY());

    // g.translate(5, 5);
    // g.translate(5, 5);

    Image image = Image.createImage(150, 150);
    Graphics gg = image.getGraphics();
    gg.setColor(255, 0, 0);
    gg.fillRect(0, 0, 50, 50);

    // (I) METHOD RGB
    int[] RGB = new int[50 * 50];
    image.getRGB(RGB, 0, 50, 0, 0, 50, 50);
    gg.drawRGB(RGB, 0, 50, 10, 50, 50, 50, true);

    g.drawImage(image, 0, 0, 0);

    // (II) METHOD copyArea
    gg.copyArea(0, 0, 50, 50, 10, 100, 0);

    // System.out.println("TestCanvas--paint()--Current x: " + g.getTranslateX());
    // System.out.println("TestCanvas--paint()--Current y: " + g.getTranslateY());
    }
    }


    ** You can remark either METHOD I / II to test the differences between them !!

    ------------------------------------------------

    I intend to invoke copyArea() to copy certain area to another area in one Image. But it seems not effect at all.

    So that, I think of using getRGB()/drawRGB() to replace it. But I still think copyArea() is the standard way to do so.

    * I think using copyArea() can save resource than drawing samething but in different area in the image, am I right ?

    * "Throws:
    IllegalStateException - if the destination of this Graphics object is the display device." . Please explain what does this sentence mean ?

    Please guide me how to make use of copyArea().

    Thanks.
    http://www.geocities.com/akokchai/

  2. #2
    Registered User
    Join Date
    Mar 2003
    Location
    Malaysia-Johor-Pontian Kecil
    Posts
    163
    Sorry everybody,

    I've done a mistaken here. The sequence of

    g.drawImage(image, 0, 0, 0);

    // (II) METHOD copyArea
    gg.copyArea(0, 0, 50, 50, 10, 100, 0);

    is wrong.

    It should be

    // (II) METHOD copyArea
    gg.copyArea(0, 0, 50, 50, 10, 100, 0);

    g.drawImage(image, 0, 0, 0);

    --------------------------------

    But the copied area is still wrong position.

    Please check it for me.

    Thanks.
    http://www.geocities.com/akokchai/

Posting Permissions

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