You Are Here:

Community: Developer Discussion Boards

#1 Old Question How to handle different screen sizes? - 2004-12-28, 15:36

Join Date: Nov 2004
Posts: 15
ykhun
Offline
Registered User
Hi,

I have a couple of 2D 180X180 png images. I used them for splash screen, backgrounds etc etc. How do i ensure that my splash screen and background (using these fixed-sized images) can cover the device's displayable area? For example, if a device is 200X200, how do i stretch my 180X180 images?

I'm currently using lcdui's Image class to display the images, and there isn't any method that i could use to scale the images for different device sizes. :-(

Thanks for any help!! :-)
Reply With Quote

#2 Old 2004-12-28, 17:59

Join Date: Mar 2003
Posts: 6,211
petrib
Offline
Forum Nokia Champion
I presume you have to implement your own image scaling code. Probably best to search for good algorithms to use a starting point:
http://www.google.com/search?hl=en&q...+%2Balgorithms
Reply With Quote

#3 Old 2004-12-29, 03:46

Join Date: Nov 2004
Posts: 15
ykhun
Offline
Registered User
Quote:
Originally posted by petrib
I presume you have to implement your own image scaling code. Probably best to search for good algorithms to use a starting point:
http://www.google.com/search?hl=en&q...+%2Balgorithms
Hi, thanks :)

OMG, is scaling the image the only way.... I'm using MIDP2.0, but just couldn't find anything that can do this automatically. The closest i'd gotten is lcdui's ImageItem, but that only works for a Form and not a Canvas...

If anyone else knows a better way to go about trackling this problem, please drop a post here! Thanks!!!
Reply With Quote

#4 Old 2004-12-30, 02:27

Join Date: May 2003
Posts: 47
anand_amarsh
Offline
Registered User
i got this algorithm from off Eric Giguere :

/**
* Creates a new, scaled version of the given image.
* ref : http://kobjects.org/utils4me/
* @param src: The source image
* @param dstW: The destination (scaled) image width
* @param dstH: The destination (scaled) image height
* @return Image: A new Image object with the given width and height.
*/
public static Image scaleImage(Image src, int dstW, int dstH) {
int srcW = src.getWidth();
int srcH = src.getHeight();

Image tmp = Image.createImage(dstW, srcH);
Graphics g = tmp.getGraphics();

int delta = (srcW << 16) / dstW;
int pos = delta / 2;

for (int x = 0; x < dstW; x++) {
g.setClip(x, 0, 1, srcH);
g.drawImage(src, x - (pos >> 16), 0, Graphics.LEFT | Graphics.TOP);
pos += delta;
}

Image dst = Image.createImage(dstW, dstH);
g = dst.getGraphics();

delta = (srcH << 16) / dstH;
pos = delta / 2;

for (int y = 0; y < dstH; y++) {
g.setClip(0, y, dstW, 1);
g.drawImage(tmp, 0, y - (pos >> 16), Graphics.LEFT | Graphics.TOP);
pos += delta;
}

return dst;
}
Reply With Quote

#5 Old My ideas, - 2005-01-04, 07:41

Join Date: Dec 2004
Posts: 6
seabird_2000
Offline
Registered User
you can solve this problem like this:
first,draw the background:
for (int x=0;x<=getWidth()/backimage.getWidth();x++)
{
for (int y=0;y<=getHeight()/backimage.getHeight();y++)
{
//the "backimage" is your background iamge
// you can also use the "fillrect()" instead of this
//gr is the graphic
gr.drawImage(backimage, x*backimage.getWidth(), y*backimage.getHeight(), gr.TOP | gr.LEFT);
}
}

second,draw your image uesd for splash:
gr.drawImage(yourimage, (getWidth()-yourimage.getWidth())/2,(getHeight()-yourimage.getHeight())/2, gr.TOP | gr.LEFT);
Reply With Quote

#6 Old 2005-01-06, 13:15

Join Date: Jan 2004
Posts: 165
mreaves
Offline
Regular Contributor
Your best bet from a polished and presentation point of view is to have different assets for different platforms, and produce builds targeted for those platform.

It will also be more efficient from a memory point of view and there won't be any delay while the graphics are scaled.

Using an ant build script and antenna for pre-processing makes the whole thing fairly painless and means you can keep the codebase across different platforms.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia