Skip to main content

Posts

Showing posts with the label android-canvas

General Android semi transparent bug

I use anti aliasing to make my images more smooth. When using anti aliasing a dark border will be drawn around the images. This happens because Android uses the color black and mixes it with the yellow from the images. This is a gernal problem! When I draw a rectangle and set the alpha value to 127 the image also gets quiet dark. Instead of using black Android should use white to draw the transparency.

draw rectangle on a picture from pixels coordinates

with the following code i can draw a rectangle on my bitmap image. Paint paint = new Paint(); paint.setStyle(Style.STROKE); paint.setColor(Color.BLUE); publishProgress(80); Canvas canvas = new Canvas(mBitmap); publishProgress(85); canvas.drawRect(200, 100, 200, 100, paint); bitmap.recycle(); channel.close(); i've read that the values given in canvas.drawRect(200, 100, 200, 100, paint); represent respectively left x, top y, right x and bottom y. So my questions are : are those values in pixels? ppi or what?? how can i draw a rectangle on my image if i have only the coordinates of each corners in pixels as shown on the picture below ? assuming that i have A (x, y) B (x, y), C(x, y) and D(x, y) with x and y expressed in pixels from the axes of the picture below. NB: i don't have control on A,B,C,D they are given to me from a web service

Determine width and height of a bitmap

I am using the following code snippet to create a bitmap with text. Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setStyle(Style.FILL); paint.setColor(fontColor); paint.setTextSize(fontSize); canvas.drawText("My Text", x, y, paint); Here's the catch. How do I determine the size of the Bitmap to use in the canvas beforehand? For instance if I want a bitmap with "Hello World!" on it, I want to find the width and height of it even before I draw the text on the canvas.