目前我正在使用 android 上的相机。
还有我的问题:
我的正常布局 http://img19.imageshack.us/img19/2402/screenshot2013050622260.jpg
当我将 TextureView.getBitmap() 转移到 ImageView 时,左下角的所有屏幕 apiers 的反射有多小。我不需要那个!
编辑 http://img834.imageshack.us/img834/4734/screenshot2013050622263.jpg
主要的.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextureView
android:id="@+id/textureView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>
MyCameraActivity.java
package lt.mk.mycam2;
import java.io.IOException;
import lt.mk.mycam2.SocketStringClient.SocketListener;
import android.app.Activity;
import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.hardware.Camera.Size;
import android.os.Bundle;
import android.view.TextureView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
public class MyCameraActivity extends Activity implements TextureView.SurfaceTextureListener {
private Camera mCamera;
private TextureView mTextureView;
private ImageView mImageView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mImageView = (ImageView) findViewById(R.id.imageView1);
mTextureView = (TextureView) findViewById(R.id.textureView1);
mTextureView.setSurfaceTextureListener(this);
}
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
mCamera = Camera.open(1);
try {
mCamera.setPreviewTexture(surface);
Size size = mCamera.getParameters().getPreviewSize();
mTextureView.setLayoutParams(new LayoutParams(size.width, size.height));
mCamera.startPreview();
} catch (IOException ioe) {}
}
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {}
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
mCamera.stopPreview();
mCamera.release();
return true;
}
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
// if i comment following line everything looks OK, like in first image
mImageView.setImageBitmap(mTextureView.getBitmap());
}
}
那么为什么会出现这种反射,以及如何让它消失呢?
编辑 2
解决了
我不知道为什么,但是当我包围时,它运行得很顺利:
mImageView.setImageBitmap(mTextureView.getBitmap());
与处理程序:
new Handler().post(new Runnable() {
public void run() {
mImageView.setImageBitmap(mTextureView.getBitmap());
}
});
不知何故,处理程序已经处理了这个问题:)