生活随笔
收集整理的這篇文章主要介紹了
图像处理详解之图像透明度
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Android支持的顏色系統(tǒng)是RGB,Alpha最后的Alpha表示透明度,他的取值是0-255,。通過設(shè)置Alpha的值,我們可以改變圖像的透明度。
下面舉例說明,效果圖如下:
public class MainActivity extends Activity implements OnSeekBarChangeListener{public static int alpha=100;private View myView;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);LinearLayout linearLayout=new LinearLayout(this);linearLayout.setOrientation(LinearLayout.VERTICAL);myView=new MyView(this);myView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 260));SeekBar seekBar=new SeekBar(this);seekBar.setMax(255);//seekbar的初始值seekBar.setProgress(alpha);seekBar.setOnSeekBarChangeListener(this);linearLayout.addView(myView);linearLayout.addView(seekBar);linearLayout.setBackgroundColor(color.white);setContentView(linearLayout);setTitle("Alpha"+alpha);}public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {// TODO Auto-generated method stubalpha=progress;setTitle("Alpha:"+alpha);myView.invalidate();}private class MyView extends View{private Bitmap bitmap;public MyView(Context context) {super(context);// TODO Auto-generated constructor stubInputStream is=getResources().openRawResource(R.drawable.ic_launcher);bitmap=BitmapFactory.decodeStream(is);setBackgroundColor(color.white);}@Overrideprotected void onDraw(Canvas canvas) {// TODO Auto-generated method stubPaint paint=new Paint();paint.setAlpha(alpha);//第二個(gè)參數(shù)表示源位圖的復(fù)制區(qū)域,第三個(gè)參數(shù)表示繪制的目標(biāo)區(qū)域canvas.drawBitmap(bitmap, new Rect(0,0,bitmap.getWidth(),bitmap.getHeight()),new Rect(10,10,310,235), paint);}}public void onStartTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub}public void onStopTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub}
}
總結(jié)
以上是生活随笔為你收集整理的图像处理详解之图像透明度的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。