Android Question How to save Preview picture in CamEx

Discussion in 'Android Questions' started by Gary Milne, Mar 11, 2015.

  1. Gary Milne

    Gary Milne Active Member Licensed User

    I think this is probably easy but I cannot find an example.

    In the CameraEx class there is a function called PreviewImageToJpeg(data() as byte, quality as Int) as Byte()

    The first parameter (data as byte array) refers to the camera preview image formatted in YUV.

    My code would be something like:
    Code:
    Dim jpeg() As Byte = camEx.PreviewImageToJpeg(PreviewImage, 70)
    But what do I need to call in order to save the preview image into the byte array in the first place.

    Any help appreciated.
     
  2. Gary Milne

    Gary Milne Active Member Licensed User

    Never mind, I figured it out.

    You have to add the Preview Sub which receives the byte array automatically.

    Code:
    Sub camera1_Preview(Data() As Byte)
        
    Log ("Running Preview")
        
    Dim jpeg() As Byte = camEx.PreviewImageToJpeg(Data, 70)

        
    Dim bmp As Bitmap
        
    Dim ins As InputStream
       
        ins.InitializeFromBytesArray(
    jpeg0jpeg.Length)
        bmp.Initialize2(ins)
        ins.Close

        
    'Save the screen images to a file for attachment
        Dim stream As OutputStream
        stream = 
    File.OpenOutput( File.DirRootExternal, "File" & Counter & ".jpg",False)
        bmp.WriteToStream(stream ,
    50,"JPEG")
        stream.Close
       
        Counter = Counter + 
    1
       
    End Sub
    This is just a simple example not to be taken too literally. You would want a timer or semaphore to flag the actual saving of the picture.
     
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