Wednesday 15 January 2014

android - Rounding Only ONE Image Corner - not all four -


I've been using it very general class round corners:

  public static bitmap getRoundedCornerBitmap (bitmap bitmap, integer pixels) {bitmap output = Bitmap.createBitmap (bitmap.getWidth (), bitmap .getHeight (), Config.ARGB_8888); Canvas canvas = new canvas (output); Final interval color = 0xff424242; Last Paint Paint = New Paint (); Last React Rect = New Rect (0, 0, Bitmap .getWidth (), BitmapGetHight ()); Last Rectifier = New Rectifier (Rect); Last float roundPx = pixels; Paint.setAntiAlias ​​(right); Canvas.drawARGB (0, 0, 0, 0); Paint.setColor (color); Canvas.drawRoundRect (rectF, roundPx, roundPx, Paint); Paint.setXfermode (new Portfidfoixform (mode. RCNINI)); Canvas.drawBitmap (bitmap, rect, print, paint); Return output; }   

I want to modify it so that only the top left corner can be rounded. I can not find the parameters in this code? Can anyone help?

This is probably not the most efficient way to do it, but you can fill in your present mask Rounded the corners by painting over the top. You could start after the current use canvas.drawRect to the appropriate areas (corners) (right to call canvas.drawRoundRect ). I think something like this would be only the upper left corner round:

  public static bitmap getRoundedTopLeftCornerBitmap (Bitmap bitmap, integer pixels) {bitmap output = Bitmap.createBitmap (bitmap.getWidth (), bitmap. GetHeight (), Config.ARGB_8888); Canvas canvas = new canvas (output); Final interval color = 0xff424242; Last Paint Paint = New Paint (); Last React Rect = New Rect (0, 0, Bitmap .getWidth (), BitmapGetHight ()); Last Rectifier = New Rectifier (Rect); Last float roundPx = pixels; Last rect topRightRect = new rect (bitmap.getWidth () / 2, 0, bitmap.getWidth (), bitmap.getHeight () / 2); Last Random downconct = new react (0, bitmapgatehit () / 2, bitmap .getWidth (), bitmapgatehit ()); Paint.setAntiAlias ​​(right); Canvas.drawARGB (0, 0, 0, 0); Paint.setColor (color); Canvas.drawRoundRect (rectF, roundPx, roundPx, Paint); // Enter the canvas in the upper right corner. Right (top right, paint); // fill the corners in the bottom canvas.drawRect (the bottom, paint); Paint.setXfermode (new Portfidfoixform (mode. RCNINI)); Canvas.drawBitmap (bitmap, rect, print, paint); Return output; }   

If you feel like this then you can do some customization here, but I think this should work. The general idea should definitely be that I have not tried or tested this code though and it will not be okay if pixels & gt; Bitmap .getWidth () / 2 or pixel & gt; Bitmap.getHeight () / 2 . Again, this was probably true even earlier.

No comments:

Post a Comment