當前位置: 首頁>>代碼示例>>Java>>正文


Java Canvas.drawBitmap方法代碼示例

本文整理匯總了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);
            }
        }
    }
 
開發者ID:jorenham,項目名稱:fingerblox,代碼行數:18,代碼來源:MainActivity.java

示例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;
}
 
開發者ID:ichason,項目名稱:PageCurl,代碼行數:29,代碼來源:CurlPage.java

示例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);
}
 
開發者ID:nidhinvv,項目名稱:BubbleAlert,代碼行數:17,代碼來源:AlertDrawable.java

示例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();
		}
	}
}
 
開發者ID:QuixomTech,項目名稱:WeatherStream,代碼行數:24,代碼來源:CustomViewBehind.java

示例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) {

    }

}
 
開發者ID:guoxiaoxing,項目名稱:android-open-source-project-analysis,代碼行數:23,代碼來源:PageView.java

示例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;
    }
}
 
開發者ID:z-chu,項目名稱:FriendBook,代碼行數:27,代碼來源:CoverPageAnim.java

示例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);
    }
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:36,代碼來源:DrawerProfileCell.java

示例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;
}
 
開發者ID:Wilshion,項目名稱:HeadlineNews,代碼行數:36,代碼來源:ImageUtils.java

示例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;
}
 
開發者ID:joelan,項目名稱:ClouldReader,代碼行數:45,代碼來源:QRCodeUtil.java

示例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;
    }
}
 
開發者ID:viseator,項目名稱:MontageCam,代碼行數:11,代碼來源:HollowView.java

示例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);
		}
	}
}
 
開發者ID:StringMon,項目名稱:homescreenarcade,代碼行數:15,代碼來源:GameSurfaceView.java

示例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);
    }
}
 
開發者ID:MobileDev418,項目名稱:chat-sdk-android-push-firebase,代碼行數:35,代碼來源:ChatBubbleImageView.java

示例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);
}
 
開發者ID:open-android,項目名稱:Glide-transformations,代碼行數:33,代碼來源:BlurTransformation.java

示例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;
}
 
開發者ID:MindorksOpenSource,項目名稱:android-mvp-architecture,代碼行數:31,代碼來源:RoundedImageView.java

示例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);
        }
    }
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:13,代碼來源:WidgetImageView.java


注:本文中的android.graphics.Canvas.drawBitmap方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。