我怎样才能让图像不透明在一定的水平? [英] How can I make image opaque to some level?
本文介绍了我怎样才能让图像不透明在一定的水平?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如果我可以使图像不透明的,如果设置在图像视图或设置为相对布局的背景。
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 setting the image dynamically or Is there any other option to set image and its opacity dynamically?
我也想相同的图像旋转在两个方向上,也可以zoomin和zoomout到anylevel。
I also want the same image to rotate in both directions and also can zoomin and zoomout to anylevel.
在此先感谢
推荐答案
工作和测试,低于code。
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);
}
- 设置阿尔法半透明 - 价值128
- 在绕原始图像中心为90度
- 放大到原始图像的左上象限
这篇关于我怎样才能让图像不透明在一定的水平?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文