本文介绍了BitmapFactory.de codeFILE和Android的ImageView的奇怪的事情的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有奇怪的问题 - 它发生在XPERIA(安卓4.0.3),而不是三星小号加(2.3.6)。在实际应用中我使用谷歌地图APIv2与支持库(在另一个活动。如果事情不知道)。

I have strange problem - it occurs on xperia (android 4.0.3) but not on samsung S plus (2.3.6). In application i'm using google maps APIv2 with support library (in another activity. Not sure if matters).

我想我已经缩小问题:

private Bitmap bitmap;
private String st;
private static final String PHOTO_DIR = "photodir";

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    [...]
    st = Environment.getExternalStorageDirectory().toString() + "/" + PHOTO_DIR  + "/test.jpg";
    bitmap = BitmapFactory.decodeFile(st);
    ImageView im = (ImageView) findViewById(R.id.imv_Photo);
    im.setImageBitmap(bitmap);
    [...]

这正常工作。但这:

@Override
public void onClick(View v)
{
    try
    {
        ImageView im = (ImageView) findViewById(R.id.imv_Photo);
        String st = Environment.getExternalStorageDirectory().toString() + "/" + PHOTO_DIR  + "/test1.jpg";
        Bitmap bitmap = BitmapFactory.decodeFile(st);
        im.setImageBitmap(bitmap);
    }
    catch (Exception e)
    {
        // null
    }
}

挂起应用(尽管try / catch块的!),即使去掉im.setImageBitmap(位图)。当我注释掉BitmapFactory.de codeFILE问题dissappears。更糟糕的是XPERIA卸载SD卡插入时,向USB,我​​不知道该怎么写图片到手机内存还没有,所以我无法检查日志(顺便说一句:有没有办法让以后登录?)

hangs the application (despite of try/catch block!) even with im.setImageBitmap(bitmap) removed. When i comment out BitmapFactory.decodeFile problem dissappears. Even worse xperia unmounts sd-card when plugged to usb and i don't know how to write pics to phone memory yet, so i'm unable to check log (btw: is there a way to get log later?)

当我从OnCreate()中删除了code,的onClick()的作品一次。我试图解码之前设置位图= null,而setImageBitmap(空),但它并不能帮助。

When i remove code from onCreate(), onClick() works exactly once. I tried to set bitmap = null, and setImageBitmap(null) before decoding, but it doesn't help.

这似乎很奇怪,我作为三星有相同code没有问题的。

This seems very strange to me as samsung has no problem with same code.

是否有任何解决方案或也许是我做错了什么?

Is there any solution or maybe i'm doing something wrong?

推荐答案

做一件事。传递给德code文件前样品图像。检查下面

Do one thing. Before passing to decode file Sample the image. Check the code below

BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 3;


Bitmap bitmap = BitmapFactory.decodeFile(st,options);
    im.setImageBitmap(bitmap);

这篇关于BitmapFactory.de codeFILE和Android的ImageView的奇怪的事情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 01:39