Android 以缩略图的形式获取图像
我在Android应用程序中工作,但我遇到了一个问题,当我从相机中获取图像时,我会在imageview中显示该图像,但我还需要显示与缩略图相同的图像。我已经检查了一个应用程序,这里是 图为:Android 以缩略图的形式获取图像,android,image,thumbnails,Android,Image,Thumbnails,我在Android应用程序中工作,但我遇到了一个问题,当我从相机中获取图像时,我会在imageview中显示该图像,但我还需要显示与缩略图相同的图像。我已经检查了一个应用程序,这里是 图为: 试试这个方法,你想要的大小的缩略图也会保持纵横比和缩放比例 public Bitmap crateThumbNail(String imagePath,int size) { try { // Decode image size BitmapF
试试这个方法,你想要的大小的缩略图也会保持纵横比和缩放比例
public Bitmap crateThumbNail(String imagePath,int size) {
try {
// Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeFile(imagePath, o);
// The new size we want to scale to
final int REQUIRED_SIZE = size;
// Find the correct scale value. It should be the power of 2.
int scale = 1;
while (o.outWidth / scale / 2 >= REQUIRED_SIZE && o.outHeight / scale / 2 >= REQUIRED_SIZE)
scale *= 2;
// Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
return BitmapFactory.decodeFile(imagePath, o2);
} catch (Throwable e) {
e.printStackTrace();
}
return null;
}
使用以下方法获取缩略图 当您拥有图像的“路径”时,此方法非常有用
/**
* 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);
编辑
当您拥有图像的位图时,使用此方法
public static Bitmap createThumb(Bitmap sourceBitmap, int thumbWidth,int thumbHeight) {
return Bitmap.createScaledBitmap(sourceBitmap, thumbWidth, thumbHeight,true);
}
使用这种方法
createThumb(editedImage, 100, 100);
对为什么不呢?这是另一种方法。等待编辑我的答案。@priya,:)首先需要创建一个拇指,然后需要对最近创建的拇指应用效果。例如,1)创建选定图像的缩略图,2)应用效果,3)在“多媒体资料”中设置。非常简单D@priya,您也可以使用键盘工作“i2cam”在play store上查看我的应用程序:)@priya,不是同一时间。。。您应该为此创建一个背景线程。要开始图像编辑,这是一个很好的开始。简单。。下载后,您将通过打开此链接接受我的答案,该链接为您提供演示:)