List of usage examples for android.graphics Paint Paint
public Paint()
From source file:Main.java
public static Bitmap drawTextToBitmap(Bitmap bitmap, String gText) { OutputStream outStream = null; Bitmap.Config bitmapConfig = bitmap.getConfig(); // set default bitmap config if none if (bitmapConfig == null) { bitmapConfig = Bitmap.Config.ARGB_8888; }/*from w w w . j a v a2s .c o m*/ String dataPath = Environment.getExternalStorageDirectory().toString() + "/SignChat/Temp/temp" + "0" + pictureNum + ".jpg"; try { FileOutputStream out = new FileOutputStream(dataPath); // NEWLY ADDED CODE STARTS HERE [ Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setColor(Color.WHITE); // Text Color paint.setStrokeWidth(12); // Text Size paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); // Text // Overlapping // Pattern // some more settings... canvas.drawBitmap(bitmap, 0, 0, paint); canvas.drawText("Testing...", 10, 10, paint); // NEWLY ADDED CODE ENDS HERE ] bitmap.compress(CompressFormat.JPEG, 90, out); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } return bitmap; }
From source file:Main.java
public static void drawFPS(Canvas canvas, String text) { if (PAINT_FPS == null) { PAINT_FPS = new Paint(); PAINT_FPS.setColor(Color.RED); PAINT_FPS.setTextSize(30);/* ww w . j a v a 2s . c o m*/ } int top = canvas.getHeight() - 50; clearCanvas(canvas, 10, top - 50, (int) (PAINT_FPS.measureText(text) + 20), canvas.getHeight()); canvas.drawText(text, 10, top, PAINT_FPS); }
From source file:Main.java
static public void setImageColor(ImageView view, Bitmap sourceBitmap, int rgbcolor)// ,Bitmap sourceBitmap) { if (sourceBitmap != null) { float R = Color.red(rgbcolor); float G = Color.green(rgbcolor); float B = Color.blue(rgbcolor); Log.v("R:G:B", R + ":" + G + ":" + B); // float[] colorTransform = { R / 255f, 0, 0, 0, 0, // R color 0, G / 255f, 0, 0, 0 // G color , 0, 0, B / 255f, 0, 0 // B color , 0, 0, 0, 1f, 0f };// ww w .j a v a2 s .c o m ColorMatrix colorMatrix = new ColorMatrix(); colorMatrix.setSaturation(0f); // Remove Colour colorMatrix.set(colorTransform); ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix); Paint paint = new Paint(); paint.setColorFilter(colorFilter); Bitmap mutableBitmap = sourceBitmap.copy(Bitmap.Config.ARGB_8888, true); view.setImageBitmap(mutableBitmap); Canvas canvas = new Canvas(mutableBitmap); canvas.drawBitmap(mutableBitmap, 0, 0, paint); } }
From source file:Main.java
public static Bitmap getRounded(Bitmap bm, int cornerRadiusPx) { int w = bm.getWidth(); int h = bm.getHeight(); Bitmap bmOut = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmOut); Paint paint = new Paint(); paint.setAntiAlias(true);// ww w . j ava 2s . c om paint.setColor(0xff424242); Rect rect = new Rect(0, 0, w, h); RectF rectF = new RectF(rect); canvas.drawARGB(0, 0, 0, 0); canvas.drawRoundRect(rectF, cornerRadiusPx, cornerRadiusPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bm, rect, rect, paint); return bmOut; }
From source file:Main.java
private static Drawable getMoreSuggestionsHint(final Resources res, final float textSize, final int color) { final Paint paint = new Paint(); paint.setAntiAlias(true);// ww w . jav a 2 s .co m paint.setTextAlign(Align.CENTER); paint.setTextSize(textSize); paint.setColor(color); final Rect bounds = new Rect(); paint.getTextBounds(MORE_SUGGESTIONS_HINT, 0, MORE_SUGGESTIONS_HINT.length(), bounds); final int width = Math.round(bounds.width() + 0.5f); final int height = Math.round(bounds.height() + 0.5f); final Bitmap buffer = Bitmap.createBitmap(width, (height * 3 / 2), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(buffer); canvas.drawText(MORE_SUGGESTIONS_HINT, width / 2, height, paint); return new BitmapDrawable(res, buffer); }
From source file:Main.java
public static Bitmap toGrayscale(Bitmap bmpOriginal) { int width, height; height = bmpOriginal.getHeight();/* w w w . jav a2s. c o m*/ width = bmpOriginal.getWidth(); try { Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bmpGrayscale); Paint paint = new Paint(); ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0); ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm); paint.setColorFilter(f); c.drawBitmap(bmpOriginal, 0, 0, paint); return bmpGrayscale; } catch (OutOfMemoryError e) { return bmpOriginal; } }
From source file:Main.java
private static Drawable getMoreSuggestionsHint(final Resources res, final float textSize, final int color) { final Paint paint = new Paint(); paint.setAntiAlias(true);/*w ww. java 2 s .com*/ paint.setTextAlign(Align.CENTER); paint.setTextSize(textSize); paint.setColor(color); final Rect bounds = new Rect(); paint.getTextBounds(MORE_SUGGESTIONS_HINT, 0, MORE_SUGGESTIONS_HINT.length(), bounds); final int width = Math.round(bounds.width() + 0.5f); final int height = Math.round(bounds.height() + 0.5f); final Bitmap buffer = Bitmap.createBitmap(width, (height * 3 / 2), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(buffer); canvas.drawText(MORE_SUGGESTIONS_HINT, width / 2, height, paint); BitmapDrawable bitmapDrawable = new BitmapDrawable(res, buffer); bitmapDrawable.setTargetDensity(canvas); return bitmapDrawable; }
From source file:Main.java
public static Bitmap createReflectImages(Bitmap bImap) { if (null == bImap) { return null; }/* ww w . j a v a2 s. co m*/ final int reflectionGap = 4; int width = bImap.getWidth(); int height = bImap.getHeight(); Bitmap bitmapWithReflection = null; try { Matrix matrix = new Matrix(); matrix.preScale(1, -1); Bitmap reflectionImage = Bitmap.createBitmap(bImap, 0, height / 2, width, height / 2, matrix, false); bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Config.ARGB_8888); Canvas canvas = new Canvas(bitmapWithReflection); canvas.drawBitmap(bImap, 0, 0, null); Paint deafaultPaint = new Paint(); canvas.drawRect(0, height, width, height + reflectionGap, deafaultPaint); canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null); Paint paint = new Paint(); LinearGradient shader = new LinearGradient(0, bImap.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap, 0x80ffffff, 0x00ffffff, TileMode.CLAMP); paint.setShader(shader); paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint); } catch (OutOfMemoryError e) { } return bitmapWithReflection; }
From source file:Main.java
public static Bitmap drawViewToBitmap(View view, int width, int height, float translateX, float translateY, int downSampling, String color) { float scale = 1f / downSampling; int bmpWidth = (int) (width * scale - translateX / downSampling); int bmpHeight = (int) (height * scale - translateY / downSampling); Bitmap dest = Bitmap.createBitmap(bmpWidth, bmpHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(dest); canvas.translate(-translateX / downSampling, -translateY / downSampling); if (downSampling > 1) { canvas.scale(scale, scale);//from www .jav a 2 s . com } Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG); PorterDuffColorFilter filter = new PorterDuffColorFilter(Color.parseColor(color), PorterDuff.Mode.SRC_ATOP); paint.setColorFilter(filter); view.buildDrawingCache(); Bitmap cache = view.getDrawingCache(); canvas.drawBitmap(cache, 0, 0, paint); cache.recycle(); view.destroyDrawingCache(); return dest; }
From source file:Main.java
private static Bitmap toGrayscale(Bitmap bmpOriginal) { int width, height; height = bmpOriginal.getHeight();/*from w w w. j ava 2 s.co m*/ width = bmpOriginal.getWidth(); Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bmpGrayscale); Paint paint = new Paint(); ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0); ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm); paint.setColorFilter(f); c.drawBitmap(bmpOriginal, 0, 0, paint); return bmpGrayscale; }