本文整理匯總了Java中android.graphics.drawable.ShapeDrawable.draw方法的典型用法代碼示例。如果您正苦於以下問題:Java ShapeDrawable.draw方法的具體用法?Java ShapeDrawable.draw怎麽用?Java ShapeDrawable.draw使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.drawable.ShapeDrawable
的用法示例。
在下文中一共展示了ShapeDrawable.draw方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: roundBitmap
import android.graphics.drawable.ShapeDrawable; //導入方法依賴的package包/類
public static Bitmap roundBitmap(Bitmap bitmap, int i, int i2, float f, float f2, float f3,
float f4) throws Throwable {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Rect rect = new Rect(0, 0, width, height);
Bitmap createBitmap = (width == i && height == i2) ? Bitmap.createBitmap(bitmap.getWidth
(), bitmap.getHeight(), Config.ARGB_8888) : Bitmap.createBitmap(i, i2, Config
.ARGB_8888);
Canvas canvas = new Canvas(createBitmap);
Paint paint = new Paint();
Rect rect2 = new Rect(0, 0, i, i2);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(-12434878);
float[] fArr = new float[]{f, f, f2, f2, f3, f3, f4, f4};
ShapeDrawable shapeDrawable = new ShapeDrawable(new RoundRectShape(fArr, new RectF(0.0f,
0.0f, 0.0f, 0.0f), fArr));
shapeDrawable.setBounds(rect2);
shapeDrawable.draw(canvas);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect2, paint);
return createBitmap;
}
示例2: studyBitmapShader
import android.graphics.drawable.ShapeDrawable; //導入方法依賴的package包/類
/**
* 位圖圖像渲染
* @param canvas
*/
private void studyBitmapShader(Canvas canvas) {
//創建BitmapShader
//其中TileMode.MIRROR x方向鏡像 TileMode.REPEAT y方向重複
mBitmapShader = new BitmapShader(mBitMap, Shader.TileMode.MIRROR, Shader.TileMode.REPEAT);
//創建矩陣 來縮放圖片
Matrix matrix = new Matrix();
matrix.setScale(0.2f,0.2f);
mBitmapShader.setLocalMatrix(matrix);
mPaint.setAntiAlias(true);
mPaint.setShader(mBitmapShader);
//畫圓形的圖片
// canvas.drawCircle(mBitMap.getWidth()/2,mBitMap.getHeight()/2,300,mPaint);
//畫矩形的圖片
// Rect rect = new Rect(0,0,600,600);
// canvas.drawRect(rect,mPaint);
//
//畫橢圓的圖片
// RectF rectf = new RectF(0,0,400,300);
//
// canvas.drawOval(rectf,mPaint);
//用shapeDrawable 實現圓形圖片
ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
shapeDrawable.getPaint().setShader(mBitmapShader);
shapeDrawable.setBounds(0,0,400,400);
shapeDrawable.draw(canvas);
}