[英]Android Animation with Gridviews: Scaling from a thumbnail to a full-size image
[英]Android: Display full-size version of thumbnail image.
看看您的decodeSampledBitmapFromUri
方法-這是加載照片的方法。
在您的情況下,您傳遞的reqWidth
和reqHeight
較低,因此獲得的分辨率較低。 您可以將其傳遞給更大的尺寸以獲得更好的圖像(如屏幕寬度和高度),也可以僅使用options.inSampleSize = 1
以獲得完整圖像
您可以為此使用BimapFactory。 我假設您具有文件的路徑以及所需的高度和寬度。
public static BitmapDrawable decodeSampledBitmapFromFile(Activity a, String path, float reqHeight, float reqWidth){
final BitmapFactory.Options options = new BitmapFactory.Options();
//you are not really creating the bitmap now but just calculating it's bounds
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
options.inJustDecodeBounds = false;
//options now holds the size needed to decode
Bitmap bitmap = BitmapFactory.decodeFile(path, options);
return new BitmapDrawable(a.getResources(), bitmap);
}
public static int calculateInSampleSize(BitmapFactory.Options options, float reqWidth, float reqHeight){
float srcWidth = options.outWidth;
float srcHeight = options.outHeight;
int sampleSize = 1;
if(srcHeight > reqHeight || srcWidth > reqWidth){
final float halfHeight = srcHeight / 2;
final float halfWidth = srcWidth / 2;
while((halfHeight / sampleSize) > reqHeight && (halfWidth / sampleSize) > reqWidth){
sampleSize *= 2;
}
}
return sampleSize;
}
從這里開始,就像將BitmapDrawble分配給視圖一樣簡單(通過view.setImageDrawable(drawble))
使它起作用:
BitmapDrawable b = decodeSampleBitmapFromFile(getActivity(), path, pictureWidth, pictureHeight);
view.setImageDrawable(b)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.