我正在实现一个应用程序,我在其中将图像附加到问题。这些附件有两种类型,
- 使用相机附件
- 画廊照片的附件(画廊中已有的照片)
我得到你的图像如下
//Camera Request
Intent captureImage = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
captureImage.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
startActivityForResult(captureImage, CAMERA_PIC_REQUEST);
// Gallery Pic request
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, GALLERY_PIC_REQUEST);
上面的结果是URI。我将这个 uri.getPath() 保存在我的数据库中。
现在的问题是,当我想显示这些图像时,我是在 uri 的帮助下获取的 我有。但是我在加载第一张图片后出现以下异常 java.lang.OutOfMemoryError: 位图大小超出 VM 预算
看了一些博客,才知道是内存不够加载。
有没有人有在列表中显示图像时压缩图像的有效解决方案。 并在工作完成后回收使用的内存。
最佳答案
您可以使用以下内容:
BitmapFactory.Options options;
options = new BitmapFactory.Options();
options.inSampleSize = 4;
options.inTempStorage = new byte[16 * 1024];
Bitmap bm = BitmapFactory.decodeFile( pathToFile, options );
这将只加载图像中四分之一的像素。更改 inSampleSize
值以加载更多/更少。
关于安卓图像处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8295771/