6
TextureView의 배경색을 변경하려고합니다. 이 색상은 반투명 카메라 미리보기를 통해 보일 것으로 기대됩니다. 웬일인지 그것은하지 않는다. onSurfaceTextureAvailable에서 카메라 미리보기를 모두 제거하면보기가 흰색으로 표시되거나 볼 수 없습니다. 어떤 아이디어? TextureView 상자를 만들기 위해 노력하고 있는데 때로는 카메라 미리보기가 포함되어 있고 다른 시간은 내가 선택한 보통 색상입니다. 감사. 당신이 TextureView
의 배경색이 관련이없는 것이라고 할 때,TextureView setBackgroundColor가 작동하지 않습니다.
textureView.setOpaque(false);
하지만 :
import android.graphics.Color;
import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.Surface;
import android.view.TextureView;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import java.io.IOException;
public class MainActivity extends Activity {
private TextureView mTextureView;
FrameLayout screenFrame;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
screenFrame = (FrameLayout)findViewById(R.id.screenFrame);
setVideoScreens();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private void setVideoScreens()
{
final LiveCameraActivity livecam = new LiveCameraActivity();
mTextureView = new TextureView(this);
mTextureView.setSurfaceTextureListener(livecam);
FrameLayout mainFrame = (FrameLayout)findViewById(R.id.mainFrame);
mainFrame.addView(mTextureView);
int width = 640;
int height = 480;
mTextureView.setLayoutParams(new FrameLayout.LayoutParams(
width, height));
mTextureView.setY(200);
mTextureView.setX(200);
mTextureView.setBackgroundColor(Color.BLUE);
mTextureView.setAlpha(.5f);
}
public class LiveCameraActivity extends Activity implements TextureView.SurfaceTextureListener
{
private Camera mCamera;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
}
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
{
mCamera = Camera.open();
try
{
mCamera.setPreviewTexture(surface);
mCamera.startPreview();
}
catch (IOException ioe)
{
// Something bad happened
}
}
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height)
{
// Ignored, Camera does all the work for us
}
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface)
{
mCamera.stopPreview();
mCamera.release();
return true;
}
public void onSurfaceTextureUpdated(SurfaceTexture surface)
{
// Invoked every time there's a new Camera preview frame
}
}
}
우리가 올바르게 도울 수 있도록 전체 코드를 알려주십시오. –
당신이 고칠 수 있습니까? – sandrstar
같은 문제가 발생했습니다. 어떤 해결책? – Alexis