1

I am dynamically adding Image & Text views to a captured photo. Below is my code to save the photo after adding views to it. Captured photo size is 1.3MB (photo is taken by 3MP camera) but saved photo size is just 50KB. How would I increase the resultant file size to get max resolution?

    photoLayout.setDrawingCacheEnabled(true);

    Bitmap b = Bitmap.createBitmap(photoLayout.getDrawingCache());       

    photoLayout.setDrawingCacheEnabled(false);    

    FileOutputStream fos = new FileOutputStream(path);
    b.compress(CompressFormat.PNG, 100, fos);
    fos.close();
Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
Santhosh
  • 4,956
  • 12
  • 62
  • 90

3 Answers3

0

Converting from Bitmap format to PNG format will reduce the file size. See if you have the required resolution for your output image. Bitmap format is a un compressed format that stores information about each single pixel of an image.

midhunhk
  • 5,560
  • 7
  • 52
  • 83
0

this may be useful: How to make Bitmap compress without change the bitmap size?

Community
  • 1
  • 1
user1351659
  • 54
  • 1
  • 9
0

If your file has only 50k, check the source bitmap - you may work with image thumbnail instead of original image. If you load a big file and you don't resize it, there is no reason to get a such small file. The file size should be similar with the original.

Can you post the code that loads the bitmap? I'm almost sure you load the thumbnail!

edit: To get a photo from the camera: Capture Image from Camera and Display in Activity

Community
  • 1
  • 1
Zelter Ady
  • 6,266
  • 12
  • 48
  • 75
  • On returning from camera app, i'am creating a bitmap of captured photo and arranging the photo as background image of my screen. And then i'am adding Text/Image views to it. Now i need to capture the resultant photo. so i created a bitmap from background view layout in which i have my photo and added views. But the file size is too small – Santhosh Jul 10 '12 at 06:45
  • I can suggest you to check the image you load like this: put a breakpoint in the line you load the image and run line by line the code. After you execute the line that loads the image check the bitmap width and height. If you get a small size.... there is the issue! – Zelter Ady Jul 10 '12 at 06:53
  • To get an image from camera intent you should use something like this: Bitmap photo = (Bitmap) data.getExtras().get("data"); in your onActivityResult method. See an example here: http://stackoverflow.com/questions/5991319/capture-image-from-camera-and-display-in-activity – Zelter Ady Jul 10 '12 at 06:55
  • Invoking Camera .... Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(clickedPhotoPath))); startActivityForResult(i, CAPTURE_PHOTO_CONSTANT); And inside onActivityresult... photoBitmap = BitmapFactory.decodeFile(clickedPhotoPath) ; – Santhosh Jul 10 '12 at 07:02
  • What do you have in clickedPhotoPath? Is this a full path to a full image or the path to a thumbnail image? Post here the clickedPhotoPath value. – Zelter Ady Jul 10 '12 at 07:03
  • String clickedPhotoPath = "/sdcard/My_Direc/photo_"+System.currentTimeInMillis()+".png"; – Santhosh Jul 10 '12 at 07:05
  • but /sdcard/My_Direc/photo_timestamp.png is not a camera capture, is a photo you added there. What is the size of that file? – Zelter Ady Jul 10 '12 at 07:07
  • I added a link to a discussion about how to capture an image from camera. Should be simple. In your example, why do you use an saved image instead to use the direct image from the camera? – Zelter Ady Jul 10 '12 at 07:10
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/13649/discussion-between-santhosh-and-zelter-ady) – Santhosh Jul 10 '12 at 07:11