List of usage examples for android.graphics Canvas drawBitmap
public void drawBitmap(@NonNull Bitmap bitmap, @Nullable Rect src, @NonNull Rect dst, @Nullable Paint paint)
From source file:com.apache.fastandroid.novel.view.readview.PageFactory.java
/** * ?// w ww. ja v a 2 s. c o m * * @param canvas */ public synchronized void onDraw(Canvas canvas) { if (mLines.size() == 0) { curEndPos = curBeginPos; mLines = pageDown(); } if (mLines.size() > 0) { int y = marginHeight + (mLineSpace << 1); // if (mBookPageBg != null) { canvas.drawBitmap(mBookPageBg, null, rectF, null); } else { canvas.drawColor(Color.WHITE); } // canvas.drawText(chaptersList.get(currentChapter - 1).title, marginWidth, y, mTitlePaint); y += mLineSpace + mNumFontSize; // ? for (String line : mLines) { y += mLineSpace; if (line.endsWith("@")) { canvas.drawText(line.substring(0, line.length() - 1), marginWidth, y, mPaint); y += mLineSpace; } else { canvas.drawText(line, marginWidth, y, mPaint); } y += mFontSize; } // ?? if (batteryBitmap != null) { canvas.drawBitmap(batteryBitmap, marginWidth + 2, mHeight - marginHeight - DimensUtil.dp2px(mContext, 12), mTitlePaint); } float percent = (float) currentChapter * 100 / chapterSize; canvas.drawText(decimalFormat.format(percent) + "%", (mWidth - percentLen) / 2, mHeight - marginHeight, mTitlePaint); String mTime = dateFormat.format(new Date()); canvas.drawText(mTime, mWidth - marginWidth - timeLen, mHeight - marginHeight, mTitlePaint); // ? SettingManager.getInstance().saveReadProgress(bookId, currentChapter, curBeginPos, curEndPos); } }
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 a v a 2 s . 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.netcompss.ffmpeg4android_client.BaseVideo.java
private Bitmap ProcessingBitmapTwo(Bitmap bm1, Bitmap bm2) { Bitmap newBitmap = null;/* www.ja v a 2 s. co m*/ int w; if (bm1.getWidth() >= bm2.getWidth()) { w = bm1.getWidth(); } else { w = bm2.getWidth(); } int h; if (bm1.getHeight() >= bm2.getHeight()) { h = bm1.getHeight(); } else { h = bm2.getHeight(); } Config config = bm1.getConfig(); if (config == null) { config = Bitmap.Config.ARGB_4444; } newBitmap = Bitmap.createBitmap(w, h, config); Canvas newCanvas = new Canvas(newBitmap); newCanvas.drawColor(Color.WHITE); if (bm2.getWidth() == bm2.getHeight()) { newCanvas.drawBitmap(bm2, (w - bm2.getWidth()) / 2, (h - bm2.getHeight()) / 2, null); } else { newCanvas.drawBitmap(bm2, (w / 2) - (bm2.getWidth() / 2), (h / 2) - (bm2.getHeight() / 2), null); } return newBitmap; }
From source file:com.mappn.gfan.ui.HomeTabActivity.java
private Bitmap drawBitmap(DisplayMetrics dm, Bitmap background, Bitmap corner) { Canvas canvas = new Canvas(); final int height = background.getScaledHeight(dm); final int width = background.getScaledWidth(dm); Bitmap smallBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); canvas.setBitmap(smallBitmap);/*from w w w . j av a 2 s. c om*/ Paint textPainter = new Paint(Paint.ANTI_ALIAS_FLAG); canvas.drawBitmap(background, 0, 0, textPainter); textPainter.setXfermode(new PorterDuffXfermode(Mode.SRC_OVER)); canvas.drawBitmap(corner, width - corner.getScaledWidth(dm), 0, textPainter); canvas.save(); return smallBitmap; }
From source file:com.dwdesign.tweetings.fragment.UserProfileFragment.java
public static Bitmap createAlphaGradientBitmap(Bitmap orig) { final int width = orig.getWidth(), height = orig.getHeight(); final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); final Paint paint = new Paint(); final LinearGradient shader = new LinearGradient(width / 2, 0, width / 2, height, 0xffffffff, 0x00ffffff, Shader.TileMode.CLAMP);// w w w.j a va2 s . co m paint.setShader(shader); paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); canvas.drawBitmap(orig, 0, 0, null); canvas.drawRect(0, 0, width, height, paint); return bitmap; }
From source file:edu.mum.ml.group7.guessasketch.android.EasyPaint.java
public Bitmap toGrayscale(Bitmap bmpOriginal) { int width, height; height = bmpOriginal.getHeight();//from w w w. ja v a 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; }
From source file:com.aimfire.gallery.cardboard.PhotoActivity.java
public Bitmap toGrayscale(Bitmap bmpOriginal) { int width, height; height = bmpOriginal.getHeight();//w w w . ja v a2 s .c o m width = bmpOriginal.getWidth(); Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); 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); bmpOriginal.recycle(); return bmpGrayscale; }
From source file:com.duy.pascal.ui.view.console.ConsoleView.java
@Override protected void onDraw(Canvas canvas) { int w = getWidth(); int h = getHeight(); if (graphicMode) { // draw bitmap graph if (!mGraphScreen.getGraphBitmap().isRecycled()) { canvas.drawBitmap(mGraphScreen.getGraphBitmap(), 0, 0, mGraphScreen.getBackgroundPaint()); }/*ww w .j a v a 2 s. com*/ } else { mConsoleScreen.drawBackground(canvas, mConsoleScreen.getLeftVisible(), mConsoleScreen.getTopVisible(), w, h); drawText(canvas, mConsoleScreen.getLeftVisible(), mConsoleScreen.getTopVisible()); } }
From source file:com.affectiva.affdexme.MainActivity.java
private void processScreenshot(Bitmap drawingViewBitmap, boolean alsoSaveRaw) { if (mostRecentFrame == null) { Toast.makeText(getApplicationContext(), "No frame detected, aborting screenshot", Toast.LENGTH_SHORT) .show();//from w w w.j a v a2s . c om return; } if (!storagePermissionsAvailable) { checkForStoragePermissions(); return; } Bitmap faceBitmap = ImageHelper.getBitmapFromFrame(mostRecentFrame); if (faceBitmap == null) { Log.e(LOG_TAG, "Unable to generate bitmap for frame, aborting screenshot"); return; } metricViewLayout.setDrawingCacheEnabled(true); Bitmap metricsBitmap = Bitmap.createBitmap(metricViewLayout.getDrawingCache()); metricViewLayout.setDrawingCacheEnabled(false); Bitmap finalScreenshot = Bitmap.createBitmap(faceBitmap.getWidth(), faceBitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(finalScreenshot); Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(faceBitmap, 0, 0, paint); float scaleFactor = ((float) faceBitmap.getWidth()) / ((float) drawingViewBitmap.getWidth()); int scaledHeight = Math.round(drawingViewBitmap.getHeight() * scaleFactor); canvas.drawBitmap(drawingViewBitmap, null, new Rect(0, 0, faceBitmap.getWidth(), scaledHeight), paint); scaleFactor = ((float) faceBitmap.getWidth()) / ((float) metricsBitmap.getWidth()); scaledHeight = Math.round(metricsBitmap.getHeight() * scaleFactor); canvas.drawBitmap(metricsBitmap, null, new Rect(0, 0, faceBitmap.getWidth(), scaledHeight), paint); metricsBitmap.recycle(); drawingViewBitmap.recycle(); Date now = new Date(); String timestamp = DateFormat.format("yyyy-MM-dd_hh-mm-ss", now).toString(); File pictureFolder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "AffdexMe"); if (!pictureFolder.exists()) { if (!pictureFolder.mkdir()) { Log.e(LOG_TAG, "Unable to create directory: " + pictureFolder.getAbsolutePath()); return; } } String screenshotFileName = timestamp + ".png"; File screenshotFile = new File(pictureFolder, screenshotFileName); try { ImageHelper.saveBitmapToFileAsPng(finalScreenshot, screenshotFile); } catch (IOException e) { String msg = "Unable to save screenshot"; Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show(); Log.e(LOG_TAG, msg, e); return; } ImageHelper.addPngToGallery(getApplicationContext(), screenshotFile); if (alsoSaveRaw) { String rawScreenshotFileName = timestamp + "_raw.png"; File rawScreenshotFile = new File(pictureFolder, rawScreenshotFileName); try { ImageHelper.saveBitmapToFileAsPng(faceBitmap, rawScreenshotFile); } catch (IOException e) { String msg = "Unable to save screenshot"; Log.e(LOG_TAG, msg, e); } ImageHelper.addPngToGallery(getApplicationContext(), rawScreenshotFile); } faceBitmap.recycle(); finalScreenshot.recycle(); String fileSavedMessage = "Screenshot saved to: " + screenshotFile.getPath(); Toast.makeText(getApplicationContext(), fileSavedMessage, Toast.LENGTH_SHORT).show(); Log.d(LOG_TAG, fileSavedMessage); }
From source file:com.android.launcher3.Utilities.java
private static Bitmap overlay(Bitmap bmp1, Bitmap bmp2) { Bitmap bmOverlay = Bitmap.createBitmap(bmp2.getWidth(), bmp2.getHeight(), bmp1.getConfig()); float left = (bmp2.getWidth() - (bmp1.getWidth() * ((float) bmp2.getHeight() / (float) bmp1.getHeight()))) / (float) 2.0; float bmp1newW = bmp1.getWidth() * ((float) bmp2.getHeight() / (float) bmp1.getHeight()); Bitmap bmp1new = Utils.getResizedBitmap(bmp1, bmp2.getHeight(), (int) bmp1newW); Canvas canvas = new Canvas(bmOverlay); canvas.drawBitmap(bmp1new, left, 0, null); canvas.drawBitmap(bmp2, new Matrix(), null); return bmOverlay; }