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.VVTeam.ManHood.Fragment.HistogramFragment.java
private Bitmap makeSnapshot() { contentRelative.setDrawingCacheEnabled(true); contentRelative.buildDrawingCache(); Bitmap bm = contentRelative.getDrawingCache(); int width = bm.getWidth(); int height = bm.getHeight(); Bitmap background = BitmapFactory.decodeResource(getResources(), R.drawable.histogram_bg); Bitmap logo = BitmapFactory.decodeResource(getResources(), R.drawable.manhoodlogo); Bitmap cs = null;/*ww w .ja v a 2 s . c om*/ cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas comboImage = new Canvas(cs); Rect src = new Rect(0, 0, background.getWidth() - 1, background.getHeight() - 1); Rect dest = new Rect(0, 0, width - 1, height - 1); comboImage.drawBitmap(background, src, dest, null); comboImage.drawBitmap(bm, 0f, 0f, null); comboImage.drawBitmap(logo, 7.0f, height - logo.getHeight() - 4.0f, null); return cs; }
From source file:com.augustopicciani.drawablepageindicator.widget.DrawablePagerIndicator.java
/** * @param canvas// w w w. j a va2 s . c o m */ @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return; } final int count = mViewPager.getAdapter().getCount(); if (count == 0) { return; } if (mCurrentPage >= count) { setCurrentItem(count - 1); return; } float dx = -1; Bitmap imageChildDefault = BitmapFactory.decodeResource(mContext.getResources(), drawableDefaultId); Bitmap imageChildSelected = BitmapFactory.decodeResource(mContext.getResources(), drawableSelectedId); Bitmap imageToDraw; int imageSize = imageChildDefault.getWidth(); int canvasWidth = canvas.getWidth(); int circlesWith = (imageSize * count) + imageSpacing * (count - 1); int startingPoint = (canvasWidth - circlesWith) / 2; for (int i = 0; i < count; i++) { if (i == 0) { dx = 0; } /** * position images indicator on the center */ if (mCentered) { dx = startingPoint + i * (imageSize + imageSpacing); } if (mCurrentPage == i) { imageToDraw = imageChildSelected; } else { imageToDraw = imageChildDefault; } canvas.drawBitmap(imageToDraw, dx, 0, null); /** * position images indicator from the left */ if (!mCentered) { dx += imageChildDefault.getWidth() + imageSpacing; } } }
From source file:com.example.sergey.currentweather.ui.fragment.MainFragment.java
private void initSwipe() { ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) {/* w w w .j a v a2 s . co m*/ @Override public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { return false; } @Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { int position = viewHolder.getAdapterPosition(); if (direction == ItemTouchHelper.LEFT) { deleteData(mCityListAdapter.removeItem(position)); } } @Override public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { Bitmap icon; if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) { View itemView = viewHolder.itemView; float height = (float) itemView.getBottom() - (float) itemView.getTop(); float width = height / 3; if (dX < 0) { mPoint.setColor(Color.parseColor("#D32F2F")); RectF background = new RectF((float) itemView.getRight() + dX, (float) itemView.getTop(), (float) itemView.getRight(), (float) itemView.getBottom()); c.drawRect(background, mPoint); icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_delete_white); RectF icon_dest = new RectF((float) itemView.getRight() - 2 * width, (float) itemView.getTop() + width, (float) itemView.getRight() - width, (float) itemView.getBottom() - width); c.drawBitmap(icon, null, icon_dest, mPoint); } } super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); } }; ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback); itemTouchHelper.attachToRecyclerView(mRecyclerView); }
From source file:com.example.SmartBoard.DrawingView.java
public void onDragDraw(Canvas canvas, int x, int y) { canvas.drawBitmap(dragImage, x, y - 20, drawPaint); }
From source file:au.com.zacher.popularmovies.activity.layout.CollapsingTitleLayout.java
@Override public void draw(@NonNull Canvas canvas) { final int saveCount = canvas.save(); final int toolbarHeight = this.mToolbar.getHeight(); canvas.clipRect(0, 0, canvas.getWidth(), interpolate(canvas.getHeight(), toolbarHeight, this.mScrollOffset)); // Now call super and let it draw the background, etc super.draw(canvas); if (this.mTitleToDraw != null) { float x = this.mTextLeft; float y = this.mTextTop; final float ascent = this.mTextPaint.ascent() * this.mScale; final float descent = this.mTextPaint.descent() * this.mScale; final float h = descent - ascent; if (DEBUG_DRAW) { // Just a debug tool, which drawn a Magneta rect in the text bounds canvas.drawRect(this.mTextLeft, y - h + descent, this.mTextRight, y + descent, DEBUG_DRAW_PAINT); }//ww w. ja v a 2s . c o m if (this.mUseTexture) { y = y - h + descent; } if (this.mScale != 1f) { canvas.scale(this.mScale, this.mScale, x, y); } if (this.mUseTexture && this.mExpandedTitleTexture != null) { // If we should use a texture, draw it instead of text canvas.drawBitmap(this.mExpandedTitleTexture, x, y, this.mTexturePaint); } else { canvas.drawText(this.mTitleToDraw, x, y, this.mTextPaint); } } canvas.restoreToCount(saveCount); }
From source file:com.example.zhangyangjing.roundcornerimageview.BezelImageView.java
@Override protected void onDraw(Canvas canvas) { if (mBounds == null) { return;/*from w w w.ja v a 2 s . c o m*/ } int width = mBounds.width(); int height = mBounds.height(); if (width == 0 || height == 0) { return; } if (!mCacheValid || width != mCachedWidth || height != mCachedHeight) { // Need to redraw the cache if (width == mCachedWidth && height == mCachedHeight) { // Have a correct-sized bitmap cache already allocated. Just erase it. mCacheBitmap.eraseColor(0); } else { // Allocate a new bitmap with the correct dimensions. mCacheBitmap.recycle(); //noinspection AndroidLintDrawAllocation mCacheBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); mCachedWidth = width; mCachedHeight = height; generateMaskPath(mCachedWidth, mCachedHeight); } Canvas cacheCanvas = new Canvas(mCacheBitmap); int sc = cacheCanvas.save(); mDesaturatePaint.setColorFilter((mDesaturateOnPress && isPressed()) ? mDesaturateColorFilter : null); cacheCanvas.saveLayer(mBoundsF, mDesaturatePaint, Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG); super.onDraw(cacheCanvas); cacheCanvas.drawPath(this.mMaskedPath, this.mMaskedPaint); cacheCanvas.restoreToCount(sc); } // Draw from cache canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null); }
From source file:com.android.app.MediaPlaybackActivity.java
/** * //from w w w . ja va2 s. c o m * * @param src * @return */ private Bitmap createCircleBitmap(Bitmap src) { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setARGB(255, 241, 239, 229); int width = src.getWidth(); int height = src.getHeight(); Bitmap target = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(target); canvas.drawCircle(width / 2, width / 2, width / 2, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(src, 0, 0, paint); return target; }
From source file:com.example.SmartBoard.DrawingView.java
public void onDrawColorDropper(Canvas canvas, int dropX, int dropY) { Bitmap dropperImage = BitmapFactory.decodeResource(getResources(), R.drawable.drop_color_iconpng); canvas.drawBitmap(dropperImage, dropX, dropY, drawPaint); }
From source file:android.support.designox.widget.CollapsingTextHelper.java
public void draw(Canvas canvas) { final int saveCount = canvas.save(); if (mTextToDraw != null && mDrawTitle) { float x = mCurrentDrawX; float y = mCurrentDrawY; final boolean drawTexture = mUseTexture && mExpandedTitleTexture != null; final float ascent; final float descent; if (drawTexture) { ascent = mTextureAscent * mScale; descent = mTextureDescent * mScale; } else {//from w w w .j a v a 2s. co m ascent = mTextPaint.ascent() * mScale; descent = mTextPaint.descent() * mScale; } if (DEBUG_DRAW) { // Just a debug tool, which drawn a Magneta rect in the text bounds canvas.drawRect(mCurrentBounds.left, y + ascent, mCurrentBounds.right, y + descent, DEBUG_DRAW_PAINT); } if (drawTexture) { y += ascent; } if (mScale != 1f) { canvas.scale(mScale, mScale, x, y); } if (drawTexture) { // If we should use a texture, draw it instead of text canvas.drawBitmap(mExpandedTitleTexture, x, y, mTexturePaint); } else { canvas.drawText(mTextToDraw, 0, mTextToDraw.length(), x, y, mTextPaint); } } canvas.restoreToCount(saveCount); }
From source file:com.amitupadhyay.aboutexample.util.CollapsingTextHelper.java
public void draw(Canvas canvas) { final int saveCount = canvas.save(); if (mTextToDraw != null && mDrawTitle) { float x = mCurrentDrawX; float y = mCurrentDrawY; final boolean drawTexture = mUseTexture && mExpandedTitleTexture != null; final float ascent; final float descent; // Update the TextPaint to the current text size mTextPaint.setTextSize(mCurrentTextSize); if (drawTexture) { ascent = mTextureAscent * mScale; descent = mTextureDescent * mScale; } else {/*from ww w . j a v a 2 s. co m*/ ascent = mTextPaint.ascent() * mScale; descent = mTextPaint.descent() * mScale; } if (DEBUG_DRAW) { // Just a debug tool, which drawn a Magneta rect in the text bounds canvas.drawRect(mCurrentBounds.left, y + ascent, mCurrentBounds.right, y + descent, DEBUG_DRAW_PAINT); } if (drawTexture) { y += ascent; } if (mScale != 1f) { canvas.scale(mScale, mScale, x, y); } if (drawTexture) { // If we should use a texture, draw it instead of text canvas.drawBitmap(mExpandedTitleTexture, x, y, mTexturePaint); } else { canvas.drawText(mTextToDraw, 0, mTextToDraw.length(), x, y, mTextPaint); } } canvas.restoreToCount(saveCount); }