I would like to know if I can make an image opaque if set in image view or set as background of relative layout.
How can I make image opaque using image view or relative layout for set开发者_StackOverflowting the image dynamically or Is there any other option to set image and its opacity dynamically?
I also want the same image to rotate in both directions and also can zoomin and zoomout to anylevel.
Thanks in advance
Working and tested code below.
private void applyTransformToImageView(int code)
{
Bitmap bmpOriginal = BitmapFactory.decodeResource(this.getResources(), R.drawable.image2);
Bitmap bmResult = Bitmap.createBitmap(bmpOriginal.getWidth(), bmpOriginal.getHeight(), Bitmap.Config.ARGB_8888);
Canvas tempCanvas = new Canvas(bmResult);
switch (code)
{
case CHANGE_TRANSPARENCY:
{
Paint alphaPaint = new Paint();
alphaPaint.setAlpha(128);
tempCanvas.drawBitmap(bmpOriginal, 0, 0, alphaPaint);
}
break;
case ROTATE:
{
tempCanvas.rotate(90, bmpOriginal.getWidth()/2, bmpOriginal.getHeight()/2);
tempCanvas.drawBitmap(bmpOriginal, 0, 0, null);
}
break;
case ZOOM_IN:
{
Rect zoomRegion = new Rect();
zoomRegion.left = 0;
zoomRegion.top = 0;
zoomRegion.right = bmpOriginal.getWidth()/2;
zoomRegion.bottom = bmpOriginal.getHeight()/2;
Rect display = new Rect();
display.left = 0;
display.top = 0;
display.right = bmpOriginal.getWidth();
display.bottom = bmpOriginal.getHeight();
tempCanvas.drawBitmap(bmpOriginal, zoomRegion, display, null);
}
break;
default:
}
mImageView.setImageBitmap(bmResult);
}
- sets alpha to semi-transparent - value 128
- rotates around original image center for 90 degrees
- zoom into top left quadrant of the original image
精彩评论