Image Processing – Image with Round Corner
One more guide for you to decorate your image: creating image with rounded corner 🙂
Form this original beauty:
This is the effect:
Pretty simple trick!
I just apply a black rounded corner rectangle to the image.
Here the implementation:
public static Bitmap roundCorner(Bitmap src, float round) { // image size int width = src.getWidth(); int height = src.getHeight(); // create bitmap output Bitmap result = Bitmap.createBitmap(width, height, Config.ARGB_8888); // set canvas for painting Canvas canvas = new Canvas(result); canvas.drawARGB(0, 0, 0, 0); // config paint final Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.BLACK); // config rectangle for embedding final Rect rect = new Rect(0, 0, width, height); final RectF rectF = new RectF(rect); // draw rect to canvas canvas.drawRoundRect(rectF, round, round, paint); // create Xfer mode paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); // draw source image to canvas canvas.drawBitmap(src, rect, rect, paint); // return final image return result; }
Hope you like it!
Cheers,
Pete Houston
if u get error on Src_in cannot be resolved
Use this:—–>
paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.SRC_IN));
INsted oF:—->
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
If anyone having issue with “SRC_IN cannot be resolved or is not a field”, you need to import Mode as import android.graphics.PorterDuff.Mode; it will solve your issue.
Nice article……
Hy Every one , i have resolved the issue of SRC_IN.
use PorterDuff.Mode.SRC_IN instead of Mode.SRC_IN
just import “import android.graphics.PorterDuff.Mode;” and hope it will help you……
Hi,
I’m having the same problem with code in “SRC_IN cannot be resolved or is not a field”.
Please help me .
Hi…your tutorial is really helpful for me…Please keep adding …
The same problem happens to me.
Pls, help us with this issue.
Hi,
I have problem with code please help me .
In my code
SRC_IN cannot be resolved or is not a field.