0

Good day, please I am trying to write an application that stores images I take with Camera automatically to a database. However i want to check the image size(MB) before it can save it.

I read the android Camera.Capture developer note and know I cannot adjust size programatically.

Also I am aware storing in a temporary folder before uploading to database is possible but I am looking for one that does without saving in a temp folder.

Thanks.

user1540792
  • 88
  • 1
  • 1
  • 8
  • check it, it may useful for you. http://stackoverflow.com/questions/1601455/check-file-input-size-with-jquery – Rnk Jangir Aug 07 '12 at 12:34

4 Answers4

0

getRowBytes() * getHeight() seems to be working fine to me.

Shachillies
  • 1,616
  • 14
  • 12
  • Thanks. used: (mediaFile.size)/(1024*1024) to get the size in MB and before proceeding to Update my database. – user1540792 Aug 07 '12 at 15:56
  • Hi can I actually save if the path is a URL to an image? Also, input type = file does not work in mobiles, what is the best alternative method to replace this input type? Thanks – user1540792 Aug 08 '12 at 13:02
0

Your server cannot know the size of the image unless it can look at it. You can use PHP to cap the maximum upload size. Once you have the file on the server as a temporary file, you can analyse it in more detail (dimensions, etc). If the image is "good", then move it to it's permanent location (another directory or as database BLOB), if not then just delete it.

VettelS
  • 1,204
  • 1
  • 9
  • 17
  • Hi can I actually save if the path is a URL to an image? Also, input type = file does not work in mobiles, what is the best alternative method to replace this input type? Thanks – user1540792 Aug 08 '12 at 13:03
0

In your cameras PictureCallback:

public void onPictureTaken(byte[] data, Camera camera)
{
  int nPictureSize = data.length;
}

the length of the compressed image is simply the length of the byte array

CSmith
  • 13,318
  • 3
  • 39
  • 42
  • Hi can I actually save if the path is a URL to an image? Also, input type = file does not work in mobiles, what is the best alternative method to replace this input type? Thanks – user1540792 Aug 08 '12 at 13:03
0

If you are using a custom camera then in your callback you's receive a byte array just get the length of this array and divide it by 1024*1024 to get size in MB.

If you are using the Camera intent then you get back a Bitmap whose size can be found by using bitmap.getRowbytes * bitmap.getHeight and then divide it by 1024*1024 to get image size in MB

A Random Android Dev
  • 2,691
  • 1
  • 18
  • 17
  • Thanks. used: (mediaFile.size)/(1024*1024) to get the size in MB and before proceeding to Update my database. – user1540792 Aug 07 '12 at 15:56
  • Hi can I actually save if the path is a URL to an image? Also, input type = file does not work in mobiles, what is the best alternative method to replace this input type? Thanks – user1540792 Aug 08 '12 at 13:00
  • Are you asking if you can save an image in Android from a URL that points to that image? – A Random Android Dev Aug 08 '12 at 13:14
  • Yes please. I want to grab the image at this url for example(http://nurmiababystore.com/product_images/uploaded_images/baby-names-mom-and-laughing-baby1.jpg). Thanks – user1540792 Aug 09 '12 at 03:56
  • Check out this link, it contains the best practice answer for your problems: http://stackoverflow.com/a/9288544/1512836 – A Random Android Dev Aug 09 '12 at 10:12