What am I doing wrong?

NJDude

Expert
Licensed User
Longtime User
This is the situation, I'm working on a routine to take pictures (camera) and I'm using the "CameraPortrait 1.10" library since it allows the camera to "work" in portrait mode, however, when you take a picture the image is rotated 90 degrees, so, I'm attemping to write a routine that will rotate it 90 degrees and save it.

The code below is the one to snap the picture, it works without a problem (this code is the sample code posted on the tutorial)

B4X:
Sub Camera1_PictureTaken (Data() As Byte)
            
    Dim Out As OutputStream

    Out = File.OpenOutput(File.DirRootExternal, "/media/Snapshot.jpg", False)
    Out.WriteBytes(Data, 0, Data.Length)
    Out.Close

End Sub


This following code is my attempt to rotate it and save it, but, it works sometimes, when it fails the phone force closes the app.

B4X:
Sub FlipButton_Click

    Dim Out As OutputStream
    Dim Canvas1 As Canvas
    Dim Bitmap1 As Bitmap
    Dim DestRect As Rect
            
    Canvas1.Initialize(PicTaken)  ' <---- PicTaken is an ImageView on my layout

    Bitmap1.Initialize(File.DirRootExternal, "/media/Snapshot.jpg")
            
    DestRect.Initialize(0dip, 0dip, 320dip, 320dip)
            
    Canvas1.DrawBitmapRotated(Bitmap1, Null, DestRect, 90)   
            
    Out = File.OpenOutput(File.DirRootExternal, "/media/Snapshot.jpg", False)
    Canvas1.Bitmap.WriteToStream(Out, 75, "JPEG")
    Out.Close
   
End Sub

I know I'm doing something wrong but I can't figure out what since I'm still green on B4A.

Thanks
 
Last edited:

NJDude

Expert
Licensed User
Longtime User
hi Klaus,

I did what you suggested and this is what I get at compiling time:

B4X:
Compiling code.                         Error
Error compiling program.
Error description: Unknown member: writetostream
Occurred on line: 151
PicTaken.Bitmap.WriteToStream(Out, 75, "JPEG")
Word: writetostream
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Erel,

The error seems to be "Null pointer error" this is a portion of the error log

B4X:
main_camera1_picturetaken (java line: 224)
java.lang.NullPointerException
   at com.CameraTest.main._camera1_picturetaken(main.java:224)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:521)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:99)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:89)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:85)
   at anywheresoftware.b4a.objects.CamRotate$3.onPictureTaken(CamRotate.java:143)
   at android.hardware.Camera$EventHandler.handleMessage(Camera.java:328)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:144)
   at android.app.ActivityThread.main(ActivityThread.java:4937)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:521)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
   at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException

It occurs regarless of changing the name of the file to be saved.
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Ok here it is.

To use it, AFTER a picture is taken the SEND button needs to be tapped (this is to isolate the rotating routine) you will see that maybe the 1st rotation works, the second will fail displaying an error.

Thanks
 

Attachments

  • CameraTest.zip
    11.7 KB · Views: 322
Upvote 0
Top