Created
August 30, 2012 19:09
-
-
Save mkuprionis/3537970 to your computer and use it in GitHub Desktop.
Android snippets, tips & tricks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Hide keyboard | |
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)) | |
.hideSoftInputFromWindow(editText.getWindowToken(), 0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.graphics.Bitmap; | |
import android.graphics.Canvas; | |
import android.graphics.Paint; | |
import android.graphics.PorterDuffXfermode; | |
import android.graphics.Rect; | |
public class ImageHelper { | |
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) { | |
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()); | |
final RectF rectF = new RectF(rect); | |
final float roundPx = pixels; | |
paint.setAntiAlias(true); | |
canvas.drawARGB(0, 0, 0, 0); | |
paint.setColor(color); | |
canvas.drawRoundRect(rectF, roundPx, roundPx, paint); | |
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); | |
canvas.drawBitmap(bitmap, rect, rect, paint); | |
return output; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment