@Override protected void onDraw(Canvas canvas) { // draw the background and color wheel canvas.drawBitmap(mBackground, mBackgroundPosition.x, mBackgroundPosition.y, null); canvas.drawBitmap(mWheel, mWheelPosition.x, mWheelPosition.y, null); // setup paint for the gradient filling Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setStyle(Paint.Style.FILL); paint.setStrokeWidth(2.0f); // create a shader that will show the range of brightness settings float[] gradientStartColor = new float[3]; float[] gradientEndColor = new float[3]; System.arraycopy(mNewColor, 0, gradientStartColor, 0, mNewColor.length); System.arraycopy(mNewColor, 0, gradientEndColor, 0, mNewColor.length); gradientStartColor[2] = 1.0f; gradientEndColor[2] = 0.0f; Shader gradientShader = new LinearGradient( (float) (mWheelPosition.x + mRadius), mWheelPosition.y, mOuterArcRect.right, mWheelPosition.y + mWheel.getHeight(), Color.HSVToColor(gradientStartColor), Color.HSVToColor(gradientEndColor), Shader.TileMode.MIRROR); paint.setShader(gradientShader); canvas.drawPath(mArcPath, paint); drawHSCrosshairs(canvas); drawBrightnessIndicator(canvas); }
/** * Draws the game controls. * * @param Canvas canvas */ private void drawControls(Canvas canvas) { canvas.drawBitmap(mCtrlUpArrow.getBitmap(), mCtrlUpArrow.getX(), mCtrlUpArrow.getY(), null); canvas.drawBitmap( mCtrlDownArrow.getBitmap(), mCtrlDownArrow.getX(), mCtrlDownArrow.getY(), null); canvas.drawBitmap( mCtrlLeftArrow.getBitmap(), mCtrlLeftArrow.getX(), mCtrlLeftArrow.getY(), null); canvas.drawBitmap( mCtrlRightArrow.getBitmap(), mCtrlRightArrow.getX(), mCtrlRightArrow.getY(), null); }
/** * Drawing src bitmap to dest bitmap with applied mask. * * @param src source bitmap * @param mask bitmap mask * @param dest destination bitmap * @param clearColor clear color */ public static void drawMasked(Bitmap src, Drawable mask, Bitmap dest, int clearColor) { clearBitmap(dest, clearColor); Canvas canvas = new Canvas(dest); canvas.drawBitmap( src, new Rect(0, 0, src.getWidth(), src.getHeight()), new Rect(0, 0, dest.getWidth(), dest.getHeight()), new Paint(Paint.FILTER_BITMAP_FLAG)); if (mask instanceof BitmapDrawable) { ((BitmapDrawable) mask) .getPaint() .setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); } else if (mask instanceof NinePatchDrawable) { ((NinePatchDrawable) mask) .getPaint() .setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); } else { throw new RuntimeException("Supported only BitmapDrawable or NinePatchDrawable"); } mask.setBounds(0, 0, mask.getIntrinsicWidth(), mask.getIntrinsicHeight()); mask.draw(canvas); canvas.setBitmap(null); }
/** * Drawing src bitmap to dest bitmap with round mask. Dest might be squared, src is recommended to * be square * * @param src source bitmap * @param dest destination bitmap * @param clearColor clear color */ public static void drawInRound(Bitmap src, Bitmap dest, int clearColor) { if (dest.getWidth() != dest.getHeight()) { throw new RuntimeException("dest Bitmap must have square size"); } clearBitmap(dest, clearColor); Canvas canvas = new Canvas(dest); int r = dest.getWidth() / 2; Rect sourceRect = WorkCache.RECT1.get(); Rect destRect = WorkCache.RECT2.get(); sourceRect.set(0, 0, src.getWidth(), src.getHeight()); destRect.set(0, 0, dest.getWidth(), dest.getHeight()); Paint paint = WorkCache.PAINT.get(); paint.reset(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.RED); paint.setAntiAlias(true); canvas.drawCircle(r, r, r, paint); paint.reset(); paint.setFilterBitmap(true); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(src, sourceRect, destRect, paint); canvas.setBitmap(null); }
/** * Drawing src bitmap to dest bitmap with rounded corners * * @param src source bitmap * @param dest destination bitmap * @param radius radius in destination bitmap scale * @param clearColor clear color */ public static void drawRoundedCorners(Bitmap src, Bitmap dest, int radius, int clearColor) { clearBitmap(dest, clearColor); Canvas canvas = new Canvas(dest); Rect sourceRect = WorkCache.RECT1.get(); Rect destRect = WorkCache.RECT2.get(); sourceRect.set(0, 0, src.getWidth(), src.getHeight()); destRect.set(0, 0, dest.getWidth(), dest.getHeight()); RectF roundRect = WorkCache.RECTF1.get(); roundRect.set(0, 0, dest.getWidth(), dest.getHeight()); Paint paint = WorkCache.PAINT.get(); paint.reset(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.RED); paint.setAntiAlias(true); canvas.drawRoundRect(roundRect, radius, radius, paint); paint.reset(); paint.setFilterBitmap(true); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(src, sourceRect, destRect, paint); canvas.setBitmap(null); }
private void drawPlaceHolder(Canvas canvas) { placeholderPaint.setColor(layout.placeHolderColor); placeholderTextPaint.setAlpha(255); placeholderPaint.setAlpha(255); avatarPaint.setAlpha(255); rect.set( layout.layoutAvatarLeft, layout.layoutAvatarTop, layout.layoutAvatarLeft + layout.layoutAvatarWidth, layout.layoutAvatarTop + layout.layoutAvatarWidth); canvas.drawRect(rect, placeholderPaint); if (layout.usePlaceholder) { canvas.drawText( layout.placeHolderName, layout.placeholderLeft, layout.placeholderTop, placeholderTextPaint); } else { rect2.set(0, 0, placeholder.getWidth(), placeholder.getHeight()); canvas.drawBitmap(placeholder, rect2, rect, avatarPaint); } }
private void drawFooter(Canvas canvas) { final ZLView view = ZLApplication.Instance().getCurrentView(); final ZLView.FooterArea footer = view.getFooterArea(); if (footer == null) { myFooterBitmap = null; return; } if (myFooterBitmap != null && (myFooterBitmap.getWidth() != getWidth() || myFooterBitmap.getHeight() != footer.getHeight())) { myFooterBitmap = null; } if (myFooterBitmap == null) { myFooterBitmap = Bitmap.createBitmap(getWidth(), footer.getHeight(), Bitmap.Config.RGB_565); } final ZLAndroidPaintContext context = new ZLAndroidPaintContext( new Canvas(myFooterBitmap), getWidth(), footer.getHeight(), view.isScrollbarShown() ? getVerticalScrollbarWidth() : 0); footer.paint(context); canvas.drawBitmap(myFooterBitmap, 0, getHeight() - footer.getHeight(), myPaint); }
public void onDraw(Canvas cnv) { if ((mBmp == null) || (bRedraw)) { getViewSizes(); getXYminmax(); if (p_xscale_auto) calcXgridRange(); if (p_yscale_auto) calcYgridRange(); calcXYcoefs(); reset(); drawData(); if (p_grid_vis) drawGrid(); if (p_xtext_vis) drawXlabel(); if (p_ytext_vis) drawYlabel(); if (p_border_vis) drawBorder(); if (p_axis_vis) drawAxis(); bRedraw = false; } cnv.drawBitmap(mBmp, 0, 0); }
@Override public void drawTo(Canvas drawCanvas, float left, float top, Paint paint, boolean onlyDirty) { final Rect src = new Rect(0, 0, mTileSize, mTileSize); final Rect dst = new Rect(0, 0, mTileSize, mTileSize); drawCanvas.save(); drawCanvas.translate(-left, -top); drawCanvas.clipRect(0, 0, mWidth, mHeight); for (int j = 0; j < mTilesY; j++) { for (int i = 0; i < mTilesX; i++) { dst.offsetTo(i * mTileSize, j * mTileSize); final int p = j * mTilesX + i; final Tile tile = mTiles[p]; if (!onlyDirty || tile.dirty) { drawCanvas.drawBitmap(tile.getBitmap(), src, dst, paint); tile.dirty = false; if (mDebug) { mDrawCount++; dbgPaint.setColor(DEBUG_COLORS[tile.top % DEBUG_COLORS.length]); // drawCanvas.drawRect(dst, (mDrawCount % 2 == 0) ? dbgPaint1 : dbgPaint2); drawCanvas.drawRect(dst, dbgPaint); // drawCanvas.drawRect(dst, dbgStroke); drawCanvas.drawText( String.format("%d,%d v%d", tile.x, tile.y, tile.top), dst.left + 4, dst.bottom - 4, dbgTextPaint); } } } } drawCanvas.restore(); }
/** * Draws all visual elements of the game. * * @param Canvas canvas */ private void doDraw(Canvas canvas) { centerView(); canvas.drawBitmap(mBackgroundImage, 0, 0, null); if (!updatingGameTiles) { drawGameTiles(canvas); } if (mPlayerUnit != null) { canvas.drawBitmap(mPlayerUnit.getBitmap(), mPlayerUnit.getX(), mPlayerUnit.getY(), null); } drawControls(canvas); canvas.drawText(mLastStatusMessage, 30, 30, mUiTextPaint); }
@Override protected void onDraw(Canvas canvas) { canvas.drawColor(Color.LTGRAY); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); canvas.drawPath(mPath, mPaint); }
private static Bitmap convertToAlphaMask(Bitmap b) { Bitmap a = Bitmap.createBitmap(b.getWidth(), b.getHeight(), Bitmap.Config.ALPHA_8); Canvas c = new Canvas(a); Paint pt = new Paint(); pt.setColorFilter(new ColorMatrixColorFilter(MASK)); c.drawBitmap(b, 0.0f, 0.0f, pt); return a; }
public void drawTo(Canvas canvas, int tileNumber, Rect dest) { int tm = tileNumber / SLICE_SIZE; int tn = tileNumber % SLICE_SIZE; canvas.drawBitmap( tilesBitmap[tm % SLICE_COUNT], new Rect(0, tn * tileSize, tileSize, tn * tileSize + tileSize), dest, null /*paint*/); }
public void onDraw(Canvas canvas) { Bitmap bitmap = mTexture; Paint paint = mPaint; int i = getWidth(); int j = getHeight(); int k = mTextureWidth; int l = mTextureHeight; for (int i1 = 0; i1 < i; i1 += k) { for (int j1 = 0; j1 < j; j1 += l) canvas.drawBitmap(bitmap, i1, j1, paint); } }
@Override protected void onDraw(Canvas canvas) { canvas.drawColor( (props.containsKeyAndNotNull(TiC.PROPERTY_BACKGROUND_COLOR)) ? TiConvert.toColor(props, TiC.PROPERTY_BACKGROUND_COLOR) : TiConvert.toColor("transparent")); canvas.drawBitmap(tiBitmap, 0, 0, tiBitmapPaint); canvas.drawPath(tiPath, tiPaint); }
private void drawBackGroud(Canvas canvas) { if (dataHolder.getGameEngine().getGameField().getSizeY() != backGroundImageFieldSizeY || dataHolder.getGameEngine().getGameField().getSizeX() != backGroundImageFieldSizeX || backgroundImageSaved == null) { backgroundImageSaved = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.RGB_565); Canvas newCanvas = new Canvas(backgroundImageSaved); drawBackGroudImageOnGivenCanvas(newCanvas); backGroundImageFieldSizeX = dataHolder.getGameEngine().getGameField().getSizeX(); backGroundImageFieldSizeY = dataHolder.getGameEngine().getGameField().getSizeY(); } canvas.drawBitmap(backgroundImageSaved, 0, 0, null); }
/** * 转换图片成圆形 * * @param bitmap 传入Bitmap对象 * @return */ public Bitmap toRoundBitmap(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); float roundPx; float left, top, right, bottom, dst_left, dst_top, dst_right, dst_bottom; if (width <= height) { roundPx = width / 2; top = 0; bottom = width; left = 0; right = width; height = width; dst_left = 0; dst_top = 0; dst_right = width; dst_bottom = width; } else { roundPx = height / 2; float clip = (width - height) / 2; left = clip; right = width - clip; top = 0; bottom = height; width = height; dst_left = 0; dst_top = 0; dst_right = height; dst_bottom = height; } Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect src = new Rect((int) left, (int) top, (int) right, (int) bottom); final Rect dst = new Rect((int) dst_left, (int) dst_top, (int) dst_right, (int) dst_bottom); final RectF rectF = new RectF(dst); paint.setAntiAlias(true); 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, src, dst, paint); return output; }
/** * Called whenever the plot needs to be drawn via the Handler, which invokes invalidate(). Should * never be called directly; use {@link #redraw()} instead. * * @param canvas */ @Override protected void onDraw(Canvas canvas) { if (renderMode == RenderMode.USE_BACKGROUND_THREAD) { synchronized (pingPong) { Bitmap bmp = pingPong.getBitmap(); if (bmp != null) { canvas.drawBitmap(bmp, 0, 0, null); } } } else if (renderMode == RenderMode.USE_MAIN_THREAD) { renderOnCanvas(canvas); } else { throw new IllegalArgumentException("Unsupported Render Mode: " + renderMode); } }
/** * Draw the correct gallow image. Calculate the best hangman image, and then search the ID from * the resource */ private void drawGallow() { double steps = (((double) config.DRAW_GALLOW_STEPS) / Hangman.settings.get_tries()) * (Hangman.settings.get_tries() - Hangman.getLives()); int nr; if (steps < 12) nr = (int) Math.round(steps); else if (steps >= 13) nr = 13; else nr = 12; String HANGMAN = "hangman" + nr; int resID = this.getResources().getIdentifier(HANGMAN, "drawable", "com.mprog.hangman"); gallow = (Bitmap) BitmapFactory.decodeResource(getResources(), resID); canvas.drawBitmap(gallow, 0, (45 * scrMlt), null); }
@Override public void drawPixmap( Pixmap pixmap, int x, int y, int srcX, int srcY, int srcWidth, int srcHeight) { srcRect.left = srcX; srcRect.top = srcY; srcRect.right = srcX + srcWidth - 1; srcRect.bottom = srcY + srcHeight - 1; dstRect.left = x; dstRect.top = y; dstRect.right = x + srcWidth - 1; dstRect.bottom = y + srcHeight - 1; canvas.drawBitmap(((AndroidPixmap) pixmap).bitmap, srcRect, dstRect, null); }
/** * Draw the symbol. * * @param ytop The ylocation (in pixels) where the top of the staff starts. */ public void Draw(Canvas canvas, Paint paint, int ytop) { if (!candraw) return; canvas.translate(getWidth() - getMinWidth(), 0); Bitmap numer = images[numerator]; Bitmap denom = images[denominator]; /* Scale the image width to match the height */ int imgheight = SheetMusic.NoteHeight * 2; int imgwidth = numer.getWidth() * imgheight / numer.getHeight(); Rect src = new Rect(0, 0, numer.getWidth(), numer.getHeight()); Rect dest = new Rect(0, ytop, imgwidth, ytop + imgheight); canvas.drawBitmap(numer, src, dest, paint); src = new Rect(0, 0, denom.getWidth(), denom.getHeight()); dest = new Rect( 0, ytop + SheetMusic.NoteHeight * 2, imgwidth, ytop + SheetMusic.NoteHeight * 2 + imgheight); canvas.drawBitmap(denom, src, dest, paint); canvas.translate(-(getWidth() - getMinWidth()), 0); }
public static Bitmap colorMatrixBmp(Bitmap bmp, float[] matrixSrc) { int width = bmp.getWidth(); int height = bmp.getHeight(); ColorMatrix matrix = new ColorMatrix(); matrix.set(matrixSrc); ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix); Paint p = new Paint(); p.setColorFilter(filter); Bitmap colorBmp = Bitmap.createBitmap(width, height, bmp.getConfig()); Canvas c = new Canvas(colorBmp); c.drawBitmap(bmp, 0, 0, p); return colorBmp; }
/** * Draws the game tiles used in the current level. * * @param Canvas canvas */ private void drawGameTiles(Canvas canvas) { int gameTilesSize = mGameTiles.size(); for (int i = 0; i < gameTilesSize; i++) { if (mGameTiles.get(i) != null) { mGameTiles.get(i).setX(mGameTiles.get(i).getX() - mScreenXOffset); mGameTiles.get(i).setY(mGameTiles.get(i).getY() - mScreenYOffset); if (mGameTiles.get(i).isVisible()) { canvas.drawBitmap( mGameTiles.get(i).getBitmap(), mGameTiles.get(i).getX(), mGameTiles.get(i).getY(), null); } } } }
/** * 根据原图和变长绘制圆形图片 * * @param source * @return */ public static Bitmap createCircleImage(Bitmap source) { if (source == null) { return null; } final Paint paint = new Paint(); paint.setAntiAlias(true); int min = source.getWidth(); Bitmap target = Bitmap.createBitmap(min, min, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(target); // 绘制圆形 canvas.drawCircle(min / 2, min / 2, min / 2, paint); // 使用SRC_IN paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); // 绘制图片 canvas.drawBitmap(source, 0, 0, paint); return target; }
public boolean play(Canvas out, Context context) { float aspect = out.getHeight() * 1.0f / out.getWidth(); int width = 1000; Bitmap bitmap = Bitmap.createBitmap(width, Math.round(width * aspect), Bitmap.Config.RGB_565); Canvas c = new Canvas(bitmap); bounds = c.getClipBounds(); windowBounds = out.getClipBounds(); if (paint == null) { String currentSize = Shared.getOptionAtribute( context.getString(R.string.FontSize), getString(R.string.current), context); String textColour = Shared.getOptionAtribute( context.getString(R.string.Colours), getString(R.string.text), context); paint = new Paint(); paint.setColor( Color.parseColor( Shared.getOption(context.getString(R.string.Colours) + "/" + textColour, context) .getTextContent())); paint.setTextSize( new Integer( Shared.getOption(context.getString(R.string.FontSize) + "/" + currentSize, context) .getTextContent())); String font = Shared.getOptionAtribute( getString(R.string.Font), getString(R.string.current), getApplicationContext()); Typeface face = Typeface.createFromAsset( getAssets(), Shared.getOption(getString(R.string.Font) + "/" + font, getApplicationContext()) .getTextContent()); paint.setTypeface(face); } c.drawText("tap the screen", 50, 50, paint); c.drawText("to start", 50, 100, paint); c.drawText("the test.", 50, 150, paint); c.drawText("Pick the Months", 50, 200, paint); c.drawText("in reverse order", 50, 250, paint); // c.drawText("",50,300,paint); out.drawBitmap(bitmap, c.getClipBounds(), out.getClipBounds(), paint); return finished; }
private void onDrawStatic(final Canvas canvas) { myBitmapManager.setSize(getWidth(), getMainAreaHeight()); canvas.drawBitmap(myBitmapManager.getBitmap(ZLView.PageIndex.current), 0, 0, myPaint); drawFooter(canvas); new Thread() { @Override public void run() { final ZLView view = ZLApplication.Instance().getCurrentView(); final ZLAndroidPaintContext context = new ZLAndroidPaintContext( canvas, getWidth(), getMainAreaHeight(), view.isScrollbarShown() ? getVerticalScrollbarWidth() : 0); view.preparePage(context, ZLView.PageIndex.next); } }.start(); }
private void drawSun(Canvas canvas) { Matrix matrix = mMatrix; matrix.reset(); // float dragPercent = mPercent; if (dragPercent > 1.0f) { // Slow down if pulling over set height dragPercent = (dragPercent + 1.0f) / 2; } float sunRadius = (float) mSunSize / 2.0f; float sunRotateGrowth = SUN_INITIAL_ROTATE_GROWTH; float offsetX = mSunLeftOffset; float offsetY = mSunTopOffset + (mTotalDragDistance / 2) * (1.0f - dragPercent); // Move the sun up float scalePercentDelta = dragPercent - SCALE_START_PERCENT; if (scalePercentDelta > 0) { // float scalePercent = scalePercentDelta / (1.0f - SCALE_START_PERCENT); float sunScale = 1.0f - (1.0f - SUN_FINAL_SCALE) * scalePercent; sunRotateGrowth += (SUN_FINAL_ROTATE_GROWTH - SUN_INITIAL_ROTATE_GROWTH) * scalePercent; // 后调用的pre操作先执行,而后调用的post操作则后执行 // matrix.preTranslate(offsetX, offsetY * (2.0f - sunScale)); // 将(0,0)向右下移动 matrix.preTranslate( offsetX + (sunRadius - sunRadius * sunScale), offsetY * (2.0f - sunScale)); matrix.preScale(sunScale, sunScale); offsetX += sunRadius; offsetY = offsetY * (2.0f - sunScale) + sunRadius * sunScale; } else { matrix.postTranslate(offsetX, offsetY); offsetX += sunRadius; offsetY += sunRadius; } // 下拉顺时针,刷新上拉逆时针 float r = (isRefreshing ? -360 : 360) * mRotate * (isRefreshing ? 1 : sunRotateGrowth); // 旋转的圆心 matrix.postRotate(r, offsetX, offsetY); canvas.drawBitmap(mSun, matrix, null); }
public static Bitmap roundedCornerBitmap(Bitmap bitmap, float radis) { 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 = radis; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(Color.WHITE); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
private void drawTown(Canvas canvas) { Matrix matrix = mMatrix; matrix.reset(); int y = Math.max(0, mTop - mTotalDragDistance); float dragPercent = Math.min(1f, Math.abs(mPercent)); float townScale; float townTopOffset; float townMoveOffset; float scalePercentDelta = dragPercent - SCALE_START_PERCENT; if (scalePercentDelta > 0) { /** * Change townScale between {@link #TOWN_INITIAL_SCALE} and {@link #TOWN_FINAL_SCALE} * depending on {@link #mPercent} Change townTopOffset between {@link #mTownInitialTopOffset} * and {@link #mTownFinalTopOffset} depending on {@link #mPercent} */ float scalePercent = scalePercentDelta / (1.0f - SCALE_START_PERCENT); townScale = TOWN_INITIAL_SCALE + (TOWN_FINAL_SCALE - TOWN_INITIAL_SCALE) * scalePercent; townTopOffset = mTownInitialTopOffset - (mTownFinalTopOffset - mTownInitialTopOffset) * scalePercent; townMoveOffset = mTownMoveOffset * (1.0f - scalePercent); } else { float scalePercent = dragPercent / SCALE_START_PERCENT; townScale = TOWN_INITIAL_SCALE; townTopOffset = mTownInitialTopOffset; townMoveOffset = mTownMoveOffset * scalePercent; } float offsetX = -(mScreenWidth * townScale - mScreenWidth) / 2.0f; // float offsetY = (1.0f - dragPercent) * mTotalDragDistance // Offset canvas moving float offsetY = y + +townTopOffset - mTownHeight * (townScale - 1.0f) / 2 // Offset town scaling + townMoveOffset; // Give it a little move matrix.postScale(townScale, townScale); // 移动建筑的中心点 matrix.postTranslate(offsetX, offsetY); canvas.drawBitmap(mTown, matrix, null); }
public static Bitmap toRoundCorner(Bitmap bitmap) { int height = bitmap.getHeight(); int width = bitmap.getHeight(); Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, width, height); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); // paint.setColor(0xff424242); paint.setColor(Color.TRANSPARENT); canvas.drawCircle(width / 2, height / 2, width / 2, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }