我是Android的新手所以我没有准确地知道如何使我的应用程序更具响应性,因为它为每个处理创建位图并设置为imageView。基本上我要做的是创建一个位图,播放用它,就像从seekBar传递值来改变它的属性并将其设置为imageView。如何创建Bitmap对象的副本以避免references.Any建议??提前致谢
答案 0 :(得分:0)
答案 1 :(得分:0)
您可以尝试这个非常有效地处理位图的库 https://github.com/thest1/LazyList 它很容易使用这个惰性列表库。 它可以自动缓存位图: -
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"/>
并且您也可以查看Nostras ImageLoader,因为它可以有效地处理将图像加载到特定大小的容器中,即在需要处理它们之前调整大小和压缩它们。它还支持内容uris,它将立即帮助你。
除此之外,如果最终将在ImageView中的128x96像素缩略图中显示,则不值得将1024x768像素图像加载到内存中。 您应该将缩小版的图像加载到内存中。 我也在为位图分享精彩的实用程序类,它可以帮助您根据大小缩小图像: -
/**
* 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);
}
}
您也可以转到此链接它将帮助您构建应用程序
http://developer.android.com/training/displaying-bitmaps/index.html