本文整理汇总了Java中android.view.Surface.lockCanvas方法的典型用法代码示例。如果您正苦于以下问题:Java Surface.lockCanvas方法的具体用法?Java Surface.lockCanvas怎么用?Java Surface.lockCanvas使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.Surface
的用法示例。
在下文中一共展示了Surface.lockCanvas方法的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);
}
}