Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 内存不足错误,在TouchImageview上设置位图_Android_Bitmap_Android Memory - Fatal编程技术网

Android 内存不足错误,在TouchImageview上设置位图

Android 内存不足错误,在TouchImageview上设置位图,android,bitmap,android-memory,Android,Bitmap,Android Memory,在我的应用程序中,我使用TouchImageView为用户启用缩放和裁剪选项。首先,我使用此方法将图像uri转换为位图 位图的Uri private Bitmap decodeUri(Uri selectedImage) throws FileNotFoundException { // Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBo

在我的应用程序中,我使用TouchImageView为用户启用缩放和裁剪选项。首先,我使用此方法将图像uri转换为位图

位图的Uri

   private Bitmap decodeUri(Uri selectedImage) throws FileNotFoundException {

    // Decode image size
    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(getContentResolver().openInputStream(selectedImage), null, o);

    // The new size we want to scale to
    final int REQUIRED_SIZE = 140;

    // Find the correct scale value. It should be the power of 2.
    int width_tmp = o.outWidth, height_tmp = o.outHeight;
    String imageType = o.outMimeType;
    int scale = 1;
    while (true) {

        if (width_tmp / 2 < REQUIRED_SIZE
                || height_tmp / 2 < REQUIRED_SIZE) {
            break;
        }
        width_tmp /= 2;
        height_tmp /= 2;
        scale *= 2;
    }

    // Decode with inSampleSize
    BitmapFactory.Options o2 = new BitmapFactory.Options();
    o2.inSampleSize = scale;
    return BitmapFactory.decodeStream(getContentResolver().openInputStream(selectedImage), null, o2);

}
public Bitmap decodeFile(String filePath) {
    //Log.e(TAG, "Camera Image 3");
    // Decode image size
    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inJustDecodeBounds = true;

    BitmapFactory.decodeFile(filePath, o);
    final int REQUIRED_SIZE = 1024;
    int width_tmp = o.outWidth, height_tmp = o.outHeight;
    int scale = 1;
    while (true) {
        if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE)
            break;
        width_tmp /= 2;
        height_tmp /= 2;
        scale *= 2;
    }

    o.inJustDecodeBounds = false;

    // Decode with inSampleSize
    BitmapFactory.Options o2 = new BitmapFactory.Options();
    o2.inSampleSize = scale;
  Bitmap  bitmap = BitmapFactory.decodeFile(filePath, o2);
    //  imageView = (ImageView) findViewById(R.id.imgView);
    // imageView.setImageBitmap(bitmap);
    return bitmap;
}
这个方法的输出是一个resizedBitmap,我将这个位图设置为imageview,如下所示

   touchimageview.setImageBitmap( scaleBitmap(decoded));

在完成所有这些缩放和解码技术后,我仍然摆脱了memeory错误,如何解决此问题有人能帮忙吗???

作为一个快速解决方案,您可以尝试将其添加到清单文件中的应用程序标记中:

android:largeHeap="true"
但是:

不要仅仅因为内存不足而请求一个大堆,并且需要一个快速修复方法。只有当您确切地知道所有内存被分配到哪里以及为什么必须保留内存时,才应该使用它


更多信息:

作为一个快速解决方案,您可以尝试将其添加到清单文件中的应用程序标记中:

android:largeHeap="true"
但是:

不要仅仅因为内存不足而请求一个大堆,并且需要一个快速修复方法。只有当您确切地知道所有内存被分配到哪里以及为什么必须保留内存时,才应该使用它


更多信息:

尝试使用UIL displayImage功能将图像加载到TouchIamgeView

试试这个

ImageLoader imageloader;
 TouchImageView touchImageView = (TouchImageView)findViewById(R.id.);


    imageLoader.displayImage(imageURL,touchImageView);

尝试使用UIL displayImage函数将图像加载到TouchIamgeView

试试这个

ImageLoader imageloader;
 TouchImageView touchImageView = (TouchImageView)findViewById(R.id.);


    imageLoader.displayImage(imageURL,touchImageView);

您是否尝试过使用毕加索、通用图像加载器等图像库?是的,我正在使用UIL将SD卡图像加载到网格布局,用户选择的图像位图直接用于setImageBitmap方法我的代码有什么问题吗??你能帮忙吗?例如UIL:ImageLoader.getInstance().loadImage(imageUrl,新的ImageSize(viewWidth,viewheight),displayImageLoaderOptions,新的SimpleImageLoadingListener(){@Override public void onLoadingComplete(字符串imageUri,视图视图,位图LoadeImage){mImageMap.setImageBitmap(LoadeImage);}}});尝试这样做。在设置要查看的图像时,应使用此选项。@jaxon在尝试注释fitImageToView()行后,看起来一切正常;在TouchIMageView上使用setImageBitmap方法并运行,如果出现问题请告诉我您是否尝试使用任何图像库,如毕加索、universal image loader等?是的,我正在使用UIL将SD卡图像加载到网格布局,并且用户选择的图像位图直接用于setImageBitmap方法我的代码有问题吗?您能帮助吗?ExUIL的:ImageLoader.getInstance().loadImage(imageUrl,新的ImageSize(viewWidth,viewheight),displayImageLoaderOptions,新的SimpleImageLoadingListener(){@Override public void onLoadingComplete(字符串imageUri,视图视图,位图LoadeImage){mImageMap.setImageBitmap(LoadeImage);}});尝试这样做。在设置要查看的图像时,应使用此选项。@jaxon在尝试注释行fitImageToView()后,看起来一切正常;在TouchIMageView上,请运行setImageBitmap方法,并在出现问题时让我知道