Android 如何使使用多个位图的应用程序更具响应性?
我是Android新手,所以我不知道如何让我的应用程序更具响应性,因为它会为每次处理创建位图并设置为imageView。基本上我想做的是创建一个位图,使用它,例如从seekBar传递值以更改其属性并将其设置为imageView。如何创建位图对象的副本以避免引用。有什么建议吗??提前感谢使用android中的延迟加载和图像加载程序类在imageView上设置图像,使其看起来更具响应性 这里有一些教程链接Android 如何使使用多个位图的应用程序更具响应性?,android,bitmap,imageview,Android,Bitmap,Imageview,我是Android新手,所以我不知道如何让我的应用程序更具响应性,因为它会为每次处理创建位图并设置为imageView。基本上我想做的是创建一个位图,使用它,例如从seekBar传递值以更改其属性并将其设置为imageView。如何创建位图对象的副本以避免引用。有什么建议吗??提前感谢使用android中的延迟加载和图像加载程序类在imageView上设置图像,使其看起来更具响应性 这里有一些教程链接 您可以尝试这个非常有效地处理位图的库。 使用这个惰性列表库非常容易。 它会自动缓存位图:-
您可以尝试这个非常有效地处理位图的库。
使用这个惰性列表库非常容易。 它会自动缓存位图:-
ImageLoader imageLoader=new ImageLoader(context);
imageLoader.DisplayImage(url, imageView);
注意:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
/**
*提供静态函数以最佳大小解码位图
*/
公共类BitmapUtil{
私有BitmapUtil(){}
/**
*返回图片的宽度或高度,具体取决于较小的大小。实际上不会
*解码图片,因此运行起来非常高效。
*/
公共静态整型getSmallerExtentFromBytes(字节[]字节){
final BitmapFactory.Options=new BitmapFactory.Options();
//不要真正解码图片,只返回其边界
options.inJustDecodeBounds=true;
BitmapFactory.decodeByteArray(字节,0,字节.长度,选项);
//测试最佳样本大小
返回Math.min(options.outWidth,options.outHeight);
}
/**
*查找加载图片的最佳样本大小
*@param originalSmallerExtent图片的宽度或高度,以较小者为准
*@param targetExtent目标视图的宽度或高度,以较大者为准。
*
*如果其中一个参数为0或更小,则不应用采样
*/
公共静态int findOptimalSampleSize(int originalSmallerExtent,int targetExtent){
//如果我们不知道尺寸,就不能取样。
if(targetExtent<1)返回1;
if(originalSmallerExtent<1)返回1;
//测试最佳样本大小
int范围=原始最小范围;
int sampleSize=1;
而((范围>>1)>=targetExtent){
样本大小=1;
}
返回样本;
}
/**
*使用给定的样本大小解码位图
*/
公共静态位图decodeBitmapFromBytes(字节[]字节,int sampleSize){
最终位图工厂。选项;
如果(示例),请发布一些代码,使您的问题更清楚。
/**
* Provides static functions to decode bitmaps at the optimal size
*/
public class BitmapUtil {
private BitmapUtil() {}
/**
* Returns Width or Height of the picture, depending on which size is smaller. Doesn't actually
* decode the picture, so it is pretty efficient to run.
*/
public static int getSmallerExtentFromBytes(byte[] bytes) {
final BitmapFactory.Options options = new BitmapFactory.Options();
// don't actually decode the picture, just return its bounds
options.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options);
// test what the best sample size is
return Math.min(options.outWidth, options.outHeight);
}
/**
* Finds the optimal sampleSize for loading the picture
* @param originalSmallerExtent Width or height of the picture, whichever is smaller
* @param targetExtent Width or height of the target view, whichever is bigger.
*
* If either one of the parameters is 0 or smaller, no sampling is applied
*/
public static int findOptimalSampleSize(int originalSmallerExtent, int targetExtent) {
// If we don't know sizes, we can't do sampling.
if (targetExtent < 1) return 1;
if (originalSmallerExtent < 1) return 1;
// test what the best sample size is
int extent = originalSmallerExtent;
int sampleSize = 1;
while ((extent >> 1) >= targetExtent) {
sampleSize <<= 1;
extent >>= 1;
}
return sampleSize;
}
/**
* Decodes the bitmap with the given sample size
*/
public static Bitmap decodeBitmapFromBytes(byte[] bytes, int sampleSize) {
final BitmapFactory.Options options;
if (sampleSize <= 1) {
options = null;
} else {
options = new BitmapFactory.Options();
options.inSampleSize = sampleSize;
}
return BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options);
}
}