0
我需要在每秒15幀的速度借鑑Surfaceview位圖,我的SurfaceView是如下Canvas.drawBitmap或Canvas.drawColor不工作
public class RawVideoViewSV extends SurfaceView implements SurfaceHolder.Callback{
private boolean isSurface;
private Bitmap mBitmap;
private SurfaceHolder holder;
public RawVideoViewSV(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
holder = getHolder();
holder.addCallback(this);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
isSurface = false;
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
isSurface = true;
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
isSurface = false;
}
public SurfaceHolder getSurfaceHolder(){
return holder;
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
if(isSurface){
canvas.drawColor(Color.GREEN);
if(mBitmap != null)
canvas.drawBitmap(mBitmap, 0, 0, null);
}
}
public void doDraw(Canvas canvas,Bitmap bmp) {
// TODO Auto-generated method stub
System.out.println("RawVideoViewSV---> doDraw isSurface = " + isSurface + bmp.getHeight());
Rect source = new Rect(0, 0, bmp.getWidth(), bmp.getHeight());
if(isSurface){
canvas.drawColor(Color.GREEN);
if(bmp != null)
canvas.drawBitmap(bmp, null,source, null);
}
}}
在我的活動正在創建其正在傳遞到表面,以位圖繪製,但由於某種原因,既不canvas.drawcolor工作,也不canvas.drawbitmap在surfacview內工作。
rawVideoViewSV0 = (RawVideoViewSV) findViewById(R.id.videoRawViewSV0);
Bitmap bmpx = Bitmap.createBitmap(rgb, videoSample.getWidth(),
videoSample.getHeight(),Bitmap.Config.ARGB_8888);
Canvas mCanvas = null;
SurfaceHolder mHolder = rawVideoViewSV0.getHolder();
try {
mCanvas = mHolder.lockCanvas();
synchronized (mHolder) {
rawVideoViewSV0.doDraw(mCanvas,bmpx);
}
} finally {
if (mCanvas != null) {
mHolder.unlockCanvasAndPost(mCanvas);
}
}
rawVideoViewSV0是RawVideoViewSV類型。 我已驗證我的位圖不爲null,只有在第一次調用onDraw時,surfaceview顯示爲綠色,就是它。
請有人指出我哪裏會出錯。
你知道surfaceview將「不會繪製」標誌設置爲true嗎? ...無論你想在這裏存檔(水印在cam/file上的視頻?),你做錯了... – Selvin 2014-11-05 13:51:49
我已經知道我錯了它現在已經工作了...感謝您的快速回復.. – zenith 2014-11-06 07:10:04