我正在创建一个应用程序,以帮助盲人感觉屏幕。这个想法是,手机会根据您触摸的像素的颜色产生不同的声音。画廊图片可以正常工作,但相机图片可以崩溃。
public void onActivityResult(int requestCode, int resultCode, Intent
data){
super.onActivityResult(requestCode, resultCode, data);
if (resultCode== Activity.RESULT_OK){
if (requestCode==REQUEST_CAMERA){
Bundle bundle=data.getExtras();
final Bitmap bmp= (Bitmap) bundle.get("data");
imageView.setImageBitmap(bmp);
} else if (requestCode==SELECT_FILE){
Uri selectedImageUri=data.getData();
imageView.setImageURI(selectedImageUri);
}
}
bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
//end of image
imageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
//action down
case MotionEvent.ACTION_DOWN: {
x = (int) motionEvent.getX();
y = (int) motionEvent.getY();
pixel = bitmap.getPixel(x, y);
//here
red = (float) Color.red(pixel) / 100;
green = (float) Color.green(pixel) / 100;
blue = (float) Color.blue(pixel) / 100;
//here
mpRed.start();
mpBlue.start();
mpYellow.start();
mpRed.setVolume(red, red);
mpBlue.setVolume(blue, blue);
mpYellow.setVolume(green, green);
break;
}
//action down
case MotionEvent.ACTION_MOVE: {
x = (int) motionEvent.getX();
y = (int) motionEvent.getY();
pixel = bitmap.getPixel(x, y);
//here
red = (float) Color.red(pixel) / 100;
green = (float) Color.green(pixel) / 100;
blue = (float) Color.blue(pixel) / 100;
mpRed.setVolume(red, red);
mpBlue.setVolume(blue, blue);
mpYellow.setVolume(green, green);
break;
//here
}
case MotionEvent.ACTION_UP: {
mpRed.seekTo(0);
mpBlue.seekTo(0);
mpYellow.seekTo(0);
mpRed.pause();
mpYellow.pause();
mpBlue.pause();
return false;
}
}
return true;
}
});
}
PS:请稍等,我只是想帮助学生的语言老师,所以如果这是一个愚蠢的问题,请不要感到惊讶。