Crop image and place it in image view in android -
my aim set circular profile pic app.user can crop image , place profile pic. code can crop pic unable place in image view.please !!! please find code below:
intent photopickerintent = new intent(intent.action_pick, android.provider.mediastore.images.media.external_content_uri); photopickerintent.settype("image/*"); photopickerintent.putextra("crop", "true"); photopickerintent.putextra("return-data", true); photopickerintent.putextra("outputformat", bitmap.compressformat.jpeg.tostring()); startactivityforresult(photopickerintent,select_picture_profile); } protected void onactivityresult(int requestcode, int resultcode, intent imagereturnedintent, intent data) { super.onactivityresult(requestcode, resultcode, imagereturnedintent); switch (requestcode) { case select_picture_profile: if (resultcode == result_ok) { if (imagereturnedintent!=null) { bundle extras = imagereturnedintent.getextras(); bitmap selectedbitmap = extras.getparcelable("data"); bitmapdrawable bd=new bitmapdrawable(getresources(), selectedbitmap); imageviewround = (imageview) findviewbyid(r.id.cimgv1); imageviewround.setimagedrawable(bd); } } }
public static bitmap getcroppedbitmap(bitmap bitmap) { bitmap output = bitmap.createbitmap(bitmap.getwidth(), bitmap.getheight(), bitmap.config.argb_8888); canvas canvas = new canvas(output); final int color = 0xff424242; final paint paint = new paint(); final rect rect = new rect(0, 0, bitmap.getwidth(), bitmap.getheight()); paint.setantialias(true); canvas.drawargb(0, 0, 0, 0); paint.setcolor(color); // canvas.drawroundrect(rectf, roundpx, roundpx, paint); canvas.drawcircle(bitmap.getwidth() / 2, bitmap.getheight() / 2, bitmap.getwidth() / 2, paint); paint.setxfermode(new porterduffxfermode(porterduff.mode.src_in)); canvas.drawbitmap(bitmap, rect, rect, paint); //bitmap _bmp = bitmap.createscaledbitmap(output, 60, 60, false); //return _bmp; return output; }
use function cropped image.
Comments
Post a Comment