本文介绍了在XML的ImageView放一个绘制时不支持的图像类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我被code引用一个图像中的ImageView的:

When I'm referencing an image in an imageview by the code:

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

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

I get the following error in Error Log:

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不喜欢,不品尝我也不在图形布局

Do that is happening? I cannot open the image on my pc without any problems, but Eclipse does not like, not sample me nor in the graphical layout

感谢。

推荐答案

也许你的JPG在CYMK模式。尝试设置的src从code中的ImageView的。

Maybe your JPG is in CYMK mode. Try to set the src for the ImageView from code.

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);

这篇关于在XML的ImageView放一个绘制时不支持的图像类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 22:25