[英]Resize image in java without using ImageIO
我們已經通過獲取JPEG縮略圖數據成功調整了圖像的大小,但是某些圖像沒有圖像。
解決方案只是調整圖像大小以能夠創建縮略圖,但只能使用Java 1.4及以下版本(因此,由於設備不支持ImageIO,因此我無法使用ImageIO)
我如何使用ImageIO調整圖像大小是否有解決方案?
java.awt.Image.getScaledInstance(width, height, hints)
返回Image的新的縮放實例。
最后一個參數hints
更改了使用的縮放方法,這將修改結果的外觀。 請參見下面的摘錄,直接從JDK來源獲取。
/**
* Use the default image-scaling algorithm.
* @since JDK1.1
*/
public static final int SCALE_DEFAULT = 1;
/**
* Choose an image-scaling algorithm that gives higher priority
* to scaling speed than smoothness of the scaled image.
* @since JDK1.1
*/
public static final int SCALE_FAST = 2;
/**
* Choose an image-scaling algorithm that gives higher priority
* to image smoothness than scaling speed.
* @since JDK1.1
*/
public static final int SCALE_SMOOTH = 4;
/**
* Use the image scaling algorithm embodied in the
* <code>ReplicateScaleFilter</code> class.
* The <code>Image</code> object is free to substitute a different filter
* that performs the same algorithm yet integrates more efficiently
* into the imaging infrastructure supplied by the toolkit.
* @see java.awt.image.ReplicateScaleFilter
* @since JDK1.1
*/
public static final int SCALE_REPLICATE = 8;
/**
* Use the Area Averaging image scaling algorithm. The
* image object is free to substitute a different filter that
* performs the same algorithm yet integrates more efficiently
* into the image infrastructure supplied by the toolkit.
* @see java.awt.image.AreaAveragingScaleFilter
* @since JDK1.1
*/
public static final int SCALE_AREA_AVERAGING = 16;
嘗試使用此代碼,只需在寬度和高度上輸入所需的大小,即可獲得所需的圖像。 到目前為止,我發現的最短代碼。 對我來說很好。
Bitmap yourBitmap;
Bitmap resized = Bitmap.createScaledBitmap(yourBitmap, newWidth, newHeight, true);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.