本文介绍了获取图像的缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的工作在Android的应用程序,但我卡的问题,当我得到的相机,我的显示是ImageView的图像的图像,但我需要表现出同样的图像的缩略图也。我已经检查了一个应用程序在这里是<一个href="https://play.google.com/store/apps/details?ID=com.appspot.swiss$c$cmonkeys.effectsfree&hl=en"相对=nofollow>链接
I am working in Android application but I'm stuck with the problem, when I get the image from camera I am displaying that image in imageview but I need to show the same image as thumbnail also. I have checked one application here is the link
下面是图像:
推荐答案
使用下面的方法来获取缩略图。
Use following method to get thumbnails.
当你有图像的路径这个方法是非常有用的。
This method is useful when you have "Path" of image.
/**
* Create a thumb of given argument size
*
* @param selectedImagePath
* : String value indicate path of Image
* @param thumbWidth
* : Required width of Thumb
* @param thumbHeight
* : required height of Thumb
* @return Bitmap : Resultant bitmap
*/
public static Bitmap createThumb(String selectedImagePath, int thumbWidth,
int thumbHeight) {
BitmapFactory.Options options = new BitmapFactory.Options();
// Decode weakReferenceBitmap with inSampleSize set
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(selectedImagePath, options);
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > thumbHeight || width > thumbWidth) {
if (width > height) {
inSampleSize = Math.round((float) height / (float) thumbHeight);
} else {
inSampleSize = Math.round((float) width / (float) thumbWidth);
}
}
options.inJustDecodeBounds = false;
options.inSampleSize = inSampleSize;
return BitmapFactory.decodeFile(selectedImagePath, options);
}
要使用此方法,
createThumb("path of image",100,100);
修改
此方法用于当你有位图您的形象。
This method is used when you have Bitmap of your image.
public static Bitmap createThumb(Bitmap sourceBitmap, int thumbWidth,int thumbHeight) {
return Bitmap.createScaledBitmap(sourceBitmap, thumbWidth, thumbHeight,true);
}
要使用这个方法
createThumb(editedImage, 100, 100);
这篇关于获取图像的缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!