2

当我通过代码在图像视图中引用图像时:

<ImageView
   android:id="@+id/imageView2"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:src="@drawable/tequila" /> 

我在错误日志中收到以下错误:

javax.imageio.IIOException: Unsupported Image Type
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(    at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(    at javax.imageio.ImageIO.read(    at javax.imageio.ImageIO.read(    at android.graphics.Bitmap_Delegate.createBitmap(Bitmap_Delegate.java:96)
    at com.android.layoutlib.bridge.impl.ResourceHelper.getDrawable(ResourceHelper.java:233)
    at android.content.res.BridgeTypedArray.getDrawable(BridgeTypedArray.java:782)
    at android.widget.ImageView.<init>(ImageView.java:120)
    at android.widget.ImageView.<init>(ImageView.java:110)
    at sun.reflect.GeneratedConstructorAccessor10.newInstance(    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(    at java.lang.reflect.Constructor.newInstance(    at android.view.LayoutInflater.createView(LayoutInflater.java:587)
    at android.view.BridgeInflater.onCreateView(BridgeInflater.java:86)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:131)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:746)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:718)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:749)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:718)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:749)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:718)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:372)

是否正在发生这种情况?我无法在我的电脑上毫无问题地打开图像,但 Eclipse 不喜欢、不采样我也不在图形布局中

谢谢。

4

1 回答 1

3

也许您的 JPG 处于 CYMK 模式。尝试从代码中设置 ImageView 的 src。

BitmapFactory.Options opts = new BitmapFactory.Options();
        opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
        Bitmap bmp = BitmapFactory.decodeResource(getResources(), 
                                                          R.drawable.tequila, opts);
        ImageView view = (ImageView) findViewById(R.id.imageView2);
view.setImageBitmap(bmp);
于 2013-04-09T13:24:49.643 回答