• Advertisement
Sign in to follow this  

Resizing images with MIDP 1.0..but how?

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm trying to resize an image with MIDP 1.0. (cant use 2.0..no way) But I cant find a way. I've read it could be done line by line with the clipping function of Graphics. But I have no idea how to manage this task. Can anybody help me in this point? Thanks!!! Axel

Share this post


Link to post
Share on other sites
Advertisement
Yes there is a way with the clipping function, but you can only resize by a full pixels and can't do scaling by 0.5 or something like that. You might be better off just storing every image size in the JAR. The basic idea is:

[SOURCE]
//Example for 8x8 image to 16x16 iamge

Image small = Image.createImage( "/small.png" );

Image large = Image.createImage( 16, 16 );
Graphics gcl = large.getGraphics();

for( int y = 0; y < 16; y+=2 )
{
for( int x = 0; x < 16; x+=2 )
{
gcl.setClip( x, y, 1, 1 );
gcl.drawImage( small, x - (x/2), y - (y/2), Graphics.TOP | Graphics.LEFT );

gcl.setClip( x + 1, y, 1, 1 );
gcl.drawImage( small, (x + 1) - (x/2), y - (y/2), Graphics.TOP | Graphics.LEFT );

gcl.setClip( x, y + 1, 1, 1 );
gcl.drawImage( small, x - (x/2), (y + 1)- (y/2), Graphics.TOP | Graphics.LEFT );

gcl.setClip( x + 1, y + 1, 1, 1 );
gcl.drawImage( small, (x + 1) - (x/2), (y + 1) - (y/2), Graphics.TOP | Graphics.LEFT );
}
}

//Large should now be 16x16
[/SOURCE]
[/source]

The above may not be exactly right!!!

Share this post


Link to post
Share on other sites
You will have to write your own image scaling routine. Obviously it could scale by a non-integral fashion easily enough.

It's not going to be very fast
- Most phones don't have very fast CPUs
- It's not very efficient to do image scaling in Java making API calls for every pixel

But on the bright side
- Most phones don't have very high res screens

Mark

Share this post


Link to post
Share on other sites
Further Note: I think some vendor specific API's might do this automatically. markr is right, you could scale by a non intergral value, using a line drawing algorithm I think, but it would be *VERY* slow. If I ever have to scale images I usually store a series of different sized sprites in a grid, and use the closest one.

I was very tired when I wrote the above code last night, and I was making it up as I went along so I'm suprised it worked!!! :-)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement