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

Bitmap cropImg = bitmap.createBitmap (src, startX , StartY, dstWidth, dstHyight);

Picture is great for crop, so you can automatically crop images from different sizes. I create this simple code for:

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

you use bitmap> dt = bitmap

  .createBitmap (src, startX, startY, dstWidth, dstHyight); From documentation   

:

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

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -