0

I have two problems in my program: 1.After taking a picture, this is what I have for onActivityResult():

        pictureTaken = (Bitmap) data.getExtras().get("data");
        ImageView im = (ImageView) findViewById(R.id.view);
        im.setImageBitmap(pictureTaken);

This displays only a thumbnail (bad quality when displayed), and when I save it to the SD card, it is also a small image. What I need is to save/display it in it's full resolution/quality. What do I change to achieve this?

  1. Retrieving and displaying the image selected by the user works:

    selectedImage = data.getData();
    ImageView im = (ImageView) findViewById(R.id.view);
    im.setImageURI(selectedImage);
    

But when saving the image the user picked, it crashes here (found by debugger):

...
File externalStorageFile = new File(dir, finalName);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
//Error
resourceImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
byte b[] = bytes.toByteArray();
try {
...

Also, is bitmap the only way you can save images in Android?

Manuel Allenspach
  • 12,467
  • 14
  • 54
  • 76
Mark
  • 700
  • 2
  • 7
  • 17

2 Answers2

0

For saving the image in sdcard use the below code

    String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
    File file = new File(extStorageDirectory, imagename);
    file.createNewFile();
    FileOutputStream fos = new  FileOutputStream(file);
    bm.compress(CompressFormat.JPEG, 75, fos);
    fos.flush();
    fos.close();
Ramakrishna
  • 4,066
  • 16
  • 48
  • 72
  • This part I have, the saving works fine, it just that the 5mp camera is returning a 80X80 photo with my code. Am I not "getting data" the right way? – Mark Jun 22 '11 at 13:23
0

Check this Links for Sample. If the Selected images from Gallery shows Bitmap out of range exception you need to Decode image.

Scale Image to screen Size....

Picking Image from gallery and Decode it.......

Community
  • 1
  • 1
Venky
  • 11,049
  • 5
  • 49
  • 66
  • I'm getting a nullPointerException... found where too! It's when trying to decode – Mark Jun 22 '11 at 13:54
  • Bitmap bImage = BitmapFactory.decodeFile(selectedImage.getPath()); – Mark Jun 22 '11 at 13:55
  • Yea! Thanks for the second link, it helped me with the decoding error. As for the 1st problem, I still need to read the link more thoroughly and see what I can find. Also, since my app is honeycomb optimized, what should I set the bitmap too (bImage = Bitmap.createScaledBitmap(bImage, 500, 500, true);)? 500 seems ok, but if they want to transfer the photo to their computer, shouldn't I use the same/similar size as the "gallery" app does? – Mark Jun 22 '11 at 17:44
  • Thank YOU for helping at least get one step closer to finish my app! – Mark Jun 23 '11 at 08:32