Tuesday, December 18, 2007

Displaying Images as a Thumbnails on wireless devices in J2ME

You can display your image as a thumbnail on your mobile device. The process is simple you just have to specify the width and height of your thumbnail and the code below will create a thumbnail of your image for you

public static Image getThumbnail (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 << pos =" delta/2;" x =" 0;">> 16), 0, Graphics.LEFT |
Graphics.TOP );
pos += delta;
}

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

delta = (srcH << pos =" delta/2;" y =" 0;">> 16), Graphics.LEFT |
Graphics.TOP );
pos += delta;
}

return dst;
}

No comments: