Namespaces
Variants
Actions
Revision as of 19:55, 26 November 2007 by dcrocha (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Como criar thumbnails em Java ME

Jump to: navigation, search

Para criar um thumbnail a partir de uma imagem maior, use o código a seguir.

private Image createThumbnail(Image image) {
int sourceWidth = image.getWidth();
int sourceHeight = image.getHeight();
 
int thumbWidth = 64;
int thumbHeight = -1;
 
if (thumbHeight == -1)
thumbHeight = thumbWidth * sourceHeight / sourceWidth;
 
Image thumb = Image.createImage(thumbWidth, thumbHeight);
Graphics g = thumb.getGraphics();
 
for (int y = 0; y < thumbHeight; y++) {
for (int x = 0; x < thumbWidth; x++) {
g.setClip(x, y, 1, 1);
int dx = x * sourceWidth / thumbWidth;
int dy = y * sourceHeight / thumbHeight;
g.drawImage(image, x - dx, y - dy,
Graphics.LEFT | Graphics.TOP);
}
}
 
Image immutableThumb = Image.createImage(thumb);
 
return immutableThumb;
}

You may also use http://www.java-tips.org/java-me-tips/midp/how-to-implement-oom-in-and-oom-out.html

Vale lembrar que ambos os métodos usam muita memória e processamento, sendo adequado que sejam feitos em background, em um novo Thread. Se você está usando um dispositivo S60, você pode tentar localizar os thumbnails já gerados pela aplicação Galeria, geralmente localizados na pasta "_PAlbTN" dentro do diretório de imagens.

Para mais detalhes, veja Thumbnail_path_for_3rd_edition_devices.

120 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved