本文整理汇总了Java中android.graphics.Canvas.drawBitmap方法的典型用法代码示例。如果您正苦于以下问题:Java Canvas.drawBitmap方法的具体用法?Java Canvas.drawBitmap怎么用?Java Canvas.drawBitmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.drawBitmap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processFrame
import android.graphics.Canvas; //导入方法依赖的package包/类
private void processFrame(Mat frame) {
Canvas canvas = null;
SurfaceHolder holder = mCameraProcessPreview.getHolder();
try {
canvas = holder.lockCanvas(null);
if (canvas != null) {
Bitmap result = ImageProcessing.preprocess(frame, mOpenCvCameraView.getWidth(), mOpenCvCameraView.getHeight());
canvas.drawBitmap(result, 0, 0, new Paint());
}
} finally {
if (canvas != null) {
holder.unlockCanvasAndPost(canvas);
}
}
}
示例2: getTexture
import android.graphics.Canvas; //导入方法依赖的package包/类
/**
* Generates nearest power of two sized Bitmap for give Bitmap. Returns this
* new Bitmap using default return statement + original texture coordinates
* are stored into RectF.
*/
private Bitmap getTexture(Bitmap bitmap, RectF textureRect) {
// Bitmap original size.
int w = bitmap.getWidth();
int h = bitmap.getHeight();
// Bitmap size expanded to next power of two. This is done due to
// the requirement on many devices, texture width and height should
// be power of two.
int newW = getNextHighestPO2(w);
int newH = getNextHighestPO2(h);
// TODO: Is there another way to create a bigger Bitmap and copy
// original Bitmap to it more efficiently? Immutable bitmap anyone?
Bitmap bitmapTex = Bitmap.createBitmap(newW, newH, bitmap.getConfig());
Canvas c = new Canvas(bitmapTex);
c.drawBitmap(bitmap, 0, 0, null);
// Calculate final texture coordinates.
float texX = (float) w / newW;
float texY = (float) h / newH;
textureRect.set(0f, 0f, texX, texY);
return bitmapTex;
}
示例3: draw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void draw(Canvas canvas) {
canvas.clipRect(borderRect);
processPath(borderPath);
canvas.drawPath(borderPath, mBackGroundPaint);
canvas.drawCircle(borderRect.right / 2, borderRect.top + circleRadius, circleRadius, mOuterCircleFillPaint);
canvas.drawCircle(borderRect.right / 2, borderRect.top + circleRadius, circleRadius - outerCircleOffset, mCircleFillPaint);
float textHeight = mOuterCircleFillPaint.descent() - mOuterCircleFillPaint.ascent();
float textOffset = (textHeight / 2) - mOuterCircleFillPaint.descent();
if (null != bitmapIcon)
canvas.drawBitmap(bitmapIcon, borderRect.right / 2 - bitmapIcon.getWidth() / 2,
borderRect.top + circleRadius - bitmapIcon.getHeight() / 2, mBackGroundPaint);
//canvas.drawText(mDrawText, borderRect.right / 2 - (mOuterCircleFillPaint.measureText(mDrawText)/2), borderRect.top + circleRadius + textOffset, mOuterCircleFillPaint);
}
示例4: drawSelector
import android.graphics.Canvas; //导入方法依赖的package包/类
public void drawSelector(View content, Canvas canvas, float openPercent) {
if (!mSelectorEnabled) return;
if (mSelectorDrawable != null && mSelectedView != null) {
String tag = (String) mSelectedView.getTag(R.id.selected_view);
if (tag.equals(TAG+"SelectedView")) {
canvas.save();
int left, right, offset;
offset = (int) (mSelectorDrawable.getWidth() * openPercent);
if (mMode == SlidingMenu.LEFT) {
right = content.getLeft();
left = right - offset;
canvas.clipRect(left, 0, right, getHeight());
canvas.drawBitmap(mSelectorDrawable, left, getSelectorTop(), null);
} else if (mMode == SlidingMenu.RIGHT) {
left = content.getRight();
right = left + offset;
canvas.clipRect(left, 0, right, getHeight());
canvas.drawBitmap(mSelectorDrawable, right - mSelectorDrawable.getWidth(), getSelectorTop(), null);
}
canvas.restore();
}
}
}
示例5: drawCurrentPageArea
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawCurrentPageArea(Canvas canvas, Bitmap bitmap, Path path) {
mPath0.reset();
mPath0.moveTo(mBezierStart1.x, mBezierStart1.y);
mPath0.quadTo(mBezierControl1.x, mBezierControl1.y, mBezierEnd1.x,
mBezierEnd1.y);
mPath0.lineTo(mTouch.x, mTouch.y);
mPath0.lineTo(mBezierEnd2.x, mBezierEnd2.y);
mPath0.quadTo(mBezierControl2.x, mBezierControl2.y, mBezierStart2.x,
mBezierStart2.y);
mPath0.lineTo(mCornerX, mCornerY);
mPath0.close();
canvas.save();
canvas.clipPath(path, Region.Op.XOR);
canvas.drawBitmap(bitmap, 0, 0, null);
try {
canvas.restore();
} catch (Exception e) {
}
}
示例6: drawMove
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void drawMove(Canvas canvas) {
switch (mDirection){
case NEXT:
int dis = (int) (mViewWidth - mStartX + mTouchX);
if (dis > mViewWidth){
dis = mViewWidth;
}
//计算bitmap截取的区域
mSrcRect.left = mViewWidth - dis;
//计算bitmap在canvas显示的区域
mDestRect.right = dis;
canvas.drawBitmap(mNextBitmap,0,0,null);
canvas.drawBitmap(mCurBitmap,mSrcRect,mDestRect,null);
addShadow(dis,canvas);
break;
default:
mSrcRect.left = (int) (mViewWidth - mTouchX);
mDestRect.right = (int) mTouchX;
canvas.drawBitmap(mCurBitmap,0,0,null);
canvas.drawBitmap(mNextBitmap,mSrcRect,mDestRect,null);
addShadow((int) mTouchX,canvas);
break;
}
}
示例7: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
int pic=SkinMan.currentSkin.actionPicture();
Drawable backgroundDrawable = pic!=0 ? ContextCompat.getDrawable(getContext(), pic) : ApplicationLoader.getCachedWallpaper();
int color = ApplicationLoader.getServiceMessageColor();
if (currentColor != color) {
currentColor = color;
shadowView.getDrawable().setColorFilter(new PorterDuffColorFilter(color | 0xff000000, PorterDuff.Mode.MULTIPLY));
}
if (ApplicationLoader.isCustomTheme() || pic !=0 && backgroundDrawable != null) {
phoneTextView.setTextColor(0xffffffff);
shadowView.setVisibility(VISIBLE);
if (backgroundDrawable instanceof ColorDrawable) {
backgroundDrawable.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
backgroundDrawable.draw(canvas);
} else if (backgroundDrawable instanceof BitmapDrawable) {
Bitmap bitmap = ((BitmapDrawable) backgroundDrawable).getBitmap();
float scaleX = (float) getMeasuredWidth() / (float) bitmap.getWidth();
float scaleY = (float) getMeasuredHeight() / (float) bitmap.getHeight();
float scale = scaleX < scaleY ? scaleY : scaleX;
int width = (int) (getMeasuredWidth() / scale);
int height = (int) (getMeasuredHeight() / scale);
int x = (bitmap.getWidth() - width) / 2;
int y = (bitmap.getHeight() - height) / 2;
srcRect.set(x, y, x + width, y + height);
destRect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
canvas.drawBitmap(bitmap, srcRect, destRect, paint);
}
} else {
shadowView.setVisibility(INVISIBLE);
phoneTextView.setTextColor(0xffc2e5ff);
super.onDraw(canvas);
}
}
示例8: addReflection
import android.graphics.Canvas; //导入方法依赖的package包/类
/**
* 添加倒影
*
* @param src 源图片的
* @param reflectionHeight 倒影高度
* @param recycle 是否回收
* @return 带倒影图片
*/
public static Bitmap addReflection(final Bitmap src, final int reflectionHeight, final boolean recycle) {
if (isEmptyBitmap(src)) return null;
// 原图与倒影之间的间距
final int REFLECTION_GAP = 0;
int srcWidth = src.getWidth();
int srcHeight = src.getHeight();
Matrix matrix = new Matrix();
matrix.preScale(1, -1);
Bitmap reflectionBitmap = Bitmap.createBitmap(src, 0, srcHeight - reflectionHeight,
srcWidth, reflectionHeight, matrix, false);
Bitmap ret = Bitmap.createBitmap(srcWidth, srcHeight + reflectionHeight, src.getConfig());
Canvas canvas = new Canvas(ret);
canvas.drawBitmap(src, 0, 0, null);
canvas.drawBitmap(reflectionBitmap, 0, srcHeight + REFLECTION_GAP, null);
Paint paint = new Paint();
paint.setAntiAlias(true);
LinearGradient shader = new LinearGradient(0, srcHeight,
0, ret.getHeight() + REFLECTION_GAP,
0x70FFFFFF, 0x00FFFFFF, Shader.TileMode.MIRROR);
paint.setShader(shader);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
canvas.drawRect(0, srcHeight + REFLECTION_GAP,
srcWidth, ret.getHeight(), paint);
if (!reflectionBitmap.isRecycled()) reflectionBitmap.recycle();
if (recycle && !src.isRecycled()) src.recycle();
return ret;
}
示例9: addLogo
import android.graphics.Canvas; //导入方法依赖的package包/类
/**
* 在二维码中间添加Logo图案
*/
private static Bitmap addLogo(Bitmap src, Bitmap logo) {
if (src == null) {
return null;
}
if (logo == null) {
return src;
}
//获取图片的宽高
int srcWidth = src.getWidth();
int srcHeight = src.getHeight();
int logoWidth = logo.getWidth();
int logoHeight = logo.getHeight();
if (srcWidth == 0 || srcHeight == 0) {
return null;
}
if (logoWidth == 0 || logoHeight == 0) {
return src;
}
//logo大小为二维码整体大小的1/5
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;
e.getStackTrace();
}
return bitmap;
}
示例10: generatorBit
import android.graphics.Canvas; //导入方法依赖的package包/类
private void generatorBit() {
mDrawBit = Bitmap.createBitmap(getMeasuredWidth(), getMeasuredHeight(), Bitmap.Config
.ARGB_8888);
mDrawBit.setHasAlpha(true);
mPaintCanvas = new Canvas(mDrawBit);
if (mPendingBitmap != null) {
mPaintCanvas.drawBitmap(mPendingBitmap, mMatrix, null);
mPendingBitmap = null;
}
}
示例11: drawMaze
import android.graphics.Canvas; //导入方法依赖的package包/类
public void drawMaze(Canvas canvas){
for (int i = 0; i < mazeRow; i++){
for (int j = 0; j < mazeColumn; j++){
if (mazeArray[i][j] == 0)
canvas.drawBitmap(wall, j*blockSize, i*blockSize, null);
if (mazeArray[i][j] == 3)
canvas.drawBitmap(door, j*blockSize, i*blockSize, null);
if (mazeArray[i][j] == 1)
canvas.drawBitmap(food, j*blockSize, i*blockSize, null);
if (mazeArray[i][j] == 2)
canvas.drawBitmap(power, j*blockSize, i*blockSize, null);
}
}
}
示例12: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (isInEditMode())
return;
/*if (showClickIndication)
{
if (pressed)
{
}
else {
}
}*/
if (image == null || image.get() == null)
{
if (fromUrl)
loadFromUrl(bubbleImageUrl, loadDone, imgWidth, imgHeight);
else
loadFromPath(bubbleImageUrl, loadDone, imgWidth, imgHeight);
return;
}
if (bubbleGravity == GRAVITY_RIGHT)
{
canvas.drawBitmap(image.get(), imagePadding /2 , imagePadding /2 , null);
}
else
{
canvas.drawBitmap(image.get(), imagePadding /2 + tipSize, imagePadding /2 , null);
}
}
示例13: transform
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int width = source.getWidth();
int height = source.getHeight();
int scaledWidth = width / mSampling;
int scaledHeight = height / mSampling;
Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(bitmap);
canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
Paint paint = new Paint();
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(source, 0, 0, paint);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
try {
bitmap = RSBlur.blur(mContext, bitmap, mRadius);
} catch (RSRuntimeException e) {
bitmap = FastBlur.blur(bitmap, mRadius, true);
}
} else {
bitmap = FastBlur.blur(bitmap, mRadius, true);
}
return BitmapResource.obtain(bitmap, mBitmapPool);
}
示例14: getRoundedCroppedBitmap
import android.graphics.Canvas; //导入方法依赖的package包/类
private Bitmap getRoundedCroppedBitmap(Bitmap bitmap, int radius) {
Bitmap finalBitmap;
if (bitmap.getWidth() != radius || bitmap.getHeight() != radius) {
finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius, false);
} else {
finalBitmap = bitmap;
}
Bitmap output = Bitmap.createBitmap(finalBitmap.getWidth(),
finalBitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, finalBitmap.getWidth(),
finalBitmap.getHeight());
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(Color.parseColor("#BAB399"));
canvas.drawCircle(finalBitmap.getWidth() / 2,
finalBitmap.getHeight() / 2,
finalBitmap.getWidth() / 2, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(finalBitmap, rect, rect, paint);
return output;
}
示例15: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
if (mBitmap != null) {
updateDstRectF();
canvas.drawBitmap(mBitmap, null, mDstRectF, mPaint);
// Only draw the badge if a preview was drawn.
if (mBadge != null) {
mBadge.draw(canvas);
}
}
}