我想知道如果在图像视图中设置或设置为相对布局的背景,我是否可以使图像不透明。
如何使用图像视图或相对布局使图像不透明以动态设置图像,或者是否有其他选项可动态设置图像及其不透明度?
我也希望相同的图像在两个方向上旋转,也可以缩放和缩小到任何级别。
提前致谢
答案 0 :(得分:6)
下面的工作和测试代码。
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);
}