I'm working on Android game and there are some problem appear I want to fill a color on bitmap object but can not I tried bitmap.setPixel but my Image is PNG format (like a circle or unsharp, surrounded with transparent color) and android can not getHeight() or getWidth(), ie
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);
BitmapDrawable BD = (BitmapDrawable) I. getDrawable(); bitmap = BD. getBitmap(); Then when ever user clicks the button we set the second bitmap variable with the first variable and change the color of the ImageView like this: O = Bitmap.
You can do a check when you want to return the BitMap look to see if the ArrayList of Paths is bigger than 0 and return the BitMap if so, or else return null.
If you're displaying large amounts of bitmap data in your app, you're likely to run into OutOfMemoryError errors. The recycle() method allows an app to reclaim memory as soon as possible. Caution: You should use recycle() only when you are sure that the bitmap is no longer being used.
If you are wanting to fill a bitmap with a solid colour you could try using
Bitmap b = /*however you get a bmp*/
b.eraseColor(color)
It clears the bitmap by filling all pixels with a colour.
Might be the effect you want
Peter
This question may be old, but there is a much simpler solution for this. Instead of applying a filter on the Bitmap image, you can apply it on the ImageView directly:
imageView.setColorFilter(tintColor, PorterDuff.Mode.MULTIPLY);
You can try different color filter modes (ADD, CLEAR, DARKEN, MULTIPLY, ...) depending on your needs and the bitmap supplied to your ImageView.
If it doesn't work, try removing the mode:
imageView.setColorFilter(tintColor);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With