testButton.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v)
{
imageView.setImageB
bm.compress(CompressFormat.JPEG, 100, fos);
remove this line
Solved, This is how i achieved to save image from ImageView
/*Variable which holds Image*/
{ImageView ivBanner = "Initialise It :)";
FileOutputStream fileOutputStream = openFileOutput("ImageName" + ".jpg", MODE_PRIVATE);
Bitmap bitmap = convertToBitMap(ivBanner.getDrawable(),ivBanner.getWidth(),ivBanner.getHeight());
bitmap.compress(Bitmap.CompressFormat.JPEG, 85, fileOutputStream);
File file = getFileStreamPath("ImageName" + ".jpg");
File f = file.getAbsoluteFile();
/*Utilise your path whatever way you want*/
String localPath = f.getAbsolutePath();}
/* Covert Drawable to Bitmap*/
private Bitmap convertToBitMap(Drawable drawable, int width, int height) {
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0,0,width,height);
drawable.draw(canvas);
return bitmap;
}
Try this code :
BitmapDrawable btmpDr = (BitmapDrawable) ivPic.getDrawable();
Bitmap bmp = btmpDr.getBitmap();
/*File sdCardDirectory = Environment.getExternalStorageDirectory();*/
try
{
File sdCardDirectory = new File(Environment.getExternalStorageDirectory() + File.separator + "MeeguImages");
sdCardDirectory.mkdirs();
imageNameForSDCard = "image_" + String.valueOf(random.nextInt(1000)) + System.currentTimeMillis() + ".jpg";
File image = new File(sdCardDirectory, imageNameForSDCard);
FileOutputStream outStream;
outStream = new FileOutputStream(image);
bmp.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
/* 100 to keep full quality of the image */
outStream.flush();
outStream.close();
//Refreshing SD card
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
}
catch (Exception e)
{
e.printStackTrace();
Toast.makeText(ViewImage.this, "Image could not be saved : Please ensure you have SD card installed " +
"properly", Toast.LENGTH_LONG).show();
}