我有一个位图:
Bitmap bitmap = BitmapFactory.decodeFile("some/arbitrary/path/image.jpg");
但我不打算向用户显示图像.我希望alpha为100(满分为255).如果这不可能,我可以设置位图的不透明度吗?
解决方法:
您也可以尝试BitmapDrawable而不是Bitmap.如果这对你有用,取决于你使用位图的方式……
编辑
作为评论者问他如何用alpha存储位图,这里有一些代码:
// lets create a new empty bitmap
Bitmap newBitmap = Bitmap.createBitmap(originalBitmap.getWidth(), originalBitmap.getHeight(), Bitmap.Config.ARGB_8888);
// create a canvas where we can draw on
Canvas canvas = new Canvas(newBitmap);
// create a paint instance with alpha
Paint alphaPaint = new Paint();
alphaPaint.setAlpha(42);
// now lets draw using alphaPaint instance
canvas.drawBitmap(originalBitmap, 0, 0, alphaPaint);
// now lets store the bitmap to a file - the canvas has drawn on the newBitmap, so we can just store that one
// please add stream handling with try/catch blocks
FileOutputStream fos = new FileOutputStream(new File("/awesome/path/to/bitmap.png"));
newBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);