c# - C#,Android:创建单色位图
问题描述
我想创建一个只填充一种颜色(#eeeeee)的位图。我设法创建了一个位图并将其设置为它的视图,但我似乎找不到正确的方法来用我想要的颜色完全填充它。输出始终只是一个白色矩形。但它需要像#eeeeee 中那样呈灰色。这是我的努力:
Bitmap greyBitmap = Bitmap.CreateBitmap(1000, 500, Bitmap.Config.Argb8888);
Bitmap mutableBitmap = greyBitmap.Copy(Bitmap.Config.Argb8888, true);//<–true makes copy mutable
Canvas canvas = new Canvas(mutableBitmap);
Paint paint = new Paint();
paint.Color = new Color(Color.ParseColor("#eeeeee"));
canvas.DrawRect(1000, 500, 1000, 500, paint);
vh.dr = new BitmapDrawable(mutableBitmap);
很有可能,我采取了太多步骤......请随时纠正我。
解决方案
在 Mike M.
Bitmap greyBitmap = Bitmap.CreateBitmap(1000, 500, Bitmap.Config.Argb8888);
Canvas canvas = new Canvas(greyBitmap );
Paint paint = new Paint();
paint.Color = new Color(Color.ParseColor("#eeeeee")); // set any color here
canvas.DrawRect(0, 0, 1000, 500, paint);
vh.dr = new BitmapDrawable(greyBitmap );
推荐阅读
- django - 如何获取 Cloudinary 对象的绝对 URL
- r - 如何在使用闪亮时传递checkboxGroup的选定输入值以用作geom_col()的ggplot2交互中的参数?
- codeigniter-3 - fsockopen(): 无法连接到远程服务器 ip Codeigniter
- icmp - 无法从 GNS3 拓扑 ping 到物理适配器
- node.js - 节点 cli 脚本中未读取 dotenv 文件
- javascript - Mongoose 架构突然失效
- javascript - 即使相同的代码适用于另一个组件,部分功能组件也不会在 React 中呈现
- probability-theory - 伯努利渗流
- django - 尝试在 urlpattern 中使用用户名来为每个用户提供唯一的链接
- laravel - 如何通过检查元素进行编辑,但是当我单击提交时,它不会进行任何更改?