List of usage examples for android.graphics Color WHITE
int WHITE
To view the source code for android.graphics Color WHITE.
Click Source Link
From source file:Main.java
public static Bitmap getCircleBitmap(Bitmap bitmap) { final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(output); final int color = Color.WHITE; 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);//from w w w. j a v a 2s . c o m canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawOval(rectF, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); bitmap.recycle(); return output; }
From source file:Main.java
public static int getReadableTextColor(final int backgroundColor) { final int greyValue = grayscaleFromRGB(backgroundColor); // 186 chosen rather than the seemingly obvious 128 because of gamma. if (greyValue < 186) { return Color.WHITE; } else {// w ww .java2 s. co m return Color.BLACK; } }
From source file:Main.java
public static Bitmap view2Bitmap(View view) { if (view == null) return null; Bitmap ret = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(ret); Drawable bgDrawable = view.getBackground(); if (bgDrawable != null) { bgDrawable.draw(canvas);// w w w . j ava2 s. c o m } else { canvas.drawColor(Color.WHITE); } view.draw(canvas); return ret; }
From source file:Main.java
public static Bitmap roundCorners(final Bitmap source, final float radius) { int width = source.getWidth(); int height = source.getHeight(); Paint paint = new Paint(); paint.setAntiAlias(true);/*from w w w .j a va2s . c o m*/ paint.setColor(Color.WHITE); Bitmap clipped = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(clipped); canvas.drawRoundRect(new RectF(0, 0, width, height), radius, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); Bitmap rounded = Bitmap.createBitmap(width, height, Config.ARGB_8888); canvas = new Canvas(rounded); canvas.drawBitmap(source, 0, 0, null); canvas.drawBitmap(clipped, 0, 0, paint); source.recycle(); clipped.recycle(); return rounded; }
From source file:Main.java
/** * Adds the white border to the specifed bitmap image using specified border size. * //from www .j a v a 2s. c om * @param bmp to add border * @param borderSize * @return bitmap image with border. */ public static Bitmap addWhiteBorder(Bitmap bmp, int borderSize, int imgSize) { Bitmap bmpWithBorder = Bitmap.createBitmap(bmp.getWidth() + borderSize * 2, bmp.getHeight() + borderSize * 2, bmp.getConfig()); Canvas canvas = new Canvas(bmpWithBorder); canvas.drawColor(Color.WHITE); canvas.drawBitmap(bmp, borderSize, borderSize, null); return bmpWithBorder; }
From source file:Main.java
public static byte[] bmp2bytesStream(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); if (width % 8 != 0) { int adjustWidth = width + (8 - width % 8); final Bitmap.Config config = Bitmap.Config.ARGB_8888; Bitmap whiteBgBitmap = Bitmap.createBitmap(adjustWidth, height, config); Canvas canvas = new Canvas(whiteBgBitmap); canvas.drawColor(Color.WHITE); canvas.drawBitmap(bitmap, 0, 0, null); bitmap = whiteBgBitmap;// w w w.j ava2s . c o m width = bitmap.getWidth(); } int[] pixels = new int[width * height]; bitmap.getPixels(pixels, 0, width, 0, 0, width, height); byte[] image = new byte[width * height]; final byte WHITE = 0, BLACK = 1; for (int i = 0; i < pixels.length; i++) { image[i] = (pixels[i] != 0xFFFFFFFF) ? BLACK : WHITE; } final int COL = width + width % 2; byte[] row = new byte[COL]; byte[] res = new byte[COL / 8 * height]; for (int i = 0, dex = 0, num = 0; i < height; ++i) { System.arraycopy(image, i * width, row, 0, width); for (byte e : row) { res[dex] += e << (7 - num++); num = 8 == num ? 0 : num; dex = 0 == num ? dex + 1 : dex; } } return res; }
From source file:Main.java
public static Bitmap getRoundBitmap(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); Bitmap out = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(out); Paint paint = new Paint(); paint.setColor(Color.WHITE); paint.setAntiAlias(true);// ww w . ja v a 2 s.co m canvas.drawCircle(width / 2, height / 2, width / 2, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); Rect rect = new Rect(0, 0, width, height); canvas.drawBitmap(bitmap, rect, rect, paint); return out; }
From source file:Main.java
public static void showOkDialog(String title, String msg, Activity act) { AlertDialog.Builder dialog = new AlertDialog.Builder(act); if (title != null) { TextView dialogTitle = new TextView(act); dialogTitle.setText(title);//w w w . j a v a2 s .c o m dialogTitle.setPadding(10, 10, 10, 10); dialogTitle.setGravity(Gravity.CENTER); dialogTitle.setTextColor(Color.WHITE); dialogTitle.setTextSize(20); dialog.setCustomTitle(dialogTitle); } if (msg != null) { dialog.setMessage(msg); } dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.dismiss(); } }); AlertDialog dlg = dialog.show(); TextView messageText = (TextView) dlg.findViewById(android.R.id.message); messageText.setGravity(Gravity.CENTER); }
From source file:Main.java
public static Bitmap getBitmapFromView(View view) { Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(returnedBitmap); Drawable bgDrawable = view.getBackground(); if (bgDrawable != null) bgDrawable.draw(canvas);//from w w w. ja v a 2 s .co m else canvas.drawColor(Color.WHITE); view.draw(canvas); return returnedBitmap; }
From source file:Main.java
public static int lighten(final int color, float fraction) { return blendColors(Color.WHITE, color, fraction); }