Crop image to square - Android -



Crop image to square - Android -

how can cutting rectangular image (600 x 300) left , right fit in square imageview ? don't want resize image, want crop it, 300 x 300.

[solution]

as @blackbelt said

bitmap cropimg = bitmap.createbitmap(src, startx, starty, dstwidth, dstheight);

is great cropping images. how can automatically crop images different sizes. create simple code that:

// drawable bitmap src= bitmapfactory.decoderesource(context.getresources(), r.drawable.image); // url bitmap src = null; seek { string url = "http://www.example.com/image.jpg"; inputstream in = new java.net.url(url).openstream(); src = bitmapfactory.decodestream(in); } grab (exception e) { e.printstacktrace(); } int width = src.getwidth(); int height = src.getheight(); int crop = (width - height) / 2; bitmap cropimg = bitmap.createbitmap(src, crop, 0, height, height); imageview.setimagebitmap(cropimg);

you can utilize

bitmap dst = bitmap.createbitmap(src, startx, starty, dstwidth, dstheight);

from documentation:

returns immutable bitmap specified subset of source bitmap. new bitmap may same object source, or re-create may have been made. initialized same density original bitmap.

here can find documentation

android android-imageview resize-crop

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -