Resizing images with MIDP 1.0..but how?
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
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]
The above may not be exactly right!!!
[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]
The above may not be exactly right!!!
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
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
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!!! :-)
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!!! :-)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement