我想将相机预览更改为灰度效果。如何做到这一点?我正在尝试,但无法从以下代码中获得任何输出:
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
if (resultCode == RESULT_OK) {
Uri selectedImage = imageReturnedIntent.getData();
basefile = preview.file;
getRealPathFromURI(selectedImage);
try {
loadBaseImage(getBitmapFromURI(selectedImage));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
preview.startCamera();
} catch (Exception e) {
toast("Ops!" + e.getMessage());
e.printStackTrace();
}
}
private void loadBaseImage(Bitmap bmp ) {
try {
photoBase.setBitmap(bmp);
photoBase.selectedPicture();
} catch (Exception e) {
toast("Ops!" + e.getMessage());
e.printStackTrace();
}
}
public Bitmap getBitmapFromString(String src)
throws FileNotFoundException {
Uri uri = Uri.fromFile(new File(src));
return getBitmapFromURI(uri);
}
public Bitmap getBitmapFromURI(Uri uri )
throws FileNotFoundException {
InputStream imageStream = getContentResolver().openInputStream(uri);
Bitmap bmp = BitmapFactory.decodeStream(imageStream);
return bmp;
}
public Toast getToast(String dados, int duration) {
return Toast.makeText(this, dados, duration);
}
public void toast(String dados) {
final Toast t = getToast(dados, Toast.LENGTH_LONG);
t.setGravity(Gravity.CENTER, 0, 0);
t.show();
}
private void setFullBrightness() {
WindowManager.LayoutParams layout = getWindow().getAttributes();
layout.screenBrightness = 1F;
getWindow().setAttributes(layout);
}
private String getSdcardCameraOverlay() {
return PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("camera_overlay_directory", "/sdcard/CameraOverlay/");
}
}