本文整理汇总了Java中android.graphics.Canvas.scale方法的典型用法代码示例。如果您正苦于以下问题:Java Canvas.scale方法的具体用法?Java Canvas.scale怎么用?Java Canvas.scale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.scale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: blurBitmap
import android.graphics.Canvas; //导入方法依赖的package包/类
public static Bitmap blurBitmap(Bitmap bkg, int width, int height) {
long startMs = System.currentTimeMillis();
float radius = 15;//越大模糊效果越大
float scaleFactor = 8;
//放大到整个view的大小
bkg = DrawableProvider.getReSizeBitmap(bkg, width, height);
Bitmap overlay = Bitmap.createBitmap((int) (width / scaleFactor)
, (int) (height / scaleFactor), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(overlay);
canvas.scale(1 / scaleFactor, 1 / scaleFactor);
Paint paint = new Paint();
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(bkg, 0, 0, paint);
overlay = FastBlur.doBlur(overlay, (int) radius, true);
Log.w("test", "cost " + (System.currentTimeMillis() - startMs) + "ms");
return overlay;
}
示例2: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Log.e(TAG, "onDraw....");
float radius = getWidth() / 10;
for (int i = 0; i < 8; i++) {
canvas.save();
// 获取绘制小圆的原点
Point point = circleAt(getWidth(), getHeight(), getWidth() / 2 - radius, i * (Math.PI / 4));
// 以point为原点坐标
canvas.translate(point.x, point.y);
// 设置尺寸
canvas.scale(scaleFloats[i], scaleFloats[i]);
// 设置透明度
mPaint.setAlpha(alphas[i]);
canvas.drawCircle(0, 0, radius, mPaint);
canvas.restore();
}
}
示例3: restoreBitmap
import android.graphics.Canvas; //导入方法依赖的package包/类
public static Bitmap restoreBitmap(Bitmap src, Matrix matrix, int w, int h) {
Bitmap result = Bitmap.createBitmap(w, h, src.getConfig());
result.setDensity(src.getDensity());
Canvas canvas = new Canvas(result);
float[] data = new float[9];
matrix.getValues(data);// 底部图片变化记录矩阵原始数据
Matrix3 cal = new Matrix3(data);// 辅助矩阵计算类
Matrix3 inverseMatrix = cal.inverseMatrix();// 计算逆矩阵
Matrix m = new Matrix();
m.setValues(inverseMatrix.getValues());
float[] f = new float[9];
m.getValues(f);
int dx = (int) f[Matrix.MTRANS_X];
int dy = (int) f[Matrix.MTRANS_Y];
float scale_x = f[Matrix.MSCALE_X];
float scale_y = f[Matrix.MSCALE_Y];
canvas.save();
canvas.translate(dx, dy);
canvas.scale(scale_x, scale_y);
canvas.drawBitmap(src, 0, 0, null);
canvas.restore();
return result;
}
示例4: stickerDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
protected void stickerDraw(Canvas canvas) {
if (containerView == null) {
return;
}
canvas.save();
Bitmap bitmap = centerImage.getBitmap();
if (bitmap != null) {
if (mirrored) {
canvas.scale(-1.0f, 1.0f);
canvas.translate(-baseSize.width, 0);
}
centerImage.setImageCoords(0, 0, (int) baseSize.width, (int) baseSize.height);
centerImage.draw(canvas);
}
canvas.restore();
}
示例5: addLogoToQRCode
import android.graphics.Canvas; //导入方法依赖的package包/类
/**
* 添加logo到二维码图片上
*
* @param src
* @param logo
* @return
*/
private static Bitmap addLogoToQRCode(Bitmap src, Bitmap logo) {
if (src == null || logo == null) {
return src;
}
int srcWidth = src.getWidth();
int srcHeight = src.getHeight();
int logoWidth = logo.getWidth();
int logoHeight = logo.getHeight();
float scaleFactor = srcWidth * 1.0f / 5 / logoWidth;
Bitmap bitmap = Bitmap.createBitmap(srcWidth, srcHeight, Bitmap.Config.ARGB_8888);
try {
Canvas canvas = new Canvas(bitmap);
canvas.drawBitmap(src, 0, 0, null);
canvas.scale(scaleFactor, scaleFactor, srcWidth / 2, srcHeight / 2);
canvas.drawBitmap(logo, (srcWidth - logoWidth) / 2, (srcHeight - logoHeight) / 2, null);
canvas.save(Canvas.ALL_SAVE_FLAG);
canvas.restore();
} catch (Exception e) {
bitmap = null;
}
return bitmap;
}
示例6: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
float circleSpacing = 4;
float radius = (Math.min(getWidth(), getHeight()) - circleSpacing * 2) / 6;
float x = getWidth() / 2 - (radius * 2 + circleSpacing);
float y = getHeight() / 2;
for (int i = 0; i < 3; i++) {
canvas.save();
float translateX = x + (radius * 2) * i + circleSpacing * i;
canvas.translate(translateX, y);
canvas.scale(scaleFloats[i], scaleFloats[i]);
canvas.drawCircle(0, 0, radius, mPaint);
canvas.restore();
}
}
示例7: draw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void draw(Canvas canvas) {
float progressWidth = mWidth * progressPercent / 100f;
float halfWidth = progressWidth / 2;
// 画背景图
canvas.save();
canvas.rotate(mRotation, getBounds().centerX(), getBounds().centerY());
float scale = 1 - progressWidth * 2.0f / mWidth;
canvas.scale(scale, scale, mWidth / 2.0f, mWidth / 2.0f);
canvas.drawCircle(mWidth / 2, mWidth / 2, mWidth / 2, mPaint);
canvas.restore();
// 画进度条
rectF.set(halfWidth, halfWidth, mWidth - halfWidth, mWidth - halfWidth);
canvas.drawArc(rectF, -90, progress, false, progressPaint);
}
示例8: draw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override public void draw(Canvas canvas) {
canvas.save();
canvas.scale(scale, scale, center.x, center.y);
canvas.rotate(rotate, center.x, center.y);
eye.draw(canvas);
eyeBound.draw(canvas);
for (int i = 0; i < numberOfSharingan; i++) {
canvas.save();
canvas.rotate(i * 120, center.x, center.y);
sharingans[i].draw(canvas);
canvas.restore();
}
canvas.restore();
}
示例9: drawTown
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawTown(Canvas canvas, int width, int height) {
Matrix matrix = mMatrix;
matrix.reset();
int bWidth = mDrawableTown.width();//mTown.getWidth();
int bHeight = mDrawableTown.height();//mTown.getHeight();
float townScale = 1f * width / bWidth;
float amplification = (0.3f * Math.max(mPercent - 1, 0) + 1);
float offsetx = width / 2 - (int) (width * amplification) / 2;
float offsety = mHeaderHeight * 0.1f * mPercent;
townScale = amplification * townScale;
if (offsety + bHeight * townScale < height) {
offsety = height - bHeight * townScale;
}
// matrix.postScale(townScale, townScale, mDrawableTown.width() / 2, mDrawableTown.height() / 2);
// matrix.postTranslate(offsetx, offsety);
// canvas.drawBitmap(mTown, matrix, null);
final int saveCount = canvas.getSaveCount();
canvas.save();
canvas.translate(offsetx, offsety);
canvas.scale(townScale, townScale);
mDrawableTown.draw(canvas);
canvas.restoreToCount(saveCount);
}
示例10: draw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void draw(Canvas canvas, Paint paint) {
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(3);
float circleSpacing=12;
float x = (getWidth()) / 2;
float y=(getHeight()) / 2;
canvas.translate(x, y);
canvas.scale(scaleFloat, scaleFloat);
canvas.rotate(degrees);
RectF rectF=new RectF(-x+circleSpacing,-y+circleSpacing,0+x-circleSpacing,0+y-circleSpacing);
canvas.drawArc(rectF, -45, 270, false, paint);
}
示例11: drawDragShadow
import android.graphics.Canvas; //导入方法依赖的package包/类
@SuppressLint("WrongCall")
public void drawDragShadow(Canvas canvas) {
final int saveCount = canvas.save(Canvas.MATRIX_SAVE_FLAG);
canvas.scale(getScaleX(), getScaleY());
onDraw(canvas);
canvas.restoreToCount(saveCount);
}
示例12: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(final Canvas canvas)
{
try {
if (recycled)
return;
repaint(getContext());
final int canvasSave = canvas.save();
canvas.translate(getPaddingLeft(), getPaddingTop());
canvas.translate(0, internalPaddingTop);
canvas.scale(scale, scale);
if (!genBackgroundBitmap.isRecycled()) {
canvas.drawBitmap(genBackgroundBitmap, 0, 0, bitmapPaint);
}
gridBitmap = null;
gridBitmap = generateGridBitmap(canvas);
canvas.drawBitmap(gridBitmap, gridX, gridY, bitmapPaint);
final int canvasSave2 = canvas.save();
canvas.translate(graphX, graphY);
for (final GraphService graph : graphs)
graph.draw(canvas);
canvas.restoreToCount(canvasSave2);
// if (!reflectionBitmap.isRecycled()) {
// canvas.drawBitmap(reflectionBitmap, reflectionX, reflectionY, bitmapPaint);
// }
canvas.restoreToCount(canvasSave);
}
catch (Exception e) {
e.printStackTrace();
}
}
示例13: getBitmapWithBorder
import android.graphics.Canvas; //导入方法依赖的package包/类
private Bitmap getBitmapWithBorder(View v, float scale) {
Bitmap bitmap = getBitmapFromView(v,0);
Bitmap b = getBitmapFromView(v,1);
Canvas can = new Canvas(bitmap);
Paint paint = new Paint();
paint.setAlpha(150);
can.scale(scale,scale,mDownX,mDownY);
can.rotate(3);
can.drawBitmap(b,0,0,paint);
return bitmap;
}
示例14: draw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void draw(Canvas canvas)
{
final float scaleFactorX = getWidth()/(WIDTH * 1.f);
final float scaleFactorY = getHeight()/(HEIGHT * 1.f);
if(canvas!=null) {
final int savedState = canvas.save();
canvas.scale(scaleFactorX, scaleFactorY);
bg.draw(canvas);
player.draw(canvas);
canvas.restoreToCount(savedState);
}
}
示例15: zoom
import android.graphics.Canvas; //导入方法依赖的package包/类
public CanvasTransformer zoom(final int openedX, final int closedX,
final int openedY, final int closedY,
final int px, final int py, final Interpolator interp) {
initTransformer();
mTrans = new CanvasTransformer() {
public void transformCanvas(Canvas canvas, float percentOpen) {
mTrans.transformCanvas(canvas, percentOpen);
float f = interp.getInterpolation(percentOpen);
canvas.scale((openedX - closedX) * f + closedX,
(openedY - closedY) * f + closedY, px, py);
}
};
return mTrans;
}