ImageView的RAM的Andr​​oid [英] ImageView Android RAM

查看:115
本文介绍了ImageView的RAM的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我原来的问题一个后续。

A followup from my original question.

有没有使用Android应用ImageViews不使用大量的RAM的方式?

Is there a way to use ImageViews in android apps without using a lot of RAM?

在原来的问题我发现我的应用程序使用了大量的内存,并且发现这是我用的ImageViews太了所有的RAM。

In the original question I found that my app used a lot of RAM, and found that it was the ImageViews which I used that too up all the RAM.

要得到我使用图像

public void addPictureOnClick(View view){
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, "Select Picture"),1);
    } 

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        if (requestCode == 1) {
            // currImageURI is the global variable I'm using to hold the content:// URI of the image
            Uri currImageURI = data.getData();                
            image.setImageURI(currImageURI);
        }

我想知道是否有另一种方式来显示图片,而不是URI?

I would like to know if there is another way to show pictures rather than the URI?

推荐答案

您可以扩展您的图片:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
imageViewFIeld.setImageBitmap(BitmapFactory.decodeByteArray(image, 0, image.length, options));

缩放过程可能会更长,如果你有大的图像,但是内存的负荷也会展出更低。

The scaling process could be longer if you have big images, but the memory load will be lower on display.

编辑:更多您增加inSampleSize价值,更多的时候,它需要,使用更少的内存,您将有

More you increase the inSampleSize value, more times it take, less memory usage you will have.

inSampleSize文档:如果设置
  一个值> 1,要求德codeR
  二次采样原始图像,
  返回一个较小的图像保存
  记忆。样本大小是多少
  在任一维的像素的那
  对应于单个像素
  德codeD位图。例如,
  inSampleSize == 4返回图像
  即1/4的宽度/高度
  原,和1/16的数量
  像素。任何值< = 1的处理
  同1。注意:去codeR会尝试
  实现这个要求,但
  所得的位图可以具有不同的
  维度pcisely有什么$ P $
  被请求。此外,2权力
  往往更快/更容易去codeR到
  荣誉。

inSampleSize documentation : If set to a value > 1, requests the decoder to subsample the original image, returning a smaller image to save memory. The sample size is the number of pixels in either dimension that correspond to a single pixel in the decoded bitmap. For example, inSampleSize == 4 returns an image that is 1/4 the width/height of the original, and 1/16 the number of pixels. Any value <= 1 is treated the same as 1. Note: the decoder will try to fulfill this request, but the resulting bitmap may have different dimensions that precisely what has been requested. Also, powers of 2 are often faster/easier for the decoder to honor.

<一个href=\"http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inSampleSize\" rel=\"nofollow\">http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inSampleSize

这篇关于ImageView的RAM的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆