イメージビューにカメラのプレビューを表示しています。imageview の位置にあるピクセルの値を知りたいのですが、アプリケーションをインストールできず、Android Phone で停止しています。私のコード:
public class MainActivity extends Activity {
private CameraPreview camPreview;
private ImageView MyCameraPreview = null;
private FrameLayout mainLayout;
private TextView colorRGB;
private static int PreviewSizeWidth = 640;
private int PreviewSizeHeight = 480;
//private Bitmap bitmap;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MyCameraPreview = new ImageView(this);
SurfaceView camView = new SurfaceView(this);
SurfaceHolder camHolder = camView.getHolder();
camPreview = new CameraPreview(PreviewSizeWidth, PreviewSizeHeight, MyCameraPreview);
camHolder.addCallback(camPreview);
mainLayout = (FrameLayout) findViewById(R.id.framelayout1);
mainLayout.addView(camView, new LayoutParams(PreviewSizeWidth, PreviewSizeHeight));
mainLayout.addView(MyCameraPreview,new LayoutParams(PreviewSizeWidth, PreviewSizeHeight));
colorRGB=(TextView)findViewById(R.id.textView1);
float Ex=48;
float Ey=28;
float[] eventXY = new float[]{Ex,Ey};
Matrix invertMatrix = new Matrix();
MyCameraPreview.getImageMatrix().invert(invertMatrix);
invertMatrix.mapPoints(eventXY);
int x=Integer.valueOf((int)eventXY[0]);
int y=Integer.valueOf((int)eventXY[1]);
Drawable imgDrawable = MyCameraPreview.getDrawable();
Bitmap bitmap = ((BitmapDrawable) imgDrawable).getBitmap();
int getRGB = bitmap.getPixel(x, y);
colorRGB.setText(Integer.toHexString(getRGB));
}
エラー ログ レポート:
06-05 19:07:59.610: E/AndroidRuntime(6665): 原因: java.lang.NullPointerException 06-05 19:07:59.610: E/AndroidRuntime(6665): com.proyek.androsign2.MainActivity.onCreate で(MainActivity.java:73) 06-05 19:07:59.610: E/AndroidRuntime(6665): android.app.Activity.performCreate(Activity.java:4465) 06-05 19:07:59.610: E/AndroidRuntime (6665): android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 06-05 19:07:59.610: E/AndroidRuntime(6665): android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931) で
ありがとう