Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Java [игнор отключен] [закрыт для гостей] / img to img / 2 сообщений из 2, страница 1 из 1
26.11.2003, 01:29
    #32334771
img to img
как преобразовать исходный файл jpg,png с разрешением x,y в файл x/2,y/2?
очень нужно
...
Рейтинг: 0 / 0
26.11.2003, 13:32
    #32335306
kadet
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
img to img
//посмотри код


Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
 import  com.sun.image.codec.jpeg.*;
 import  java.awt.*;
 import  java.awt.image.*;
 import  java.io.*;

 public   class  Thumbnail {
   public   static   void  main(String[] args)  throws  Exception {
     if  (args.length !=  5 ) {
      System.err.println("Usage: java Thumbnail INFILE " +
                         "OUTFILE WIDTH HEIGHT QUALITY");
      System.exit( 1 );
    } /* load image from INFILE*/
    Image image = Toolkit.getDefaultToolkit().getImage(args[ 0 ]);
    MediaTracker mediaTracker =  new  MediaTracker( new  Container());
    mediaTracker.addImage(image,  0 );
    mediaTracker.waitForID( 0 );
        /* determine thumbnail size from WIDTH and HEIGHT*/
     int  thumbWidth = Integer.parseInt(args[ 2 ]);
     int  thumbHeight = Integer.parseInt(args[ 3 ]);
     double  thumbRatio = ( double ) thumbWidth / ( double ) thumbHeight;
     int  imageWidth = image.getWidth( null );
     int  imageHeight = image.getHeight( null );
     double  imageRatio = ( double ) imageWidth / ( double ) imageHeight;
     if  (thumbRatio < imageRatio) {
      thumbHeight = ( int ) (thumbWidth / imageRatio);
    }
     else  {
      thumbWidth = ( int ) (thumbHeight * imageRatio);
    } /* draw original image to thumbnail image object and     scale it to the new size on-the-fly*/
    BufferedImage thumbImage =  new  BufferedImage(thumbWidth, thumbHeight,
                                                 BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics2D = thumbImage.createGraphics();
    graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                                RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    graphics2D.drawImage(image,  0 ,  0 , thumbWidth, thumbHeight,  null );
        /* save thumbnail image to OUTFILE*/
    BufferedOutputStream out =  new  BufferedOutputStream( new  FileOutputStream(
        args[ 1 ]));
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbImage);
     int  quality = Integer.parseInt(args[ 4 ]);
    quality = Math.max( 0 , Math.min(quality,  100 ));
    param.setQuality( ( float ) quality /  100 .0f, false);
    encoder.setJPEGEncodeParam(param);
    encoder.encode(thumbImage);
    System.out.println("Done.");
    System.exit( 0 );
  }
}
...
Рейтинг: 0 / 0
Форумы / Java [игнор отключен] [закрыт для гостей] / img to img / 2 сообщений из 2, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]