Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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
Android 使用ClipDrawable隐藏和ImageView的一部分_Android_Image_Bitmap_Imageview_Android Imageview - Fatal编程技术网

Android 使用ClipDrawable隐藏和ImageView的一部分

Android 使用ClipDrawable隐藏和ImageView的一部分,android,image,bitmap,imageview,android-imageview,Android,Image,Bitmap,Imageview,Android Imageview,我试图隐藏图像的一部分,以便用户看不到它。最初,我将位图像素复制到另一个位图上,而没有仅复制所需的像素,也没有在创建时将第二个位图设置为正确的大小。这是可行的,但我有很多大图片,不幸的是,这导致了oom。因此,我没有这样做,而是考虑使用ClipDrawable来绘制图像,并使我不需要的像素不可见 代码如下 ClipDrawable clipDrawable = new ClipDrawable(new BitmapDrawable(resources, bitmap), gravity, ori

我试图隐藏图像的一部分,以便用户看不到它。最初,我将位图像素复制到另一个位图上,而没有仅复制所需的像素,也没有在创建时将第二个位图设置为正确的大小。这是可行的,但我有很多大图片,不幸的是,这导致了oom。因此,我没有这样做,而是考虑使用ClipDrawable来绘制图像,并使我不需要的像素不可见

代码如下

ClipDrawable clipDrawable = new ClipDrawable(new BitmapDrawable(resources, bitmap), gravity, orientation);
clipDrawable.setLevel(level);

// Cannot use as the imageview source. Must use background or else we don't get anything on the screen.
picture.setBackground(clipDrawable);
// This is super important. Do not modify this! Without it you will not get the fullscreen image working and the ImageView will be deleted
// from the parent layout.
picture.setImageResource(android.R.color.transparent);
我的想法是,我根据图像大小计算级别,以便隐藏我不需要的像素。它正在工作。除了我不明白为什么我需要使用

picture.setBackground(clipDrawable);

picture.setImageResource(android.R.color.transparent);
而不是更正常的:

picture.setImageDrawable(clipDrawable);
如果我做了第二个更普通的例子,那么我在ImageView中不会得到任何东西,但是如果我将其设置为背景,并在其上放置一个透明的图像,那么它就工作了。由于我想使用缩放类进一步操作ImageView,该类需要将图片设置为src而不是背景,因此我不能同时使用这两个类,要么使用ClipDrawable显示,要么对图像进行缩放

任何帮助都将不胜感激

picture.setImageDrawable(new
    ClipDrawable(new BitmapDrawable(resources, bitmap), gravity, orientation
));

ClipDrawable clipDrawable = (ClipDrawable) picture.getDrawable();
clipDrawable.setLevel(level);