Example usage for android.view SurfaceHolder lockCanvas

List of usage examples for android.view SurfaceHolder lockCanvas

Introduction

In this page you can find the example usage for android.view SurfaceHolder lockCanvas.

Prototype

public Canvas lockCanvas(Rect dirty);

Source Link

Document

Just like #lockCanvas() but allows specification of a dirty rectangle.

Usage

From source file:Main.java

public static synchronized void cleansurfaceview(SurfaceHolder postureholder, SurfaceView posturesurface) {
    Canvas canvas = postureholder
            .lockCanvas(new Rect(0, 0, posturesurface.getWidth(), posturesurface.getHeight()));
    canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
    postureholder.unlockCanvasAndPost(canvas);
    Canvas canvasa = postureholder
            .lockCanvas(new Rect(0, 0, posturesurface.getWidth(), posturesurface.getHeight()));
    canvasa.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
    postureholder.unlockCanvasAndPost(canvasa);
}

From source file:org.medcare.Dicom.DicomActivity.java

public void delDicom(SurfaceHolder surfaceHolder) {
    Log.i(TAG, "debut traitement DEL");
    curentImageController = dicomView.getCurrentImageController();
    if (curentImageController == null)
        return;// w  w w . ja v a  2 s  .  co  m
    dicomView.imageControllers.remove(curentImageController);
    int index = dicomView.imageControllers.size() - 1;
    Canvas c = null;
    try {
        if (index >= 0) {
            curentImageController = dicomView.imageControllers.get(dicomView.imageControllers.size() - 1);
            curentImageController.setChange(true);
        } else {
            curentImageController = null;
            c = surfaceHolder.lockCanvas(null);
            synchronized (surfaceHolder) {
                dicomView.clear(c);
            }
        }
    } finally {
        // do this in a finally so that if an exception is
        // thrown
        // during the above, we don't leave the Surface in an
        // inconsistent state
        if (c != null) {
            surfaceHolder.unlockCanvasAndPost(c);
        }
    }
}

From source file:com.fishstix.dosboxfree.DBGLSurfaceView.java

private void canvasDraw(Bitmap bitmap, int src_width, int src_height, int startLine, int endLine) {
    SurfaceHolder surfaceHolder = getHolder();
    Surface surface = surfaceHolder.getSurface();
    Canvas canvas = null;/*from   w  ww  . ja v  a  2 s.c  o m*/

    try {
        synchronized (surfaceHolder) {

            boolean isDirty = false;

            if (mDirtyCount < 3) {
                mDirtyCount++;
                isDirty = true;
                startLine = 0;
                endLine = src_height;
            }

            if (mScale) {
                mDstRect.set(0, 0, mRenderer.width, mRenderer.height);
                mSrcRect.set(0, 0, src_width, src_height);
                mDstRect.offset(mRenderer.x, mRenderer.y);

                mDirtyRect.set(0, startLine * mRenderer.height / src_height, mRenderer.width,
                        endLine * mRenderer.height / src_height + 1);

                //locnet, 2011-04-21, a strip on right side not updated
                mDirtyRect.offset(mRenderer.x, mRenderer.y);
            } else {
                //L,T,R,B 
                mSrcRect.set(-mScroll_x, Math.max(-mScroll_y, startLine), mRenderer.mCropWorkspace[2],
                        Math.min(Math.min(getHeight() - mScroll_y, src_height), endLine));
                mDstRect.set(0, mSrcRect.top + mScroll_y, mSrcRect.width(),
                        mSrcRect.top + mScroll_y + mSrcRect.height());
                if (isLandscape) {
                    mDstRect.offset((getWidth() - mSrcRect.width()) / 2, 0);
                } else {
                    mDstRect.offset((getWidth() - mSrcRect.width()) / 2, mActionBarHeight);
                }

                mDirtyRect.set(mDstRect);
            }
            if (surface != null && surface.isValid()) {
                if (isDirty) {
                    canvas = surfaceHolder.lockCanvas(null);
                    canvas.drawColor(0xff000000);
                } else {
                    canvas = surfaceHolder.lockCanvas(mDirtyRect);
                }

                if (mScale) {
                    canvas.drawBitmap(bitmap, mSrcRect, mDstRect,
                            (mParent.mPrefScaleFilterOn) ? mBitmapPaint : null);
                } else {
                    canvas.drawBitmap(bitmap, mSrcRect, mDstRect, null);
                }

            }
        }
    } finally {
        if (canvas != null && surface != null && surface.isValid()) {
            surfaceHolder.unlockCanvasAndPost(canvas);
        }
    }

    surfaceHolder = null;
}