1

Possible Duplicate:
Android : Bitmap save to location

I have successfully created a QR code generator application but cannot save the generated image to a external storage. I have tried various practices but failed to do so. Following is the class where the image generated is showed on the screen and then i have to use a button called save button to store the image but i cannot get it done. Can someone please help me to sort out this. Will be very thankful for your efforts in helping me. cheers

     public class QRDisplay extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.qr_view);

    String url = getIntent().getStringExtra("IMAGE_URL");

    ImageView imageView = (ImageView)findViewById(R.id.qr_image);
    try {
        URL imageURL = new URL(url);
        Bitmap qrBitmap = BitmapFactory.decodeStream(imageURL.openStream());
        imageView.setImageBitmap(qrBitmap);
    } catch (Exception e) {
        Log.d("QRDisplay", e.getMessage());
    }


Button saveButton= (Button)findViewById(R.id.saveButton);
saveButton.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
    ?????????????????   
    }
});

}

}

Community
  • 1
  • 1
abhijeet
  • 13
  • 1
  • 3

1 Answers1

1

hey abhijeet use this it definately solve your problem

String Filepath = Environment.getExternalStorageDirectory().toString();
OutputStream Out = null;
File file = new File(path, "yourimagename"+".jpg");
Out = new FileOutputStream(file);

getImageBitmap(myurl).compress(Bitmap.CompressFormat.JPEG, 85, fOut);
Out.flush();
Out.close();

MediaStore.Images.Media.insertImage(getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());

also put these code into ur maifest file to add permission -

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
juan
  • 80,295
  • 52
  • 162
  • 195
itechDroid
  • 1,031
  • 1
  • 11
  • 17