×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Jul 2012
    Location
    India
    Posts
    103

    How to Set Image height and width in j2me(java)

    Hi
    i have created an image from the image url(lcdui image)

    HttpConnection c = (HttpConnection) Connector.open(imageurl);
    int len = (int)c.getLength();
    if (len > 0)
    {
    is = c.openDataInputStream();
    byte[] data = new byte[len];
    is.readFully(data);

    img = Image.createImage(data, 0, len);

    i want to set height and width to this?and i want to display?

  2. #2
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: How to Set Image height and width in j2me(java)

    Hi pavanragi,

    You are better off using a ScalableImage instance (svg image) of the Scalable 2D Vector Graphics API. An example of image manipulation (scaling and rotation) can be found here.

  3. #3
    Nokia Developer Expert
    Join Date
    May 2012
    Location
    Espoo
    Posts
    224

    Re: How to Set Image height and width in j2me(java)

    Hi pavanragi,

    Following example can help you.
    How to Fit an Image to the Screen Size

  4. #4
    Registered User
    Join Date
    Jul 2012
    Location
    India
    Posts
    103

    Re: How to Set Image height and width in j2me(java)

    Hi bandarap,
    this code will work perfectly for LCDUI Image,but my requirement is for LWUIT Image,so i am not able to use this code?

    Quote Originally Posted by bandarap View Post
    Hi pavanragi,

    Following example can help you.
    How to Fit an Image to the Screen Size

  5. #5
    Registered User
    Join Date
    Jul 2012
    Location
    India
    Posts
    103

    Re: How to Set Image height and width in j2me(java)

    Here is the code i got for LWUIT Image Resize:


    public Image resizeImage(Image src, int screenHeight, int screenWidth) {
    int srcWidth = src.getWidth();

    int srcHeight = src.getHeight();
    Image tmp = Image.createImage(screenWidth, srcHeight);
    Graphics g = tmp.getGraphics();
    int ratio = (srcWidth << 16) / screenWidth;
    int pos = ratio / 2;

    //Horizontal Resize

    for (int index = 0; index < screenWidth; index++) {
    g.setClip(index, 0, 1, srcHeight);
    g.drawImage(src, index - (pos >> 16), 0);
    pos += ratio;
    }

    Image resizedImage = Image.createImage(screenWidth, screenHeight);
    g = resizedImage.getGraphics();
    ratio = (srcHeight << 16) / screenHeight;
    pos = ratio / 2;

    //Vertical resize

    for (int index = 0; index < screenHeight; index++) {
    g.setClip(0, index, screenWidth, 1);
    g.drawImage(tmp, 0, index - (pos >> 16));
    pos += ratio;
    }
    return resizedImage;

    }

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: How to Set Image height and width in j2me(java)

    Yeah, com.sun.lwuit.Image is so extremely different.
    Let me guess,
    Code:
    Image.createRGBImage(iNewRGBArray, iNewWidth, iNewHeight, true);
    did not compile, and writing
    Code:
    Image.createImage((iNewRGBArray, iNewWidth, iNewHeight);
    is way beyond what anyone could expect from a software developer.

Similar Threads

  1. How To Scale Image and Get Camera ViewFinder Width & Height?
    By coolblues5000 in forum Symbian Media (Closed)
    Replies: 60
    Last Post: 2008-10-28, 02:05
  2. Can't set width/height in <image> -- JSR 226
    By SYTDeath in forum Mobile Java Media (Graphics & Sounds)
    Replies: 0
    Last Post: 2008-10-09, 10:29
  3. Can't set width/height in <image> -- JSR 226
    By SYTDeath in forum Mobile Java General
    Replies: 0
    Last Post: 2008-10-08, 22:43
  4. how to get the width and height of a jpg or bmp
    By faqffq in forum Symbian User Interface
    Replies: 2
    Last Post: 2005-12-15, 10:49
  5. Replies: 1
    Last Post: 2003-02-10, 16:15

Posting Permissions

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