给图片的边缘加上光晕

[img]http://dl.iteye.com/upload/attachment/573899/3cdc5027-d590-3edb-b84d-d9dd56e832fa.jpg[/img]

[img]http://dl.iteye.com/upload/attachment/573901/fadecba1-20bf-3cbe-88cb-292bbfd135a3.jpg[/img]


ImageView v = (ImageView)findViewById(R.id.image);//一定要给ImageView加上几个像素的Padding,要不然效果出来不了
Paint p= new Paint();
p.setColor(Color.RED);//红色的光晕
BitmapDrawable bd = (BitmapDrawable) v.getDrawable();
Bitmap b = bd.getBitmap();
Bitmap bitmap = Bitmap.createBitmap(bd.getIntrinsicWidth(), bd.getIntrinsicHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawBitmap(b.extractAlpha(), 0, 0, p);

StateListDrawable sld = new StateListDrawable();
sld.addState(new int[]{android.R.attr.state_pressed}, new BitmapDrawable(bitmap));

v.setBackgroundDrawable(sld);


参考[url]http://gundumw100.iteye.com/blog/1205547#comments[/url]

你可能感兴趣的:(android效果汇集)