Resizing images with MIDP 1.0..but how?

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

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 on other sites
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 iamgeImage 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 on other sites
That works fine...thanks!

Axel

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 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!!! :-)

1. 1
2. 2
Rutin
21
3. 3
JoeJ
18
4. 4
5. 5

• 14
• 40
• 23
• 13
• 13
• Forum Statistics

• Total Topics
631722
• Total Posts
3001890
×