问题描述
你好,请我想写存储我随身携带相机会自动将数据库图像的应用程序。不过,我要检查的图像大小(MB),才可以将其保存。
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.
我读了Android Camera.Capture开发商说明,并知道我不能编程调整大小。
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.
感谢。
推荐答案
如果您使用的是自定义的相机,然后以MB为单位。
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.
如果您使用的是相机的意图,那么你得到一个位图的大小可以通过使用bitmap.getRowbytes * bitmap.getHeight然后1024 * 1024除以它来获取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
这篇关于检查图像大小,才可以被保存到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!