Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中动态更改位图的不透明度_Android_Opacity_Alpha_Seekbar - Fatal编程技术网

如何在android中动态更改位图的不透明度

如何在android中动态更改位图的不透明度,android,opacity,alpha,seekbar,Android,Opacity,Alpha,Seekbar,可能重复: 我想更改seekbar进程更改时位图的不透明度。我正在使用下面的代码 opacityseekbar.setMax(255); opacityseekbar.setProgress(255); opacityseekbar.setOnSeekBarChangeListener( new OnSeekBarChangeListener() { public void onStopTrackingTouch(See

可能重复:

我想更改seekbar进程更改时位图的不透明度。我正在使用下面的代码

opacityseekbar.setMax(255);
opacityseekbar.setProgress(255);
opacityseekbar.setOnSeekBarChangeListener( new OnSeekBarChangeListener()
                {

                    public void onStopTrackingTouch(SeekBar arg0) {
                        // TODO Auto-generated method stub


                    }

                    public void onStartTrackingTouch(SeekBar arg0) {
                        // TODO Auto-generated method stub

                    }

                    public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
                        // TODO Auto-generated method stub
                        Log.e("Progress Value", "Progress number" + arg1);


                        Bitmap mutableBitmap = theTattoo.isMutable()? theTattoo: theTattoo.copy(Bitmap.Config.ARGB_8888, true);
                        Canvas canvas = new Canvas(mutableBitmap);
                        int colour = ((opacityseekbar.getProgress() << 24) & 0xFF000000);
                        canvas.drawColor(colour, Mode.DST_IN);

                        theTattoo=mutableBitmap;




                    }
                });
opacityseekbar.setMax(255);
设置进度(255);
setOnSeekBarChangeListener(新的OnSeekBarChangeListener()
{
TopTrackingTouch上的公共无效(请参见kbar arg0){
//TODO自动生成的方法存根
}
开始跟踪触摸时的公共无效(请参见kbar arg0){
//TODO自动生成的方法存根
}
public void onProgressChanged(请参见kbar arg0、int arg1、boolean arg2){
//TODO自动生成的方法存根
Log.e(“进度值”、“进度编号”+arg1);
位图可变位图=theattoo.isMutable()?theattoo:theattoo.copy(Bitmap.Config.ARGB_8888,true);
画布画布=新画布(可变位图);

int color=((opacityseekbar.getProgress()使用
BitmapDrawable
而不是直接使用
位图

更改不透明度要容易得多:

BitmapDrawable bmpDrawable = new BitmapDrawable(getResources(), bitmap);
bmpDrawable.setAlpha(150);

使用
位图可绘制
而不是直接使用
位图

更改不透明度要容易得多:

BitmapDrawable bmpDrawable = new BitmapDrawable(getResources(), bitmap);
bmpDrawable.setAlpha(150);

您可以使用Color.argb..以下是示例代码

canvas.drawColor(Color.argb(alpha, red, green, blue));
其中alpha是不透明度,因此可以在alpha中使用进度值

这里的aplha、红色、绿色和蓝色必须为0到255


在您的情况下,每次都必须通过相同的RGB,只需更改Alpha值即可。您可以使用Color.argb。以下是示例代码

canvas.drawColor(Color.argb(alpha, red, green, blue));
其中alpha是不透明度,因此可以在alpha中使用进度值

这里的aplha、红色、绿色和蓝色必须为0到255


在您的情况下,每次都必须通过相同的RGB,只需更改Alpha值即可

我需要以位图的形式获得最终结果在这种情况下,您可以创建一个新位图,并在位图上绘制BitmapDrawable。我尝试了此代码。但它会一次又一次地返回相同的位图。我认为它只适用于不透明度的静态更改,而不适用于动态更改。这也是仅在HTC one M8中不起作用。不确定为什么要以位图形式获得最终结果,只需调用
bmpDrawable.getBitmap();
我需要以位图的形式获得最终结果在这种情况下,您可以创建一个新的位图,并在位图上绘制BitmapDrawable。我尝试了此代码。但它一次又一次地返回相同的位图。我认为它只适用于不透明度的静态更改,而不适用于动态更改。此外,这不仅适用于HTC one M8。不确定为什么要获得最终结果作为位图,只需调用
bmpDrawable.getBitmap();
canvas.drawColor(Color.argb(alpha,red,green,blue));尝试搜索第一个canvas.drawColor(Color.argb(alpha,red,green,blue));首先尝试搜索,我们必须将R,G,B值设置为?我认为@Dalmas答案更简单。我们必须将R,G,B值设置为?我认为@Dalmas答案更简单。