List of usage examples for android.graphics Paint setARGB
public void setARGB(int a, int r, int g, int b)
From source file:Main.java
/** * Returns a rounded bitmap using specified bitmap image. * /* www . ja v a 2 s.co m*/ * @param scaleBitmapImage bitmap to make round image. * @return rounded bitmap */ public static Bitmap getRoundedShape(Bitmap scaleBitmapImage) { if (scaleBitmapImage == null) return null; int targetWidth = (int) DP; int targetHeight = (int) DP; Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(targetBitmap); Path path = new Path(); path.addCircle(((float) targetWidth - 1) / 2, ((float) targetHeight - 1) / 2, (Math.min(((float) targetWidth), ((float) targetHeight)) / 2), Path.Direction.CCW); Paint p = new Paint(); p.setAntiAlias(true); canvas.clipPath(path); canvas.drawBitmap(scaleBitmapImage, new Rect(0, 0, scaleBitmapImage.getWidth(), scaleBitmapImage.getHeight()), new Rect(0, 0, targetWidth, targetHeight), p); p.setARGB(255, 16, 18, 16); scaleBitmapImage.recycle(); return targetBitmap; }
From source file:com.ecuamobi.deckwallet.util.Renderer.java
public static void printQR(final Activity context, final String addressUri) { new AsyncTask<Void, Void, Bitmap>() { @Override//from ww w . jav a 2 s . c o m protected Bitmap doInBackground(Void... params) { TextPaint textPaint = new TextPaint(); textPaint.setAntiAlias(true); textPaint.setColor(0xFF000000); final int bitmapMargin = 100;//big margin is to prevent possible clipping final int textHeight = 28; textPaint.setTextSize(textHeight); textPaint.setTextAlign(Paint.Align.CENTER); final int qrCodePadding = (int) (textPaint.descent() * 2); int textWidth = getTextWidth(addressUri, textPaint); QRCode addressQrCode = QRCode.getMinimumQRCode(addressUri, ErrorCorrectLevel.M); Bitmap addressQrCodeBitmap = addressQrCode.createImage(textWidth); Bitmap bmp = Bitmap.createBitmap(textWidth + bitmapMargin * 2, addressQrCodeBitmap.getHeight() + qrCodePadding * 2 + bitmapMargin * 2, Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bmp); Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setARGB(0xFF, 0xFF, 0xFF, 0xFF); paint.setAntiAlias(false); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), paint); int centerXForAddress = bitmapMargin + textWidth / 2; int y = bitmapMargin + qrCodePadding; Paint qrCodePaint = new Paint(); qrCodePaint.setAntiAlias(false); qrCodePaint.setDither(false); canvas.drawBitmap(addressQrCodeBitmap, centerXForAddress - addressQrCodeBitmap.getWidth() / 2, y, qrCodePaint); y += qrCodePadding - textPaint.ascent(); canvas.drawText(addressUri, centerXForAddress, y + addressQrCodeBitmap.getHeight(), textPaint); return bmp; } @Override protected void onPostExecute(final Bitmap bitmap) { if (bitmap != null) { //DEBUG // android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context); // android.widget.ImageView view = new android.widget.ImageView(context); // view.setImageBitmap(bitmap); // builder.setView(view); // builder.setPositiveButton(android.R.string.ok, null); // builder.show(); PrintHelper printHelper = new PrintHelper(context); printHelper.setScaleMode(PrintHelper.SCALE_MODE_FIT); printHelper.printBitmap(addressUri, bitmap); } } }.execute(); }
From source file:com.ecuamobi.deckwallet.util.Renderer.java
static void printWallet(final Activity context, final String label, final String addressUri, final String privateKey) { new AsyncTask<Void, Void, Bitmap>() { @Override//from w w w . j a va 2 s . c om protected Bitmap doInBackground(Void... params) { TextPaint textPaint = new TextPaint(); textPaint.setAntiAlias(true); textPaint.setColor(0xFF000000); final int bitmapMargin = 100;//big margin is to prevent possible clipping final int textHeight = 28; final int spaceBetweenQrCodes = 60; textPaint.setTextSize(textHeight); textPaint.setTextAlign(Paint.Align.CENTER); final int qrCodePadding = (int) (textPaint.descent() * 2); Rect bounds = new Rect(); textPaint.getTextBounds(privateKey, 0, privateKey.length(), bounds); int textWidth = getTextWidth(privateKey, textPaint); ArrayList<String> labelLinesRelaxed = wrap(label, textWidth, false, textPaint); for (String titleLine : labelLinesRelaxed) { textWidth = Math.max(textWidth, getTextWidth(titleLine, textPaint)); } textWidth = Math.max(textWidth, getTextWidth(addressUri, textPaint)); QRCode privateKeyQrCode = QRCode.getMinimumQRCode(privateKey, ErrorCorrectLevel.M); Bitmap privateKeyQrCodeBitmap = privateKeyQrCode.createImage(textWidth); QRCode addressQrCode = QRCode.getMinimumQRCode(addressUri, ErrorCorrectLevel.M); Bitmap addressQrCodeBitmap = addressQrCode.createImage(textWidth); ArrayList<String> labelLines = wrap(label, textWidth, true, textPaint); Bitmap bmp = Bitmap.createBitmap( textWidth * 2 + bitmapMargin * 2 + spaceBetweenQrCodes, privateKeyQrCodeBitmap.getHeight() + textHeight * (labelLines.size() + 1) + qrCodePadding * 2 + bitmapMargin * 2, Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bmp); Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setARGB(0xFF, 0xFF, 0xFF, 0xFF); paint.setAntiAlias(false); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), paint); int centerXForAddress = bitmapMargin + textWidth / 2; int centerXForPrivateKey = bitmapMargin + textWidth + spaceBetweenQrCodes + textWidth / 2; int y = (int) (bitmapMargin - textPaint.ascent()); for (int i = 0; i < labelLines.size(); i++) { canvas.drawText(labelLines.get(i), centerXForPrivateKey, y + i * textHeight, textPaint); } y = bitmapMargin + labelLines.size() * textHeight + qrCodePadding; Paint qrCodePaint = new Paint(); qrCodePaint.setAntiAlias(false); qrCodePaint.setDither(false); canvas.drawBitmap(addressQrCodeBitmap, centerXForAddress - addressQrCodeBitmap.getWidth() / 2, y, qrCodePaint); canvas.drawBitmap(privateKeyQrCodeBitmap, centerXForPrivateKey - privateKeyQrCodeBitmap.getWidth() / 2, y, qrCodePaint); y += qrCodePadding - textPaint.ascent(); canvas.drawText(addressUri, centerXForAddress, y + addressQrCodeBitmap.getHeight(), textPaint); canvas.drawText(privateKey, centerXForPrivateKey, y + privateKeyQrCodeBitmap.getHeight(), textPaint); return bmp; } @Override protected void onPostExecute(final Bitmap bitmap) { if (bitmap != null) { //DEBUG // android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context); // android.widget.ImageView view = new android.widget.ImageView(context); // view.setImageBitmap(bitmap); // builder.setView(view); // builder.setPositiveButton(android.R.string.ok, null); // builder.show(); PrintHelper printHelper = new PrintHelper(context); printHelper.setScaleMode(PrintHelper.SCALE_MODE_FIT); printHelper.printBitmap(label, bitmap); } } }.execute(); }
From source file:com.ridgelineapps.wallpaper.Utils.java
public static Paint createPaint(int alpha, int r, int g, int b) { Paint paint = new Paint(); paint.setAntiAlias(true);//w w w . ja va 2 s. c o m paint.setARGB(alpha, r, g, b); return paint; }
From source file:com.ridgelineapps.wallpaper.Utils.java
public static Paint createPaint(int r, int g, int b) { Paint paint = new Paint(); paint.setAntiAlias(true);/* ww w.j av a 2 s. co m*/ paint.setARGB(255, r, g, b); return paint; }
From source file:eu.iescities.pilot.rovereto.roveretoexplorer.map.MapManager.java
private static Bitmap writeOnMarker(Context mContext, int drawableId, String text) { float scale = mContext.getResources().getDisplayMetrics().density; Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), drawableId) .copy(Bitmap.Config.ARGB_8888, true); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextAlign(Align.CENTER);//w w w .j a v a 2 s . co m paint.setTextSize(scale * 14); paint.setAntiAlias(true); paint.setARGB(255, 255, 255, 255); Canvas canvas = new Canvas(bitmap); Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), bounds); float x = bitmap.getWidth() / 2; float y = bitmap.getHeight() / 2; canvas.drawText(text, x, y, paint); return bitmap; }
From source file:eu.iescities.pilot.rovereto.roveretoexplorer.map.MapManager.java
private static Bitmap writeOnStoryMarker(Context mContext, int drawableId, String text) { float scale = mContext.getResources().getDisplayMetrics().density; Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), drawableId) .copy(Bitmap.Config.ARGB_8888, true); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextAlign(Align.CENTER);//w ww. java2 s . c om paint.setTextSize(scale * 14); paint.setAntiAlias(true); paint.setARGB(255, 255, 255, 255); Canvas canvas = new Canvas(bitmap); Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), bounds); float x = bitmap.getWidth() / 2; float y = bitmap.getHeight() / 2 - ((paint.descent() + paint.ascent()) / 2); canvas.drawText(text, x, y, paint); return bitmap; }
From source file:eu.trentorise.smartcampus.trentinofamiglia.map.MapManager.java
private static Bitmap writeOnMarker(Context mContext, int drawableId, String text) { float scale = mContext.getResources().getDisplayMetrics().density; Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), drawableId) .copy(Bitmap.Config.ARGB_8888, true); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextAlign(Align.CENTER);//from w w w . j a v a2 s . c o m paint.setTextSize(scale * 14); paint.setAntiAlias(true); paint.setARGB(255, 255, 255, 255); Canvas canvas = new Canvas(bitmap); Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), bounds); float x = bitmap.getWidth() / 2; float y = bitmap.getHeight() / 2 - 5; canvas.drawText(text, x, y, paint); return bitmap; }
From source file:com.kmagic.solitaire.DrawMaster.java
/** * Get red paint for general use// www.j a v a 2s. c o m * @return black paint object */ public static Paint getBlackPaint() { final Paint paint = getPaint(); paint.setARGB(255, 0, 0, 0); return (paint); }
From source file:com.kmagic.solitaire.DrawMaster.java
/** * Get red paint for general use// w w w .j a v a2s .c om * @return red paint object */ public static Paint getRedPaint() { final Paint paint = getPaint(); paint.setARGB(255, 255, 0, 0); return (paint); }