List of usage examples for android.graphics Paint Paint
public Paint()
From source file:com.madgag.android.lazydrawables.samples.DemoListActivity.java
private ImageResourceDownloader<String, Bitmap> slowImageMaker() { return new ImageResourceDownloader<String, Bitmap>() { public Bitmap get(String key) { Log.d(TAG, "Asked to download " + key); try { Thread.sleep(4000L); } catch (InterruptedException e) { }/*from w w w. j a v a 2s. c o m*/ Bitmap bitmap = Bitmap.createBitmap(80, 80, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bitmap); Paint paint = new Paint(); paint.setColor(0xff0000ff); c.drawCircle(0, 0, 50, paint); paint.setColor(0xffff007f); paint.setStyle(Paint.Style.FILL); paint.setAntiAlias(true); paint.setTextSize(30); c.drawText(key, 0, 3, 0, 60, paint); Log.d(TAG, "Done drawing... " + key); return bitmap; } }; }
From source file:com.acceleratedio.pac_n_zoom.DrawSVG.java
public ArrayList<ImageView> DrawSVG(Context context, ImageView orgnlImageView, RelativeLayout rel_anm_lo) { paint.setColor(Color.WHITE);//from ww w . j a v a 2 s. c o m paint.setStyle(Paint.Style.FILL); LoadSVG.SVGData data = AnimActivity.svg_data; ArrayList<ImageView> imgViews = new ArrayList<ImageView>(); imgViews.add(orgnlImageView); if (data.symbl != null) { ArrayList<String> sprt_ordr = data.svg.ordr; int sym_mbr = 0; Bitmap bitmap; Canvas canvas; // - Loop through the sprites int sprt_nmbr = sprt_ordr.size(); data.svg.initScl = new float[sprt_nmbr]; float[] initScl = data.svg.initScl; for (int sprt_mbr = 1; sprt_mbr < sprt_nmbr; sprt_mbr += 1) { String sprt_id = sprt_ordr.get(sprt_mbr); // e.g., id="g2_0" if (Integer.parseInt(sprt_id.substring(sprt_id.indexOf('_') + 1)) > 0) { // The symbol is already drawn; replicate the view String init_sprt = sprt_id.substring(0, sprt_id.indexOf('_') + 1) + '0'; String svg_ordr = data.svg.svg_ordr; String cnt_str = svg_ordr.substring(0, svg_ordr.indexOf(init_sprt)); ImageView init_vw = imgViews.get(StringUtils.countMatches(cnt_str, ",")); Bitmap initBmp = ((BitmapDrawable) init_vw.getDrawable()).getBitmap(); bitmap = Bitmap.createBitmap(initBmp.getWidth(), initBmp.getHeight(), initBmp.getConfig()); canvas = new Canvas(bitmap); canvas.save(Canvas.MATRIX_SAVE_FLAG); xfrmInit crt_sprt = getInitSpriteAttrib(sprt_id); canvas.scale(crt_sprt.scl, crt_sprt.scl); initScl[sprt_mbr] = crt_sprt.scl; canvas.translate(0, 0); } else { // The symbol needs to be drawn; a new view is used bitmap = getCreatBmp(rel_anm_lo); canvas = new Canvas(bitmap); canvas.save(Canvas.MATRIX_SAVE_FLAG); // - Set the init values xfrmInit crt_sprt = getInitSpriteAttrib(sprt_id); canvas.scale(crt_sprt.scl, crt_sprt.scl); initScl[sprt_mbr] = crt_sprt.scl; canvas.translate(0, 0); // - Draw the bitmap LoadSVG.symbol crt_sym = data.symbl.get(sym_mbr); ArrayList<LoadSVG.path> pths = crt_sym.pths; int pth_nmbr = pths.size(); // Loop through the paths for (int pth_mbr = 0; pth_mbr < pth_nmbr; pth_mbr += 1) { LoadSVG.path crt_pth = pths.get(pth_mbr); final Path path = new Path(); final Paint paint = new Paint(); /* Debug if (pth_mbr + 1 == pth_nmbr) { String log_str = "Paths: pth_mbr = " + String.valueOf(pth_mbr) + "; color = " + crt_pth.clr; Log.d("DrawSVG", log_str); } */ paint.setColor(Color.parseColor(crt_pth.clr)); paint.setAntiAlias(true); paint.setStyle(Paint.Style.FILL_AND_STROKE); ld_pth_pnts(crt_pth.pth, path); path.close(); path.setFillType(Path.FillType.EVEN_ODD); canvas.drawPath(path, paint); } canvas.restore(); sym_mbr += 1; } ImageView iv = new ImageView(context); iv.setImageBitmap(bitmap); RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); iv.draw(canvas); iv.setLayoutParams(rlp); iv.setBackgroundColor(Color.TRANSPARENT); imgViews.add(iv); } // sprites } // if symbol return imgViews; }
From source file:com.hxsn.witwork.ui.ViewfinderView.java
public ViewfinderView(Context context, AttributeSet attrs) { super(context, attrs); con = context;//from ww w . j a va2s. c o m name = new ArrayList<String>(); density = context.getResources().getDisplayMetrics().density; // ???dp ScreenRate = (int) (20 * density); paint = new Paint(); Resources resources = getResources(); maskColor = resources.getColor(R.color.viewfinder_mask); resultColor = resources.getColor(R.color.result_view); resultPointColor = resources.getColor(R.color.possible_result_points); possibleResultPoints = new HashSet<ResultPoint>(5); }
From source file:com.ibuildapp.romanblack.FanWallPlugin.data.Statics.java
/** * Sets the downloaded avatar.//from w ww . j a v a 2 s . com * * @param filePath file path to avatar image */ public static Bitmap publishAvatar(String filePath) { Bitmap bitmap = null; if (!TextUtils.isEmpty(filePath)) { try { BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inSampleSize = 1; bitmap = BitmapFactory.decodeFile(filePath, opts); int size = 0; if (bitmap.getHeight() > bitmap.getWidth()) { size = bitmap.getWidth(); } else { size = bitmap.getHeight(); } Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, size, size); final RectF rectF = new RectF(rect); final float roundPx = 12; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); bitmap.recycle(); return output; } catch (Exception e) { } } return null; }
From source file:ca.psiphon.ploggy.Robohash.java
public static Bitmap getRobohash(Context context, boolean cacheCandidate, byte[] data) throws Utils.ApplicationError { try {// w w w. j ava2 s . c om MessageDigest sha1 = MessageDigest.getInstance("SHA-1"); byte[] digest = sha1.digest(data); String key = Utils.formatFingerprint(digest); Bitmap cachedBitmap = mCache.get(key); if (cachedBitmap != null) { return cachedBitmap; } ByteBuffer byteBuffer = ByteBuffer.wrap(digest); byteBuffer.order(ByteOrder.BIG_ENDIAN); // TODO: SecureRandom SHA1PRNG (but not LinuxSecureRandom) Random random = new Random(byteBuffer.getLong()); AssetManager assetManager = context.getAssets(); if (mConfig == null) { mConfig = new JSONObject(loadAssetToString(assetManager, CONFIG_FILENAME)); } int width = mConfig.getInt("width"); int height = mConfig.getInt("height"); JSONArray colors = mConfig.getJSONArray("colors"); JSONArray parts = colors.getJSONArray(random.nextInt(colors.length())); Bitmap robotBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas robotCanvas = new Canvas(robotBitmap); for (int i = 0; i < parts.length(); i++) { JSONArray partChoices = parts.getJSONArray(i); String selection = partChoices.getString(random.nextInt(partChoices.length())); Bitmap partBitmap = loadAssetToBitmap(assetManager, selection); Rect rect = new Rect(0, 0, width, height); Paint paint = new Paint(); paint.setAlpha(255); robotCanvas.drawBitmap(partBitmap, rect, rect, paint); partBitmap.recycle(); } if (cacheCandidate) { mCache.set(key, robotBitmap); } return robotBitmap; } catch (IOException e) { throw new Utils.ApplicationError(LOG_TAG, e); } catch (JSONException e) { throw new Utils.ApplicationError(LOG_TAG, e); } catch (NoSuchAlgorithmException e) { throw new Utils.ApplicationError(LOG_TAG, e); } }
From source file:com.richtodd.android.quiltdesign.block.Theme.java
private void draw(Canvas canvas, int width, int height) { canvas.drawColor(Color.WHITE); Paint swatchPaint = new Paint(); swatchPaint.setStyle(Style.FILL); int idx = 0;//from w ww . jav a2s .c o m int left = 0; int right = 0; for (Swatch swatch : m_swatches) { idx += 1; left = right; right = width * idx / m_swatches.size(); swatchPaint.setColor(swatch.getColor()); canvas.drawRect(left, 0, right, height, swatchPaint); } }
From source file:com.wareninja.opensource.gravatar4android.common.Utils.java
public static Bitmap getBitmapWithReflection(Bitmap originalImage) { //The gap we want between the reflection and the original image final int reflectionGap = 4; int width = originalImage.getWidth(); int height = originalImage.getHeight(); //This will not scale but will flip on the Y axis Matrix matrix = new Matrix(); matrix.preScale(1, -1);/* w w w. ja va2s . c o m*/ //Create a Bitmap with the flip matrix applied to it. //We only want the bottom half of the image Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height / 2, width, height / 2, matrix, false); //Create a new bitmap with same width but taller to fit reflection Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Config.ARGB_8888); //Create a new Canvas with the bitmap that's big enough for //the image plus gap plus reflection Canvas canvas = new Canvas(bitmapWithReflection); //Draw in the original image canvas.drawBitmap(originalImage, 0, 0, null); //Draw in the gap Paint deafaultPaint = new Paint(); canvas.drawRect(0, height, width, height + reflectionGap, deafaultPaint); //Draw in the reflection canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null); //Create a shader that is a linear gradient that covers the reflection Paint paint = new Paint(); LinearGradient shader = new LinearGradient(0, originalImage.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP); //Set the paint to use this shader (linear gradient) paint.setShader(shader); //Set the Transfer mode to be porter duff and destination in paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); //Draw a rectangle using the paint with our linear gradient canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint); return bitmapWithReflection; }
From source file:ee.ioc.phon.android.speak.Utils.java
static Bitmap bytesToBitmap(byte[] byteBuffer, int w, int h, int startPosition, int endPosition) { final ShortBuffer waveBuffer = ByteBuffer.wrap(byteBuffer).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer(); final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); final Canvas c = new Canvas(b); final Paint paint = new Paint(); paint.setColor(0xFFFFFFFF); // 0xAARRGGBB paint.setAntiAlias(true);/*from w w w .j ava 2 s. co m*/ paint.setStyle(Paint.Style.STROKE); paint.setAlpha(80); final PathEffect effect = new CornerPathEffect(3); paint.setPathEffect(effect); final int numSamples = waveBuffer.remaining(); int endIndex; if (endPosition == 0) { endIndex = numSamples; } else { endIndex = Math.min(endPosition, numSamples); } int startIndex = startPosition - 2000; // include 250ms before speech if (startIndex < 0) { startIndex = 0; } final int numSamplePerWave = 200; // 8KHz 25ms = 200 samples final float scale = 10.0f / 65536.0f; final int count = (endIndex - startIndex) / numSamplePerWave; final float deltaX = 1.0f * w / count; int yMax = h / 2; Path path = new Path(); c.translate(0, yMax); float x = 0; path.moveTo(x, 0); for (int i = 0; i < count; i++) { final int avabs = getAverageAbs(waveBuffer, startIndex, i, numSamplePerWave); int sign = ((i & 01) == 0) ? -1 : 1; final float y = Math.min(yMax, avabs * h * scale) * sign; path.lineTo(x, y); x += deltaX; path.lineTo(x, y); } if (deltaX > 4) { paint.setStrokeWidth(2); } else { paint.setStrokeWidth(Math.max(0, (int) (deltaX - .05))); } c.drawPath(path, paint); return b; }
From source file:com.entertailion.android.slideshow.utils.Utils.java
/** * Create a bitmap from a image URL.//w ww. j av a 2s . c om * * @param src * @return */ public static final Bitmap getBitmapFromURL(String src) { try { URL url = new URL(src); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.connect(); InputStream input = connection.getInputStream(); Bitmap myBitmap = BitmapFactory.decodeStream(input); int size = Math.max(myBitmap.getWidth(), myBitmap.getHeight()); Bitmap b = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); Paint paint = new Paint(); paint.setAntiAlias(true); c.drawBitmap(myBitmap, (size - myBitmap.getWidth()) / 2, (size - myBitmap.getHeight()) / 2, paint); return b; } catch (Exception e) { Log.e(LOG_TAG, "Faild to get the image from URL:" + src, e); return null; } }