如何将图像按钮的背景设置为用户拍摄的照片?

发布于 2024-10-04 09:38:19 字数 393 浏览 0 评论 0原文

我希望能够将 xml 文件中的图像按钮的背景设置为用户在手机上拍摄的图片。

我将图片设置为cameraBitmap。

cameraBitmap = (Bitmap) intent.getExtras().get("data");

我想传递该图片作为图像按钮的背景。问题是,方法:setBackgroundDrawable()只能传入一个drawable。我该如何将该位图更改为可绘制图片并将其设为背景?

我目前有:

private ImageButton theImageButton;


theImageButton.setBackgroundDrawable(cameraBitmap);

I want to be able to set the background of an image button in an xml file to be the picture the user took on the phone.

I have the picture set as cameraBitmap.

cameraBitmap = (Bitmap) intent.getExtras().get("data");

and I want to pass that picture to be the bakground of the imagebutton. The problem is, the method: setBackgroundDrawable() only can pass in a drawable. How do I go about changing that Bitmap to a drawable picture and making it the background?

I currently have:

private ImageButton theImageButton;


theImageButton.setBackgroundDrawable(cameraBitmap);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋千易 2024-10-11 09:38:19

如果您正在使用 ImageButton 为什么不能使用它

theImageButton.setImageBitmap(cameraBitmap)

If you are using ImageButton why can't you use this

theImageButton.setImageBitmap(cameraBitmap)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文