本文整理匯總了Java中android.view.Surface.unlockCanvasAndPost方法的典型用法代碼示例。如果您正苦於以下問題:Java Surface.unlockCanvasAndPost方法的具體用法?Java Surface.unlockCanvasAndPost怎麽用?Java Surface.unlockCanvasAndPost使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.view.Surface
的用法示例。
在下文中一共展示了Surface.unlockCanvasAndPost方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: drawCircleSurface
import android.view.Surface; //導入方法依賴的package包/類
/**
* Clears the surface, then draws a filled circle with a shadow.
* <p>
* The Canvas drawing we're doing may not be fully implemented for hardware-accelerated
* renderers (shadow layers only supported for text). However, Surface#lockCanvas()
* currently only returns an unaccelerated Canvas, so it all comes out looking fine.
*/
private void drawCircleSurface(Surface surface, int x, int y, int radius) {
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.WHITE);
paint.setStyle(Paint.Style.FILL);
paint.setShadowLayer(radius / 4 + 1, 0, 0, Color.RED);
Canvas canvas = surface.lockCanvas(null);
try {
Log.v(TAG, "drawCircleSurface: isHwAcc=" + canvas.isHardwareAccelerated());
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
canvas.drawCircle(x, y, radius, paint);
} finally {
surface.unlockCanvasAndPost(canvas);
}
}
示例2: initGLComponents
import android.view.Surface; //導入方法依賴的package包/類
@Override
protected synchronized void initGLComponents()
{
if (mEffect != null) {
mEffect.initGLComponents();
int videoTexture = mEffect.getVideoTexture();
mVideoSurfaceTexture = new SurfaceTexture(videoTexture);
mVideoSurfaceTexture.setOnFrameAvailableListener(this);
int uiTexture = mEffect.getUIOverlayTexture();
mUISurfaceTexture = new SurfaceTexture(uiTexture);
mUISurfaceTexture.setDefaultBufferSize(mViewWidth, mViewHeight);
mUISurface = new Surface(mUISurfaceTexture);
try {
Canvas c = mUISurface.lockCanvas(null);
c.drawColor(0x0);
mUISurface.unlockCanvasAndPost(c);
} catch (Exception e) { }
}
notifyInit();
}
示例3: drawBouncingCircle
import android.view.Surface; //導入方法依賴的package包/類
/**
* Clears the surface, then draws a filled circle with a shadow.
* <p>
* Similar to drawCircleSurface(), but the position changes based on the value of "i".
*/
private void drawBouncingCircle(Surface surface, int i) {
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.WHITE);
paint.setStyle(Paint.Style.FILL);
Canvas canvas = surface.lockCanvas(null);
try {
Trace.beginSection("drawBouncingCircle");
Trace.beginSection("drawColor");
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
Trace.endSection(); // drawColor
int width = canvas.getWidth();
int height = canvas.getHeight();
int radius, x, y;
if (width < height) {
// portrait
radius = width / 4;
x = width / 4 + ((width / 2 * i) / BOUNCE_STEPS);
y = height * 3 / 4;
} else {
// landscape
radius = height / 4;
x = width * 3 / 4;
y = height / 4 + ((height / 2 * i) / BOUNCE_STEPS);
}
paint.setShadowLayer(radius / 4 + 1, 0, 0, Color.RED);
canvas.drawCircle(x, y, radius, paint);
Trace.endSection(); // drawBouncingCircle
} finally {
surface.unlockCanvasAndPost(canvas);
}
}
示例4: drawColorBars
import android.view.Surface; //導入方法依賴的package包/類
/**
* Draw color bars with text labels.
*/
private void drawColorBars(Surface surface) {
Canvas canvas = surface.lockCanvas(null);
try {
// TODO: if the device is in portrait, draw the color bars horizontally. Right
// now this only looks good in landscape.
int width = canvas.getWidth();
int height = canvas.getHeight();
int least = Math.min(width, height);
Log.d(TAG, "Drawing color bars at " + width + "x" + height);
Paint textPaint = new Paint();
Typeface typeface = Typeface.defaultFromStyle(Typeface.NORMAL);
textPaint.setTypeface(typeface);
textPaint.setTextSize(least / 20);
textPaint.setAntiAlias(true);
Paint rectPaint = new Paint();
for (int i = 0; i < 8; i++) {
int color = 0xff000000;
if ((i & 0x01) != 0) {
color |= 0x00ff0000;
}
if ((i & 0x02) != 0) {
color |= 0x0000ff00;
}
if ((i & 0x04) != 0) {
color |= 0x000000ff;
}
rectPaint.setColor(color);
float sliceWidth = width / 8;
canvas.drawRect(sliceWidth * i, 0, sliceWidth * (i+1), height, rectPaint);
}
rectPaint.setColor(0x80808080); // ARGB 50/50 grey (non-premul)
float sliceHeight = height / 8;
int posn = 6;
canvas.drawRect(0, sliceHeight * posn, width, sliceHeight * (posn+1), rectPaint);
// Draw the labels last so they're on top of everything.
for (int i = 0; i < 8; i++) {
drawOutlineText(canvas, textPaint, COLOR_NAMES[i],
(width / 8) * i + 4, (height / 8) * ((i & 1) + 1));
}
} finally {
surface.unlockCanvasAndPost(canvas);
}
}