draw circle on bitmap

余生长醉 提交于 2019-12-21 20:09:15

问题


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);

回答1:


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.



来源:https://stackoverflow.com/questions/5531062/draw-circle-on-bitmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!