Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.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以编程方式显示位图的一部分?_Android_Image_Bitmap - Fatal编程技术网

Android 如何使用ClipDrawable以编程方式显示位图的一部分?

Android 如何使用ClipDrawable以编程方式显示位图的一部分?,android,image,bitmap,Android,Image,Bitmap,我试图展示图像的某一部分 例如: 我尝试使用下面的代码从位图中设置图像视图的ClipDrawable,但它没有显示 BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap); ClipDrawable clipDrawable = new ClipDrawable(bitmapDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL); clipDrawable.s

我试图展示图像的某一部分

例如:

我尝试使用下面的代码从
位图中设置
图像视图的
ClipDrawable
,但它没有显示

BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
ClipDrawable clipDrawable = new ClipDrawable(bitmapDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);
clipDrawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
clipDrawable.setLevel(5000);
imageView.setImageDrawable(clipDrawable);
我还通过查看
imageView.setImageDrawable(BitmapDrawable)
是否会显示完整图像来测试
BitmapDrawable
是否存在问题

如何使用
ClipDrawable
显示
位图的一小部分

为什么图像没有出现

我看了一下,但接受的答案是假设可以从资源中检索图像,而我正在动态加载图像

这篇文章的答案不是用
ClipDrawable
回答我的问题,而是用幻数创建一个新的
位图


只有在XML中设置了
可绘制的
时,才能解释如何解决此问题

设置级别后,您需要在clipdrawable上调用
invalidateSelf
,或者您应该尝试以下操作:

imageView.setBackground(clipDrawable);
imageView.setImageResource(android.R.color.transparent);

提供人:

设置级别后,您需要在clipdrawable上调用
invalidateSelf
,或者您应该尝试以下操作:

imageView.setBackground(clipDrawable);
imageView.setImageResource(android.R.color.transparent);

提供人:

设置级别后,您需要在clipdrawable上调用
invalidateSelf
,或者您应该尝试以下操作:

imageView.setBackground(clipDrawable);
imageView.setImageResource(android.R.color.transparent);

提供人:

设置级别后,您需要在clipdrawable上调用
invalidateSelf
,或者您应该尝试以下操作:

imageView.setBackground(clipDrawable);
imageView.setImageResource(android.R.color.transparent);

提供人:

您能否只修改
setBounds
width
height
参数?我不是一个android开发人员,但是看到你如何将它传递到
ClipDrawable
,它有一个
setBounds
方法,我会这么认为。在第二次阅读您的帖子后,您是否在显示图像时遇到问题?如果是这样的话,你应该让你的帖子与problem@VinceEmigh是的,当我调用
imageView.setImageDrawable(clipDrawable)
时,它没有显示。我会编辑这篇文章。您认为我应该如何更改
setBounds
方法的参数?检查我的答案:您不能只修改
setBounds
宽度和
高度
参数吗?我不是一个android开发人员,但是看到你如何将它传递到
ClipDrawable
,它有一个
setBounds
方法,我会这么认为。在第二次阅读您的帖子后,您是否在显示图像时遇到问题?如果是这样的话,你应该让你的帖子与problem@VinceEmigh是的,当我调用
imageView.setImageDrawable(clipDrawable)
时,它没有显示。我会编辑这篇文章。您认为我应该如何更改
setBounds
方法的参数?检查我的答案:您不能只修改
setBounds
宽度和
高度
参数吗?我不是一个android开发人员,但是看到你如何将它传递到
ClipDrawable
,它有一个
setBounds
方法,我会这么认为。在第二次阅读您的帖子后,您是否在显示图像时遇到问题?如果是这样的话,你应该让你的帖子与problem@VinceEmigh是的,当我调用
imageView.setImageDrawable(clipDrawable)
时,它没有显示。我会编辑这篇文章。您认为我应该如何更改
setBounds
方法的参数?检查我的答案:您不能只修改
setBounds
宽度和
高度
参数吗?我不是一个android开发人员,但是看到你如何将它传递到
ClipDrawable
,它有一个
setBounds
方法,我会这么认为。在第二次阅读您的帖子后,您是否在显示图像时遇到问题?如果是这样的话,你应该让你的帖子与problem@VinceEmigh是的,当我调用
imageView.setImageDrawable(clipDrawable)
时,它没有显示。我会编辑这篇文章。您认为我应该如何更改
setBounds
方法的参数?请检查我的答案: