Search code examples
javaandroidcordovaimage-processingcreatebitmap

createBitmap simple crop android


Code im using:

Bitmap cropImg = Bitmap.createBitmap(bitmap, cropW, cropH, newWidth, newHeight);

Not a java programmer but as i understand it everything is from top left.

my dimensions are

cropW: '696',
cropH: '72',
newWidth: '1200',
newHeight:'1800',

But i end up with the top left of the image..

What i really would like would be like give it 4 points and it takes out the image in the middle.

Im using this as a plugin with Cordova/Phonegap if it makes a difference.

Any help or explanation would be helpful.

Thanks


Solution

  • use Below Function

    public  Bitmap getCircleBitmap(Bitmap bm) {
    
        int sice = Math.min((bm.getWidth()), (bm.getHeight()));
    
        Bitmap bitmap = ThumbnailUtils.extractThumbnail(bm, sice, sice);
    
        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    
        Canvas canvas = new Canvas(output);
    
    
        int color = 0xff424242;
        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        final RectF rectF = new RectF(rect);
    
        paint.setAntiAlias(true);
        paint.setDither(true);
        paint.setFilterBitmap(true);
        paint.setColor(color);
        canvas.drawARGB(0, 0, 0, 0);
    
        canvas.drawOval(rectF, paint);
        //canvas.drawCircle(50, 50, 50, paint);
        paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);
    
     return output;
    

    }