Como criar thumbnails em Java ME
| Line 32: | Line 32: | ||
</code> | </code> | ||
| − | + | Você pode utilizar também: | |
http://www.java-tips.org/java-me-tips/midp/how-to-implement-oom-in-and-oom-out.html | 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 | + | Vale lembrar que ambos os métodos usam muita memória e processamento, sendo adequado que sejam feitos em background, em uma nova 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]]. | Para mais detalhes, veja [[Thumbnail_path_for_3rd_edition_devices]]. | ||
[[Category:Java_ME_(Português)]][[Category:Exemplos de código Java ME]][[Category:Lang-PT]] | [[Category:Java_ME_(Português)]][[Category:Exemplos de código Java ME]][[Category:Lang-PT]] | ||
Revision as of 01:26, 1 October 2009
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;
}
Você pode utilizar também: 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 uma nova 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.

