hildebrando 16 de out. de 2006
Cara, ve se te ajuda.
public static void gerarThumbnail ( InputStream inputStream , String realPath , String fileName , int thumbAltura , float quality ) throws BusinessException , SystemException {
Image image = null ;
int largura = 0 ;
int altura = 0 ;
try {
//Recuperar os valores de LARGURA/ALTURA e ALTERAR no registro da FOTO
image = ImageIO . read ( inputStream );
largura = image . getWidth ( null );
altura = image . getHeight ( null );
} catch ( Exception e ) {
throw new br . com . twosolutions . exception . SystemException ( "ERRO ALTERANDO TAMANHO DA IMAGEM " + e );
}
try {
//Fazer a geracao do TumbNail levando em conta o tamanho da ALTURA
MediaTracker mediaTracker = new MediaTracker ( new Container ());
mediaTracker . addImage ( image , 0 );
mediaTracker . waitForID ( 0 );
// determine thumbnail size from WIDTH and HEIGHT
double thumbPorcentagem = (( thumbAltura * 100.0 ) / altura ) / 100.0 ;
int thumbLargura = ( int )( largura * thumbPorcentagem );
// draw original image to thumbnail image object and
// scale it to the new size on-the-fly
BufferedImage thumbImage = new BufferedImage ( thumbLargura , thumbAltura , BufferedImage . TYPE_INT_RGB );
Graphics2D graphics2D = thumbImage . createGraphics ();
graphics2D . setRenderingHint ( RenderingHints . KEY_INTERPOLATION , RenderingHints . VALUE_INTERPOLATION_BICUBIC ); //For speed better use RenderingHints.VALUE_INTERPOLATION_BILINEAR
graphics2D . drawImage ( image , 0 , 0 , thumbLargura , thumbAltura , null );
// save thumbnail image to OUTFILE
BufferedOutputStream out = new BufferedOutputStream ( new FileOutputStream ( realPath + fileName ));
JPEGImageEncoder encoder = JPEGCodec . createJPEGEncoder ( out );
JPEGEncodeParam param = encoder . getDefaultJPEGEncodeParam ( thumbImage );
param . setQuality ( quality , false ); //The quality argument from the command line is converted from the interval 0 to 100 to the interval 0.0f to 1.0f, because that's what the codec expects (I mostly use 0.75f).
encoder . setJPEGEncodeParam ( param );
encoder . encode ( thumbImage );
out . close ();
} catch ( Exception e ) {
throw new SystemException ( "ERRO SALVANDO O THUMBNAIL DA IMAGEM " + e );
}
}
ethoshow 17 de out. de 2006
Cara, q mastigado isso aiii!! q show de bolaa
muito obrigado!
so teria um problema…
ñ sei como aplicar isso!! se faço um .js e jogo dentro, mas como poderia chama-lo depois, como isso funciona…
sou meio leigo…
des de ja agradeço!