Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

draw circle on bitmap

i've written an app that captures a picture and saves it on the sdcard. i then can load that image into an imageview to display it. i'd like to draw a circle on the bitmap before i display it. the code below displays the bitmap but no circle, any ideas why the circle is not there?

thanks.

BitmapFactory.Options bfo = new BitmapFactory.Options();
        bfo.inSampleSize = 5;
        Bitmap bm = BitmapFactory.decodeByteArray(imageArray, 0, imageArray.length, bfo);
        Log.e(TAG, bm.toString());
        //imageview.setImageBitmap(bm);


        Bitmap bmOverlay = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), bm.getConfig());
        canvas = new Canvas(bmOverlay);
        Paint paint = new Paint();
        paint.setColor(Color.RED);
        canvas.drawBitmap(bm, new Matrix(), null);
        canvas.drawCircle(750, 14, 11, paint);
        imageview.setImageBitmap(bmOverlay);
like image 503
turtleboy Avatar asked Apr 03 '11 17:04

turtleboy


People also ask

How do you draw a bitmap?

To draw on a bitmap, use the image control's canvas and attach the mouse-event handlers to the appropriate events in the image control. Typically, you would use region operations (fills, rectangles, polylines, and so on). These are fast and efficient methods of drawing.


1 Answers

You might check bm.getWidth. If you are using a sample size of 5 then your image will be 5 times smaller than the original, causing your circle to disappear off the right side of the image.

You could try:

paint.setStrokeWidth(10);
canvas.drawCircle(50, 50, 25);

just as a sanity check.

like image 156
Matthew Willis Avatar answered Oct 17 '22 04:10

Matthew Willis