Crop image to square - Android -
How can I rotate the rectangular image (600 x 300) to the right and right to fit into the ImageView? I do not want to resize the image, I want to crop it, 300x300. [Solution] As said @ Blackbelt Picture is great for crop, so you can automatically crop images from different sizes. I create this simple code for: you use bitmap> dt = bitmap : Returns the irreversible bitmap from the specified subtotal of the source bitmap. A new bitmap can be similar to a source, or there may be a copy. It is started with the same density as the original bitmap. You can find the documentation Bitmap cropImg = bitmap.createBitmap (src, startX , StartY, dstWidth, dstHyight);
// Drawable bitmap src = BitmapFactory.decodeResource (context.getResources (), R.drawable.image); // bitmap src = null; Try {string url = "http://www.example.com/image.jpg"; InputStream = new java.net.URL (URL) .openstream (); Src = BitmapFactory.decodeStream (in); } Hold (exception e) {e.printStackTrace (); } Width = src.getWidth (); Int height = src.getHeight (); Int crop = (width - height) / 2; Bitmap crop impact = bitmap.Saritmap (source, crop, 0, height, height); ImageView.setImageBitmap (cropImg);
.createBitmap (src, startX, startY, dstWidth, dstHyight); From documentation
Comments
Post a Comment