List of usage examples for android.graphics Canvas drawARGB
public void drawARGB(int a, int r, int g, int b)
From source file:com.clov4r.moboplayer.android.nil.codec.activity.MoboThumbnailTestActivity.java
public Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) { try {/*from w w w. j a v a 2s .com*/ Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight())); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(Color.BLACK); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); final Rect src = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); canvas.drawBitmap(bitmap, src, rect, paint); return output; } catch (Exception e) { return bitmap; } }
From source file:potboiler.client.PotsActivity.java
License:asdf
private void createDrawerMenu() { mMenuItems = getResources().getStringArray(R.array.menu_sections); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawer = (LinearLayout) findViewById(R.id.left_drawer); mCommandsList = (ListView) findViewById(R.id.commands); User user = PreferenceUtils.getUser(this); ((TextView) findViewById(R.id.name)).setText(user.username); Bitmap bitmap = ImageUtils.getImageFromFile(this, FileUtils.getImagesPath(this) + user.serverId); if (bitmap != null) { /*Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); // w w w . j a v a2s.c om BitmapShader shader = new BitmapShader (bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); Paint paint = new Paint(); paint.setShader(shader); paint.setAntiAlias(true); Canvas c = new Canvas(circleBitmap); c.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint);*/ int w = bitmap.getWidth(); int h = bitmap.getHeight(); int radius = Math.min(h / 2, w / 2); Bitmap circleBitmap = Bitmap.createBitmap(w + 8, h + 8, Bitmap.Config.ARGB_8888); Paint paint = new Paint(); paint.setAntiAlias(true); Canvas c = new Canvas(circleBitmap); c.drawARGB(0, 0, 0, 0); paint.setStyle(Paint.Style.FILL); c.drawCircle((w / 2) + 4, (h / 2) + 4, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); c.drawBitmap(bitmap, 4, 4, paint); paint.setXfermode(null); paint.setStyle(Paint.Style.STROKE); paint.setColor(Color.WHITE); paint.setStrokeWidth(3); c.drawCircle((w / 2) + 4, (h / 2) + 4, radius, paint); ((ImageView) findViewById(R.id.avatar)).setImageBitmap(circleBitmap); } mDrawerLayout.setScrimColor(getResources().getColor(android.R.color.transparent)); DrawerAdapter adapter = new DrawerAdapter(this, R.layout.item_drawer_list, R.id.title, mMenuItems); mCommandsList.setAdapter(adapter); mCommandsList.setOnItemClickListener(new DrawerItemClickListener()); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.pots, R.string.pots) { public void onDrawerClosed(View view) { super.onDrawerClosed(view); syncActionBarArrowState(); // invalidateOptionsMenu(); // mDrawerToggle.syncState(); // setRefreshMenu(); } public void onDrawerOpened(View drawerView) { // super.onDrawerClosed(drawerView); super.onDrawerOpened(drawerView); mDrawerToggle.setDrawerIndicatorEnabled(true); // invalidateOptionsMenu(); // mDrawerToggle.syncState(); // setRefreshMenu(); } @Override public void onDrawerSlide(View drawerView, float slideOffset) { super.onDrawerSlide(drawerView, slideOffset); float xPositionOpenDrawer = mCommandsList.getWidth(); float xPositionWindowContent = (slideOffset * xPositionOpenDrawer); FrameLayout mHostFragment = (FrameLayout) findViewById(R.id.content_frame); mHostFragment.setX(xPositionWindowContent); getActionBarView().setX(xPositionWindowContent); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerToggle.syncState(); getSupportFragmentManager().addOnBackStackChangedListener(mOnBackStackChangedListener); findViewById(R.id.signout).setOnClickListener(this); }
From source file:ch.ethz.dcg.jukefox.manager.libraryimport.AndroidAlbumCoverFetcherThread.java
private void drawTextOnBitmap(CompleteAlbum album, Bitmap bitmapHigh, int bitmapSize, float textHeight) { Canvas canvas = new Canvas(bitmapHigh); canvas.drawARGB(0, 125, 125, 125); Paint paint = new Paint(); paint.setColor(Color.BLACK);/*www . ja v a 2 s . co m*/ paint.setTypeface(Typeface.SERIF); paint.setSubpixelText(true); paint.setTextSize(textHeight); paint.setAntiAlias(true); String artist = album.getArtists().get(0).getName(); String shortenedText = new String(artist); int textLength = artist.length(); if (textLength > 18) { shortenedText = artist.substring(0, 15) + "..."; textLength = 18; } else if (textLength < 8) { while (shortenedText.length() < 8) { shortenedText = " " + shortenedText + " "; } } float pixelLength = paint.measureText(shortenedText); paint.setTextSize(textHeight * (bitmapSize * 2 / 3) / pixelLength); canvas.drawText(shortenedText, bitmapSize / 6, bitmapSize / 3, paint); shortenedText = album.getName(); textLength = album.getName().length(); if (textLength > 18) { shortenedText = album.getName().substring(0, 15) + "..."; textLength = 18; } else if (textLength < 8) { while (shortenedText.length() < 8) { shortenedText = " " + shortenedText + " "; } } paint.setTextSize(bitmapSize / 10f); pixelLength = paint.measureText(shortenedText); textHeight = textHeight * bitmapSize * 2f / 3f / pixelLength; paint.setTextSize(textHeight); canvas.drawText(shortenedText, bitmapSize / 6f, bitmapSize * 2 / 3f + textHeight, paint); }
From source file:com.android.andryyu.lifehelper.widget.RippleView.java
private Bitmap getCircleBitmap(final int radius) { final Bitmap output = Bitmap.createBitmap(originBitmap.getWidth(), originBitmap.getHeight(), Bitmap.Config.ARGB_8888);// w w w. j a v a 2s. c o m final Canvas canvas = new Canvas(output); final Paint paint = new Paint(); final Rect rect = new Rect((int) (x - radius), (int) (y - radius), (int) (x + radius), (int) (y + radius)); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); canvas.drawCircle(x, y, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(originBitmap, rect, rect, paint); return output; }
From source file:com.crazyapk.util.bitmap.ImageWorker.java
public Bitmap toRoundCorner(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);/*ww w . j ava2s .c o m*/ 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; }
From source file:com.linhnv.apps.maxim.utils.ImageWorker.java
private BitmapDrawable roundCornered(BitmapDrawable scaledBitmap, int i) { Bitmap bitmap = scaledBitmap.getBitmap(); Bitmap result = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); int color = 0xff424242; Paint paint = new Paint(); Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); RectF rectF = new RectF(rect); int roundPx = i; paint.setAntiAlias(true);//from www . j a v a 2 s. c om canvas.drawARGB(0, 0, 0, 0); // paint.setColor(Color.BLUE); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); BitmapDrawable finalresult = new BitmapDrawable(mResources, result); return finalresult; }
From source file:fr.mathieu.berengere.safdemo.CameraActivity.java
public Bitmap makeTransparent(Bitmap src, int value) { int width = src.getWidth(); int height = src.getHeight(); Bitmap transBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(transBitmap); canvas.drawARGB(0, 0, 0, 0); // config paint final Paint paint = new Paint(); paint.setAlpha(value);/* w w w . j a v a2 s .c o m*/ canvas.drawBitmap(src, 0, 0, paint); return transBitmap; }
From source file:com.yk.notification.util.BitmapUtil.java
/** * //from ww w .j av a 2s . com * * @param bitmap * ?Bitmap * @param roundPx * ? * @return Bitmap */ public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) { 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); 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; }
From source file:com.yk.notification.util.BitmapUtil.java
/** * ??//from www.j a v a2 s .c o m * * @param bitmap * Bitmap * @return Bitmap */ public static Bitmap getRoundBitmap(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); float roundPx; float left, top, right, bottom, dst_left, dst_top, dst_right, dst_bottom; if (width <= height) { roundPx = width / 2; top = 0; bottom = width; left = 0; right = width; height = width; dst_left = 0; dst_top = 0; dst_right = width; dst_bottom = width; } else { roundPx = height / 2; float clip = (width - height) / 2; left = clip; right = width - clip; top = 0; bottom = height; width = height; dst_left = 0; dst_top = 0; dst_right = height; dst_bottom = height; } Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect src = new Rect((int) left, (int) top, (int) right, (int) bottom); final Rect dst = new Rect((int) dst_left, (int) dst_top, (int) dst_right, (int) dst_bottom); final RectF rectF = new RectF(dst); 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, src, dst, paint); return output; }
From source file:com.tct.mail.utils.NotificationUtils.java
/** * Crop a square bitmap into a circular one. Used for both contact photos and letter tiles. * @param icon Square bitmap to crop/*from w w w . ja v a 2 s . c o m*/ * @return Circular bitmap */ private static Bitmap cropSquareIconToCircle(Bitmap icon) { final int iconWidth = icon.getWidth(); final Bitmap newIcon = Bitmap.createBitmap(iconWidth, iconWidth, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(newIcon); final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, icon.getWidth(), icon.getHeight()); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); canvas.drawCircle(iconWidth / 2, iconWidth / 2, iconWidth / 2, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(icon, rect, rect, paint); return newIcon; }