Hala buen dia, que ver si me pueden ayudar con este problema que tengo, tenga que hacer una escala de grises a una imagen, y tengo que programar cada boton, el problema es que todas las acciones de los botones se ponen en uno solo.
este es mi codigo java:
public class MainActivity extends ActionBarActivity {
private String APP_DIRECTORY = "myPictureApp/";
private String MEDIA_DIRECTORY = APP_DIRECTORY + "media";
private String TEMPORAL_PICTURE_NAME = "tempral.jpg";
private final int PHOTO_CODE = 100;
private final int SELECT_PICTURE = 200;
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.imageView);
Button button = (Button) findViewById(R.id.Cam);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final CharSequence[] options = {"Tomar Foto", "Elegir Galeria", "Cancelar"};
final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Foto Capturada");
builder.setItems(options, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (options[which] == "Cam") {
openCamera();
} else if (options[which] == "Elegir Galeria") {
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, "Selecciona App de la imagen"), SELECT_PICTURE);
} else if (options[which] == "Candelar") {
dialog.dismiss();
}
}
});
builder.show();
}
});
}
private void openCamera(){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent,PHOTO_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode){
case PHOTO_CODE:
if (resultCode == RESULT_OK){
Bundle ext = data.getExtras();
imageView.setImageBitmap((Bitmap)ext.get("data"));
//Original = (Bitmap)ext.get("data");
}
break;
case SELECT_PICTURE:
if (resultCode == RESULT_OK){
Uri path= data.getData();
imageView.setImageURI(path);
}
break;
}
}
private void decodeBitmap(String dir){
Bitmap bitmap;
bitmap = BitmapFactory.decodeFile(dir);
imageView.setImageBitmap(bitmap);
}
}
y tengo este otro codigo pero no se donde ponerlo:
//Bitmap bmp = (Bitmap)ext.get("data");
//Bitmap objmut = Bitmap.createBitmap(bmp);
//for (int i=0;i<=bmp.getWidth();i++){
//for (int j=0;j<=bmp.getHeight();j++){
//int color = wolverine.getpixel(i, j);
//int cA = Color.alpha(color);
//int cB = Color.blue(color);
//int cG = Color.green(color);
//int cR = Color.red(color);
//int media = (cA+cG+cR)/3;
//objmut.setPixel(i, j, color);
//}
//}