gpt4 book ai didi

android - 如何在Android中用颜色填充位图对象

转载 作者:IT老高 更新时间:2023-10-28 23:27:47 27 4
gpt4 key购买 nike

我正在开发 Android 游戏,但出现了一些问题我想在位图对象上填充颜色但不能我试过bitmap.setPixel,但我的图像是PNG格式(像圆形或不清晰,周围有透明颜色),android不能getHeight()或getWidth(),即

ImageView i = new ImageView(mContext);Bitmap bMap = BitmapFactory.decodeResource(this.mContext.getResources(), mImageIds[position]);

// 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);

最佳答案

如果您想用纯色填充位图,可以尝试使用

Bitmap b = /*however you get a bmp*/
b.eraseColor(color)

它通过用颜色填充所有像素来清除位图。

可能是你想要的效果

彼得

关于android - 如何在Android中用颜色填充位图对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3272841/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com