我正在研究Android游戏,并且出现了一些问题,我想在位图对象上填充颜色,但我不能尝试bitmap.setPixel但我的图像是PNG格式(如圆形或不锐化,用透明色包围)和android不能getHeight()或getWidth(),即
ImageView i = new ImageView(mContext); Bitmap bMap = BitmapFactory.decodeResource(this.mContext.getResources(), mImageIds[position]);Run Code Online (Sandbox Code Playgroud)// for(int i1 = 0; i1 < bMap.getHeight();i1++) // for(int j = 0; j < bMap.getWidth(); j ++) // bMap.setPixel(i1, j, Color.RED); //can not set
i.setImageBitmap(bMap); i.setLayoutParams(new Gallery.LayoutParams(150, 100)); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setBackgroundResource(mGalleryItemBackground); i.setBackgroundColor(Color.TRANSPARENT);
小智 45
如果您想填充纯色的位图,可以尝试使用
Bitmap b = /*however you get a bmp*/
b.eraseColor(color)
Run Code Online (Sandbox Code Playgroud)
它通过用颜色填充所有像素来清除位图.
可能是你想要的效果
彼得
| 归档时间: |
|
| 查看次数: |
17654 次 |
| 最近记录: |