Advanced Camera Orientation Problem

Jack Cole

Well-Known Member
Licensed User
Longtime User
I am using the Advanced Camera library 8, and am having a problem.

I have the mode set to oriportrait, and the preview for this works fine. When taking a picture, it is saved in landscape orientation. Please see the attached example program. Take a picture and it will be loaded into one of the two panels below the preview panel. I want the picture to be saved in portrait orientation if possible.

Any ideas would be appreciated.
 

Attachments

  • camtest.zip
    6.8 KB · Views: 387

Jack Cole

Well-Known Member
Licensed User
Longtime User
The JPEG library chokes with pictures taken on my phone, and I'm concerned that it would do that on other phones as well.

I was finally able to work out a solution, although not ideal. My camera is an 8 megapixel, so I have to scale down the image before rotating it. Otherwise, I get a forced close because of running out of memory. Any ideas on how to get around that would be appreciated. Here is my final working code for rotating the image.

B4X:
Sub save_and_rotate(dir,fn)
    Dim Out As OutputStream
    Dim Canvas1 As Canvas
    Dim Bitmap1 As Bitmap
    Dim bitmap2 As Bitmap
    Dim DestRect As Rect
    Bitmap1.Initializesample(dir,fn,1500,1150)   
    bitmap2.InitializeMutable(1500,1150)

    Canvas1.Initialize2(bitmap2)

    DestRect.Initialize(0dip, 0dip, bitmap1.width, bitmap1.Width)
    Canvas1.DrawBitmapRotated(Bitmap1, Null, destrect, 90)
    
    Out = File.OpenOutput(dir, fn, False)
    Canvas1.Bitmap.WriteToStream(Out, 100, "JPEG")
    Out.Close
    ToastMessageShow("Image saved: " & File.Combine(dir, fn), True)
End Sub
 
Upvote 0

Jack Cole

Well-Known Member
Licensed User
Longtime User
Thanks vb1992,

I didn't know that existed (which prompted me to update to the ACL library). However, it causes the same problem (forced close). I suppose I can live with the 1.7 mpix max for my app. It would be nice to have the full pic size.
 
Upvote 0

Jack Cole

Well-Known Member
Licensed User
Longtime User
Debugger doesn't get it, but the unfiltered log does.

B4X:
FATAL EXCEPTION: main
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
   at android.graphics.Bitmap.nativeCreate(Native Method)
   at android.graphics.Bitmap.createBitmap(Bitmap.java:507)
   at android.graphics.Bitmap.createBitmap(Bitmap.java:474)
   at xvs.ACL.ACL$5.onPictureTaken(ACL.java:306)
   at android.hardware.Camera$EventHandler.handleMessage(Camera.java:542)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:130)
   at android.app.ActivityThread.main(ActivityThread.java:3806)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:507)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
   at dalvik.system.NativeStart.main(Native Method)
  Force finishing activity en.things.io.advancedcamera/.main

This is the same problem as when I try the code for rotating the bitmap on the full image. When I scale it down, it works without taking up too much memory. 1500x1150 is about the highest res I can get, whereas my phone will take pics at 3264x2248.
 
Upvote 0

MikieK

Member
Licensed User
Longtime User
Processing the image after taking it, just consumes battery. Have a look at the Jpeg Utils library which should enable you to tell your phones media gallery which way up to show the image without losing any of the information from the original image.
 
Upvote 0

Jack Cole

Well-Known Member
Licensed User
Longtime User
Thanks vb1992 for your work on this. It pops up twice with the value of 32768 (I assume that's KB based on the code). After taking the pic, I get the same force close and error with out of VM.

I guess I can just reorient my layout to be landscape and take the pic that way. I have a form that has other data to be filled in, and it flows better in portrait mode. But I can adapt it to landscape, and switch the camera orientation to landscape as well. Not ideal, but I think I can trust it to work on nearly all phones that way.
 
Upvote 0

vb1992

Well-Known Member
Licensed User
Longtime User
Camera: 3.2 megapixel
Internal Memory: 2GB
1GHz Processor

Mine came up with 49152 maxheap
and then 644.30 freemem

Saves fine, but takes about 8 seconds
to save (and rotate)

The photo size on disk is 2.4 MB
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…