android - Crop square image to circle - Programmatically -
i searching past 1 day , not successful .
i image api , , download bitmap file using following code .
private bitmap downloadimage(string url) { bitmap bitmap = null; inputstream in = null; try { in = openhttpconnection(url); bitmap = bitmapfactory.decodestream(in); in.close(); } catch (ioexception e1) { e1.printstacktrace(); } return bitmap; } private inputstream openhttpconnection(string urlstring) throws ioexception { inputstream in = null; int response = -1; url url = new url(urlstring); urlconnection conn = url.openconnection(); if (!(conn instanceof httpurlconnection)) throw new ioexception("not http connection"); try { httpurlconnection httpconn = (httpurlconnection) conn; httpconn.setallowuserinteraction(false); httpconn.setinstancefollowredirects(true); httpconn.setrequestmethod("get"); httpconn.connect(); response = httpconn.getresponsecode(); if (response == httpurlconnection.http_ok) { in = httpconn.getinputstream(); } } catch (exception ex) { throw new ioexception("error connecting"); } return in; }
and image square , want crop 4 corners , make circular image . there possible way achieve ?
any related answers welcomed . in advance .
public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); drawingview dv = new drawingview(this); setcontentview(dv); } class drawingview extends view { bitmap bitmap; public drawingview(context context) { super(context); bitmap = bitmapfactory.decoderesource(context.getresources(), r.drawable.glossy_overlay); } @override public void ondraw(canvas canvas) { paint paint = new paint(); // paint.setcolor(color.cyan); canvas.drawbitmap(getclip(), 30, 20, paint); } public bitmap getclip() { bitmap output = bitmap.createbitmap(bitmap.getwidth(), bitmap.getheight(), 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.drawcircle(bitmap.getwidth() / 2, bitmap.getheight() / 2, bitmap.getwidth() / 2, paint); paint.setxfermode(new porterduffxfermode(mode.src_in)); canvas.drawbitmap(bitmap, rect, rect, paint); return output; } } }
Comments
Post a Comment