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

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -