×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Regular Contributor
    Join Date
    Mar 2006
    Posts
    76

    Question Problem while creating images .

    Hi friends,
    I'm to creating the image on Canvas.

    To create image from resource folder

    I've use the follwing code

    imageError = new Image[2];
    imageError[0] =Image.createImage("/warning.png");
    imageError[1] =Image.createImage("/error.png");


    But this didn't work.

    So i've tried ,

    imageError = new Image[2];
    imageError[0] =createImageRes("/warning.png");
    imageError[1] =createImageRes("/error.png");


    where the method createImageRes is

    public Image createImageRes(String res)
    {
    Image img_1 = null;
    try
    {
    dis_img = getClass().getResourceAsStream(res);
    din_img = new DataInputStream(dis_img);
    int fsize = din_img.readInt();
    byte[] img_byte = new byte[fsize];
    din_img.readFully(img_byte, 0, fsize);
    img_1 = Image.createImage(img_byte, 0, fsize);
    }
    catch (Exception e)
    {
    System.err.println("An Exception occurs. "+e);
    }
    return img_1;
    }
    and dis_img is instance of InputStream and din_img is instance of DataInputStreamInputStream.


    Still i'm not abel to create image.

    Note:
    warning.png and error.png i've store in res folder.

    Whats the problem?

    Regards,
    Sachin Warang.

  2. #2
    Registered User
    Join Date
    Feb 2004
    Posts
    6

    Re: Problem while creating images .

    What do you mean by doesn't work. Does your code not compile or are you getting unexpected results?

    If your code is not compiling it could be because the static function Image.createImage( String name ) will throw either a NullPointerException or an IOException. The code you posted isn't handling the exceptions, put the calls to createImage() in a Try/Catch block.


    Image[] imageError = new Image[2];

    try {
    imageError[0] = Image.createImage( "/warrning.png" );
    imageError[1] = Image.createImage( "/error.png" );
    }
    Catch ( Exception e ) {
    }

  3. #3
    Super Contributor
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,430

    Re: Problem while creating images .

    Sachin ,

    I guess you have already got replies here http://agathonisi.erlm.siemens.de:80...18202&tstart=0

    or still problem exists ?

    Regards
    Gopal

Similar Threads

  1. Problem displaying GIF and JPG images on phones
    By paulmckillop in forum Browsing and Mark-ups
    Replies: 1
    Last Post: 2004-12-20, 05:07
  2. Creating transparent images with MIDP 1.0
    By desgra_p in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2004-01-14, 11:42
  3. Replies: 0
    Last Post: 2003-09-22, 07:00
  4. Problem creating profiles in D211
    By molausso in forum Multimodecards
    Replies: 1
    Last Post: 2002-09-16, 11:14
  5. 3410 problem with images (IllegalArgumentException)
    By bigredswitch in forum Mobile Java General
    Replies: 1
    Last Post: 2002-09-13, 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
  •