我一個上傳圖片,GIF文件,之後,我要保存在縮略圖格式的文件之後。如何存儲JPEG,GIF圖像格式的略圖通過Java API的上傳
1
A
回答
0
一般有沒有這樣的東西「縮略圖格式」,而要使用圖片庫來調整圖像上傳到特定的體積小,對其進行壓縮,並保存原件一起。
我不熟悉Java的圖像格式庫,但肯定會有其他人回答了這一點。
1
從http://viralpatel.net/blogs/2009/05/20-useful-java-code-snippets-for-java-developers.html:
private void createThumbnail(String filename, int thumbWidth, int thumbHeight, int quality, String outFilename)
02 throws InterruptedException, FileNotFoundException, IOException
03 {
04 // load image from filename
05 Image image = Toolkit.getDefaultToolkit().getImage(filename);
06 MediaTracker mediaTracker = new MediaTracker(new Container());
07 mediaTracker.addImage(image, 0);
08 mediaTracker.waitForID(0);
09 // use this to test for errors at this point: System.out.println(mediaTracker.isErrorAny());
10
11 // determine thumbnail size from WIDTH and HEIGHT
12 double thumbRatio = (double)thumbWidth/(double)thumbHeight;
13 int imageWidth = image.getWidth(null);
14 int imageHeight = image.getHeight(null);
15 double imageRatio = (double)imageWidth/(double)imageHeight;
16 if (thumbRatio < imageRatio) {
17 thumbHeight = (int)(thumbWidth/imageRatio);
18 } else {
19 thumbWidth = (int)(thumbHeight * imageRatio);
20 }
21
22 // draw original image to thumbnail image object and
23 // scale it to the new size on-the-fly
24 BufferedImage thumbImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB);
25 Graphics2D graphics2D = thumbImage.createGraphics();
26 graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
27 graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);
28
29 // save thumbnail image to outFilename
30 BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outFilename));
31 JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
32 JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbImage);
33 quality = Math.max(0, Math.min(quality, 100));
34 param.setQuality((float)quality/100.0f, false);
35 encoder.setJPEGEncodeParam(param);
36 encoder.encode(thumbImage);
37 out.close();
38 }
你需要找出其中所有類從何而來,但它並不像他們使用任何非與JDK捆綁在一起(儘管我可能是錯誤)。
0
遵循以下步驟:
- 從上傳商品
- 使用
ImageIO
得到InputStream
載入和重新調整圖像(谷歌的「java規模圖像」) - 保存新縮放圖像
imagename_thumb.extension
0
相關問題
- 1. 如何將繪圖圖保存爲C#格式的JPEG圖像
- 2. 內存中的OpenCV jpeg格式圖像
- 3. 如何通過Picasa API上傳圖片時防止JPEG壓縮?
- 4. base64格式的JPEG圖像
- 5. JPEG,PNG,GIF格式圖像不顯示在任何瀏覽器
- 6. 將從各種格式上傳的圖像轉換爲JPEG
- 7. 最佳方式存儲上傳圖像
- 8. 上傳和存儲圖像
- 9. 在Java App Engine上使用Java存儲上傳的圖像
- 10. 通過Django上傳JPEG圖像顯示錯誤
- 11. 如何上傳和在春季和MySQL數據庫存儲的圖像格式
- 12. 針對任何圖像格式(jpg,PNG,gif)的java圖像壓縮
- 13. 上傳圖像通過URL
- 14. 通過ftp上傳圖像
- 15. 如何在AWS上存儲圖像縮略圖s3
- 16. 拖放圖像,通過ajax形式存儲圖像ID
- 17. 上傳圖像和縮略圖通過PHP
- 18. 在java中上傳和存儲圖像的Java解決方案
- 19. 圖片上傳存儲策略
- 20. 存儲上傳的圖像與Laravel 5
- 21. 存儲未上傳的圖像
- 22. 如何將上傳的圖像存儲到AWS上的PHP S3
- 23. 使用ffmpeg從jpeg圖像生成gif
- 24. 如何將圖像(GIF,JPG,JPEG,PNG)轉換爲PHP中的TIFF?
- 25. 通過API Gateway以二進制格式將圖像從AWS Lambda上傳到S3
- 26. Java:保存上傳的PNG圖像
- 27. Django的 - 上傳格式的.tif和CONVER的圖像轉換成JPEG
- 28. 上傳在Heroku的Rails的圖像通過API
- 29. 通過drupal中的FCKeditor上傳圖像
- 30. 轉換上傳的圖片縮略圖+ Blob存儲
我相信人們會穿上就像精力在要求它回答這個問題,你有。 – skaffman 2010-02-04 13:29:47