Skip to main content

scaling images programaticaly

6 replies [Last post]
amuche
Offline
Joined: 2011-09-05
Points: 0

please wats d best option for scaling an image programatically??

for example, i want to create a gridlayout that scalesa

all the images on the form irrespectiv of their

sizes to the same size??any sample code for that wud b appreciated

i no d gridlayout makes images same..buh sumtyms, bigger sized images

appear bigger even if de on d same row? any solution>????

plis any RPLY WUD B APREIOCATED!!! just suggest sumfin plis!!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
gt8887b
Offline
Joined: 2010-03-15
Points: 0

Image class provides a number of useful methods to perform scaling:

scaledHeight(), scaledWidth(), scaled(), and scaledSmallerRatio().

You can check the java docs to see which method will be most suitable to your needs.

amuche
Offline
Joined: 2011-09-05
Points: 0

tried this:

try{

Image image=Image.createImage("/jug.png");

image.setWidth(form.getWidth/4);

image.setHeight(form.getHeight/4);

form.getStyle.setBgImage(image);

}

catch(IOException ab){

//stmts

}

checkd its output and image size remaind d SAME!!! is der anyfin i mised??? plis help me out???

gt8887b
Offline
Joined: 2010-03-15
Points: 0

What Image class are you using?

com.sun.lwuit.Image does not provide methods setWidth() and setHeight().

You need to use scaling methods from com.sun.lwuit.Image

Ex:

result = Image.createImage("/jug.png");

Image scaledImage = result.scaledWidth(form.getWidth()/4);
amuche
Offline
Joined: 2011-09-05
Points: 0

stil didnt work... used it same way u did buh result produced same image size.

try{
Image mine=Image.createImage("/blue.jpeg");
Image scaledWidth=mine.scaledWidth(form.getWidth()/4);

}

catch(//exceptn stmts)

is der any oda alternative?

gt8887b
Offline
Joined: 2010-03-15
Points: 0

The only thing I can think of is that when you call form.getWidth() the width is not yet initialized.

Have you tried stepping into the scaledWidth() method with a debugger?

If you are passing valid arguments and it still does not work it is possible that there is a bug in LWUIT. In this case we'd love if you could post a small sample on how to reproduce the issue.

amuche
Offline
Joined: 2011-09-05
Points: 0

it is just as d previous reply code stated..only code coming before it is the Display.Init(this) code and then the create and display image

using the try and catch statements..if i try initializing the getwidth(), what would it be? du i try initializing it to the size of the screen?

rily dnt understand..stil expecting a rply..if only i could reduce the size of my images programticaly so that images scale themselves\

as they step into each phone model and i could reduce the size of my app drasticaly to kilobytes away from megabytes..i would greatly appreciate!!