Discussion Board

Results 1 to 3 of 3
  1. #1
    Regular Contributor sachinwarang's Avatar
    Join Date
    Mar 2006
    Posts
    76
    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 kralvarado's Avatar
    Join Date
    Feb 2004
    Posts
    6
    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
    Nokia Developer Champion balagopalks's Avatar
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,427
    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
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved