×

Discussion Board

Results 1 to 3 of 3

Thread: image in canvas

  1. #1
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    179

    Exclamation image in canvas

    Hello,

    from gprs data i have made an image in my midlet class now i have to draw this image in canvas class , i have defined the image as public static and the canvas class as well as main midlet is in the same package , but yet i am not able to get that image in my canvas class and when i am writiing

    g.drawImage(image_canvas, 10, 10, 5); it is showing error

    kindly guide me .

    thanks and regards
    Arunesh

  2. #2
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    179

    Re: image in canvas

    its done ....

  3. #3
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: image in canvas

    Quote Originally Posted by Arunesh View Post
    it is showing error
    What error? Can you be as specific as possible, please?

    Quote Originally Posted by Arunesh View Post
    Code:
    g.drawImage(image_canvas, 10, 10, 5);
    I recommend you don't put a "5" here. Use the constants. If you're getting an IllegalArgumentException, it's because "5" is not a valid combination. You must combine one of LEFT, HCENTER or RIGHT, with one of TOP, VCENTER or BOTTOM, using the "|" operator, when placing images.

    What you have written is identical to:

    Code:
    g.drawImage(image_canvas, 10, 10, Graphics.LEFT | Graphics.HCENTER);
    You've combined two from the same group. If you mean top-left, then you need to write:

    Code:
    g.drawImage(image_canvas, 10, 10, Graphics.TOP | Graphics.LEFT);
    If you use the constants, you won't make this kind of error. Your code will also be more readable. I had to read through the JavaDocs to work out what "5" meant. If you use constants, you can get everything you need to know just from the code.

    There is no disadvantage to using the constants. They don't increase the size of the code, nor do they make the code slower. The code generated by the compiler is identical either way.

    Graham.

Similar Threads

  1. Image overlay Camera Canvas
    By jonahkhan1 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 8
    Last Post: 2009-10-13, 12:29
  2. Image as a menu bar in Canvas in j2me
    By soumengoswami in forum Mobile Java General
    Replies: 2
    Last Post: 2009-05-15, 07:25
  3. Canvas: How to draw a Rect around an image?
    By ricardopcunha in forum Mobile Java General
    Replies: 2
    Last Post: 2009-02-10, 17:34
  4. Replies: 1
    Last Post: 2008-07-11, 02:32
  5. Canvas and image
    By j2me_raj in forum Mobile Java General
    Replies: 1
    Last Post: 2003-08-18, 13:21

Posting Permissions

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