Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android2中使用位图类_Android - Fatal编程技术网

在android2中使用位图类

在android2中使用位图类,android,Android,我正在尝试位图。当我运行位图时,它没有显示图像。我不明白我在做什么。我还在尝试选项。inJustDecodeBounds=true但未更改。请帮助我: 我的代码在这里: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

我正在尝试位图。当我运行位图时,它没有显示图像。我不明白我在做什么。我还在尝试选项。inJustDecodeBounds=true但未更改。请帮助我:

我的代码在这里:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        txt = (TextView) findViewById(R.id.textView1);
        imgView = (ImageView) findViewById(R.id.imageView1);

        BitmapFactory.Options options=new BitmapFactory.Options();
        options.inJustDecodeBounds=true;

        Bitmap bMap=BitmapFactory.decodeResource(getResources(), R.drawable.b,options);
        imgView.setImageBitmap(bMap);


    }
布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >



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

</LinearLayout>

使用直接资源映像在ImageView中进行设置

imgView.setImageResource(R.drawable.b);
当您使用inJustDecodeBounds时,它只解码具有真实图像分辨率的黑色图像。

为什么需要位图? 你试过这个吗

imgView.setBackgroundResource(R.drawable.b);

将Options.inJustDecodeBounds设置为true并调用 BitmapFactory获取/解码位图的方法,返回位图 将使用Options.outWidth和Options.outHeight为空,以像素表示图像的宽度和高度

这通常用于缩放图像。因为在解码之前你会得到图像信息

如果您不想做这样的事情,请将Options.inJustDecodeBounds设置为false,您的代码将正常工作。如果您想扩展,请查看以下内容:

问题是什么?当我运行时,它没有显示出来image@user3659367读我的工作,请告诉我。。我想用位图也许你的图像太大了。。。您可以添加选项。inSampleSize=2;您也可以尝试3、4或更多。。。但是每一个数字都会使你的图像质量下降。谢谢兄弟@Roman Black…问题解决了。bro支持所有照片的通用尺寸是多少…(inSampleSize)当您设置inSampleSize=1或图像按原样解码时,当您设置inSampleSize=2时,图片以高度/2和宽度/2分辨率解码,当它=3时,图片以高度/4和宽度/4分辨率解码,依此类推。