[英]C#, Android: Create bitmap with single color
我想創建僅填充一種顏色(#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 );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.