答案 0 :(得分:0)
您可以使用以下方法来伪造您想要达到的效果:
android:foreground="@drawable/image_overlay"
或
imageView.setForeground(imageOverlayDrawable);
这实际上不会使图像透明,但是如果您具有静态的纯色背景色,则足以使图像与背景融合在一起。
如果不是这样,请尝试以下操作:
// Get the image from wherever it lives and create a Bitmap of it
...
// Draw the image to a canvas so that we can modify it
Canvas canvas = new Canvas(image);
Paint imagePaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(imageBitmap, 0, 0, imagePaint);
// Create a paint to draw the overlay with
PorterDuffXfermode porterDuffXfermode = new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY);
Paint overlayPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
overlayPaint.setXfermode(porterDuffXfermode);
// The overlay in this case needs to be a white gradient (where fully opaque means that
// the image will be left untouched and fully transparent will completely erase the image)
Bitmap overlayBitmap = BitmapFactory.decodeResource(getResources(), R.id.drawable.gradient_overlay, Bitmap.Config.ARGB_8888);
// Apply the overlay to create the alpha effect
canvas.drawBitmap(overlayBitmap, 0, 0, overlayPaint);
// Update the ImageView
imageView.setImageBitmap(bitmap);