Android Question Rotate camera taken picture

omidaghakhani1368

Well-Known Member
Licensed User
Longtime User
Hi.
Excuse me for duplicate post.
But i cannot rotate bitmap with all of rotate code in forum.
I take picture from camera but when save it,picture is rotated.
I try to rotate picture with below code but it get error
Is there any way to adjust camera orienation or rotate bitmap?

B4X:
Sub RotateImage(original As Bitmap, degree As Float) As Bitmap
   Dim matrix As JavaObject
   matrix.InitializeNewInstance("android.graphics.Matrix", Null)
   matrix.RunMethod("postRotate", Array(degree))
   Dim bmp As JavaObject
   bmp.InitializeStatic("android.graphics.Bitmap")
   Dim NewImage As Bitmap = bmp.RunMethod("createBitmap", Array(original, 0, 0, original.Width, original.Height, _
     matrix, True))
   Return NewImage
End Sub

Sub camera_PictureTaken (Data() As Byte)
exCam.SavePictureToFile(Data,File.DirInternalCache,"temp.png")
pnlcamera.Bitmap = RotateImage(LoadBitmap(File.DirInternalCache,"temp.png"),90)
End Sub
 

JOTHA

Well-Known Member
Licensed User
Longtime User
Hi omidaghakhani1368,

maybe a silly question:
Where did you declare the variables "pnlcamera" and "exCam"?

If I use them, I get "Undeclared variable 'pnlcamera' is used before it was assigned any value" ...

Thanks in advance for your answer.
 
Upvote 0

omidaghakhani1368

Well-Known Member
Licensed User
Longtime User
Hi omidaghakhani1368,

maybe a silly question:
Where did you declare the variables "pnlcamera" and "exCam"?

If I use them, I get "Undeclared variable 'pnlcamera' is used before it was assigned any value" ...

Thanks in advance for your answer.
Hi.
pnlcamera exist in layout for show taken picture
and excam variable is advancecamera library
 
Upvote 0

JOTHA

Well-Known Member
Licensed User
Longtime User
Hi omidaghakhani1368,

thank you for your fast response.

... but there must be some more other code, because I got these messages now:

"Unknown member: savepicturetofile"
"Unknown member: bitmap"

The ACL works fine, but there is only the way how to rotate the picture ...
 
Upvote 0

omidaghakhani1368

Well-Known Member
Licensed User
Longtime User
not problem
assume you take picture from camera and save it and then use RotateImage easily
 
Upvote 0

JOTHA

Well-Known Member
Licensed User
Longtime User
... you gave me the right idea ..
I thought, that the picture was saved in the rotated version, but it first saved as taken photo and then it was rotated.

Now I made a little workaround:
B4X:
Dim NewImage As Bitmap
NewImage = RotateImage(LoadBitmap(File.DirRootExternal, "DCIM/FrontCam/1234567890123.jpg"),-90)
Panel_014_ImageView_001.Bitmap = NewImage

'-- jetzt nur noch das Bild in gedrehter Position speichern --
    Dim out As OutputStream
    out = File.OpenOutput(File.DirRootExternal, "DCIM/FrontCam/1234567890123.jpg", False)
    NewImage.WriteToStream(out, 100, "JPEG")
    out.Close

Thank you! +Like
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…