Android Question Rotate camera taken picture

Discussion in 'Android Questions' started by omidaghakhani1368, Feb 20, 2015.

  1. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed 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?

    Code:
    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, 00, original.Width, original.Height, _
         
    matrixTrue))
       
    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
     
  2. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

    Hi again.
    I can solve it.
    I replace LoadBitmap with LoadBitmapSample and it's ok
     
    Leni Berry likes this.
  3. JOTHA

    JOTHA Well-Known Member Licensed 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.
     
  4. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

    Hi.
    pnlcamera exist in layout for show taken picture
    and excam variable is advancecamera library
     
  5. JOTHA

    JOTHA Well-Known Member Licensed 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 ... :(
     
  6. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

    not problem
    assume you take picture from camera and save it and then use RotateImage easily
     
    JOTHA likes this.
  7. JOTHA

    JOTHA Well-Known Member Licensed 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:
    Code:
    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
     
    Leni Berry likes this.
  8. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

    Gooooooood luck!
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice