如何使应用程序的响应,它使用多个位图?多个、位图、应用程序

2023-09-05 04:55:28 作者:我酷所以撩妹

我是新来的Andr​​oid所以我没有收到究竟如何,因为它创建位图的每个处理让我的应用程序的响应,并设置为imageView.Basically我想要做的是,创造一个位图什么,玩有了它,就像从搜索栏传递值来改变它的属性,并将其设置为imageView.How创建位图对象的副本,以避免references.Any建议?在此先感谢

I'm new to Android so I'm not getting exactly how to make my application more responsive as it creates bitmaps for each processing and set to imageView.Basically What i'm trying to do is that create a bitmap, play with it,like passing values from seekBar to change its properties and set it to imageView.How to create a Copy of Bitmap object to avoid references.Any Suggestions ?? Thanks in advance

推荐答案

您可以试试这个库,它非常有效地处理位图。 https://github.com/thest1/LazyList 它非常容易使用这个懒惰的名单库。 它会自动缓存位图的工作​​: -

You can try this library which handles bitmap very efficiently. https://github.com/thest1/LazyList Its very easy to use this lazy list library. It does the job of caching bitmap automatically:-

 ImageLoader imageLoader=new ImageLoader(context);
 imageLoader.DisplayImage(url, imageView);

注意:

请不要忘了下列权限添加到您的Andr​​oidManifest.xml:

NOTE :

Don't forget to add the following permissions to your AndroidManifest.xml:

  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

请创建ImageLoader的只有一个实例,并重新使用它周围的所有应用程序。这样图像缓存将是更加高效。

Please create only one instance of ImageLoader and reuse it all around your application. This way image caching will be much more efficient.

,你也可以看看Nostras ImageLoader的,因为它有效地处理加载图像转换成特定大小的容器,也就是调整和COM pressing他们之前,你需要来处理它们。它也支持内容的URI,这将有助于你的一次。

and also you can look into Nostras ImageLoader, as it efficiently handles loading images into specific sized containers, i.e resizing and compressing them, before you will need to handle them. It also supports content uris which will help you all at once.

除此之外,这是不值得载入1024×768像素的图片到内存中,如果它最终将在ImageView的显示在128x96像素的缩略图。  您应该加载图像的缩小版到​​内存中。 我也分享了位图的精彩实用类,它可以帮助你根据大小缩小图像: -

Besides this,it’s not worth loading a 1024x768 pixel image into memory if it will eventually be displayed in a 128x96 pixel thumbnail in an ImageView. You should load a scaled down version of image into memory. I am also sharing wonderful utility class for bitmap which helps you to scale down your image according to size:-

/**
* 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

also You can go to this link It will help you to build the app http://developer.android.com/training/displaying-bitmaps/index.html