Toby Toby - 1 year ago 58
Android Question

Image Saved From Android Studio Application is Very Small

This activity takes 3 pictures from the back camera and saves them in the phones internal storage. They can later be accessed for testing. The app actually does work, but the problem is that the images saved are very small, they are only like 20KB when taken from a cell phone. (This is not the phones capabilities, they phone takes normal sized pictures when taken with the phones camera from the factory camera app.)

I think it must be the way I am saving the image, but I have not been able to find any other way to do this that changes this problem. I have included the relevant code, the XML file is very spare and contains simply a picView.

There is also a bug that seems to cause the activity to crash when the physical phone itself is moved around a lot when the activity is working. I am at a loss as to why this would be as well. I thought maybe it had to do with the phone orientation, but when I lock the screen orientation, it still crashes if the phone is moved too much while testing.

Answer Source

I am a very new developer and I have been stuck on this problem for days

Somewhere in those days, you should have read a book on Android app development, one that has a chapter on taking pictures with the camera. Overall, using the camera APIs in very difficult and is not something that I would recommend for a "very new developer".

but the problem is that the images saved are very small, they are only like 20KB when taken from a cell phone

You do not seem to be setting the picture resolution. What size you get will depend on hardware, whatever it chose as the default. Perhaps your test device chose a small size as its default.

How would I go about setting a picture resolution?

Step #1: After you get your Camera object, fill in your parameters field using the result of calling getParameters() on the Camera

Step #2: Call getSupportedPictureSizes() on the Camera.Parameters object, to find out what picture resolutions ("sizes") the camera hardware supports

Step #3: Choose one of those sizes, by whatever algorithm you want (e.g., largest by area

Step #4: Call setPictureSize() on the Camera.Parameters object, supplying the size that you chose from Step #3

Step #5: Call setParameters() on the Camera, passing in your Camera.Parameters object

private void configureCamera(Camera camera) {
    Camera.Parameters params = camera.getParameters();
    List<Size> sizes = params.getSupportedPictureSizes();
    Camera.Size size = // insert your algorithm here

    params.setPictureSize(size.width, size.height);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download