Call this out of your if condition:
Intent intentPhoto = new Intent(MainActivity.this, SecondActivity.class);
intentPhoto.putExtra("image",byteArray);
startActivity(intentPhoto);
Try this:
try {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
String fullPath = Environment.getExternalStorageDirectory()
.getAbsolutePath();
try {
File dir = new File(fullPath);
if (!dir.exists()) {
dir.mkdirs();
}
OutputStream fOut = null;
File file = new File(fullPath, "userImage" + ".png");
if (file.exists())
file.delete();
file.createNewFile();
fOut = new FileOutputStream(file);
fOut.flush();
fOut.close();
Log.v("Image saved", "in" + file);
} catch (Exception e) {
Log.e("saveToExternalStorage()", e.getMessage());
}
decodeFile(picturePath);
/*
* iv_display.setImageBitmap(mPhoto); Bitmap useThisBitmap =
* Bitmap.createScaledBitmap(mPhoto, mPhoto.getWidth(),
* mPhoto.getHeight(), true);
*/
ByteArrayOutputStream baos = new ByteArrayOutputStream();
myBitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
bytepicture = baos.toByteArray();
Intent newdata = new Intent(MainMenu.this, SecondActivity.class);
newdata.putExtra("picture", bytepicture);
startActivity(newdata);
} catch (Exception e) {
// TODO: handle exception
Log.v("TAG", "No Image Selected:");
}
For decode file :
public void decodeFile(String filePath) {
// Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, o);
// The new size we want to scale to
final int REQUIRED_SIZE = 1024;
// Find the correct scale value. It should be the power of 2.
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 3;
while (true) {
if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE)
break;
width_tmp /= 2;
height_tmp /= 2;
scale *= 2;
}
// Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
mPhoto = BitmapFactory.decodeFile(filePath, o2);
myBitmap = ExifUtils.rotateBitmap(filePath, mPhoto);
// image.setImageBitmap(bitmap);
}