• 10
• 12
• 12
• 14
• 15

# Resizing images with MIDP 1.0..but how?

This topic is 4933 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