Android how to restrict user to upload a image less than 2MB
In my android application i am uploading a image but if the size is greater than 2MB it crashes. Anybody having the solution to stop the user to upload the image greater than 2MB
Thanx开发者_JS百科 in advance....
I'm not sure what you expect from a general question like that without any specifics, but a general question gets a general answer:
- Check image size. Depending on the format you can use the correct API for that.
- Compare image size to 2MB.
- Restrict if size is too large.
I also got these "out of memory" issue when I worked on images. But I problem is that the image dimemsion is to big. I post my solution for it, hope it can help u out.
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize=0.5;
BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
精彩评论