Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android how to draw a bitmap on canvas semi transparent

Tags:

I have tried to modify a Paint variable, but have been unsuccessful - how can I make a bitmap appear "semi-transparent"?

like image 888
GideonKain Avatar asked Sep 15 '11 23:09

GideonKain


People also ask

How do I make bitmap transparent in Android?

Using adjustOpacity , I make ImageView 's Bitmap be semi-transparent. Bitmap newBitmap = adjustOpacity(orignalBitmap, 10); view. setImageBitmap(newBitmap); view. setBackgroundColor(Color.

How do you make a bitmap on Canvas?

Use the Canvas method public void drawBitmap (Bitmap bitmap, Rect src, RectF dst, Paint paint) . Set dst to the size of the rectangle you want the entire image to be scaled into. EDIT: Here's a possible implementation for drawing the bitmaps in squares across on the canvas.

Can we draw directly on Canvas in android studio?

The parameter to onDraw() is a Canvas object that the view can use to draw itself. The Canvas class defines methods for drawing text, lines, bitmaps, and many other graphics primitives. You can use these methods in onDraw() to create your custom user interface (UI).


2 Answers

canvas.drawColor(Color.WHITE);    BitmapDrawable bd = (BitmapDrawable) getResources().getDrawable(R.drawable.loading);     Bitmap bm = bd.getBitmap();     Paint paint = new Paint();     paint.setAlpha(60);                             //you can set your transparent value here     canvas.drawBitmap(bm, 0, 0, paint); 
like image 109
waychow Avatar answered Sep 18 '22 09:09

waychow


Paint p = new Paint(); p.setAlpha(70);  Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.wallpaper); canvas.drawBitmap(image, xPosition, yPosition, p);  
like image 37
praveen s Avatar answered Sep 22 '22 09:09

praveen s