Android Question cameraex resize yuvImage

Discussion in 'Android Questions' started by PassionDEV, Jun 17, 2019.

  1. PassionDEV

    PassionDEV Active Member Licensed User

    i see this sub in cameraex


    Code:
    Public Sub PreviewImageToJpeg(data() As Byte, quality As Int) As Byte()
        
    Dim size, previewFormat As Object
      
        r.target = parameters
      
        size = r.RunMethod(
    "getPreviewSize")
      
        previewFormat = r.RunMethod(
    "getPreviewFormat")
      
        r.target = size
      
        
    Dim width = r.GetField("width"), height = r.GetField("height"As Int
      
        
    Dim yuvImage As Object = r.CreateObject2("android.graphics.YuvImage", _
            
    Array As Object(data, previewFormat, width, height, Null), _
            
    Array As String("[B""java.lang.int""java.lang.int""java.lang.int""[I"))
      
        r.target = yuvImage
      
        
    Dim rect1 As Rect
      
        rect1.Initialize(
    00, r.RunMethod("getWidth"), r.RunMethod("getHeight"))
      
        
    Dim out As OutputStream
      
        out.InitializeToBytesArray(
    100)
      
        r.RunMethod4(
    "compressToJpeg"Array As Object(rect1, quality, out), _
            
    Array As String("android.graphics.Rect""java.lang.int""java.io.OutputStream"))
          
      
      
        
    Return out.ToBytesArray
      
      

    End Sub
    can i set a custom scaled size during the compression to jpeg ? i dont want to convert each frame to bitmap to resize can i do it directly in this function ?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. PassionDEV

    PassionDEV Active Member Licensed User

    i do similar approach like following

    Code:
    Sub camera_Preview(Data() As Byte)
      


    If DateTime.Now > lastPreviewSaved + IntervalMs Then


    Dim jpeg() As Byte = camera1.PreviewImageToJpeg(Data, 10)

    Dim rot As Int = camera1.CurrOrient
    Dim ins As InputStream
    Dim bmp As Bitmap

    ins.InitializeFromBytesArray(
    jpeg0jpeg.Length)
    bmp.Initialize2(ins)
    ins.Close

    bmp = bmp.Resize(
    240320False)
    bmp = bmp.Rotate(rot)

    Dim imagetostring As String
    Dim imgbyets() As Byte
    imgbyets =  imagetobyets(bmp)
    imagetostring = strutls.EncodeBase64(imgbyets)

    lastPreviewSaved = 
    DateTime.Now

    CallSub2(Service,"LIVECAMSENDER",imagetostring)




    End If



    End Sub
    but the app is freezing alot while doing the resize and rotate process and i want the custom size to set to 240 x 320
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Make sure to test it in release mode. Have you set the preview size?
     
  5. PassionDEV

    PassionDEV Active Member Licensed User

    yes the app is in release mode , oncamera ready i set the preview size to the lowest

    Code:
    Sub camera_Ready (Success As Boolean)
    If Success Then
    camera1.SetJpegQuality(
    10)

    Dim x2, y2, size As Int
    For Each PictureSize As CameraSize In camera1.GetSupportedPicturesSizes
    Dim TempSize As Int = Sqrt(Power(PictureSize.Width, 2) + Power(PictureSize.Height, 2))
    If size = 0 Or TempSize < size Then
    x2 = PictureSize.Width
    y2 = PictureSize.Height
    size = TempSize
    End If
    Next


    Log(x2&": "& y2)
    camera1.SetPictureSize(x2,y2)

    camera1.CommitParameters
    camera1.StartPreview
    Else
    ToastMessageShow("Cannot open camera."True)
    End If

    End Sub

    sense some devices will not have the exact size that i need i had to resize the output image but this process is too heavy and make the phone freezes
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Read post #2 again. You are not setting it correctly.
     
    PassionDEV likes this.
  7. PassionDEV

    PassionDEV Active Member Licensed User

    sorry my bad

    Code:
    Sub camera_Ready (Success As Boolean)
    If Success Then
    camera1.SetJpegQuality(
    10)

    Dim x2, y2, size As Int
    For Each PictureSize As CameraSize In camera1.GetSupportedPicturesSizes
    Dim TempSize As Int = Sqrt(Power(PictureSize.Width, 2) + Power(PictureSize.Height, 2))
    If size = 0 Or TempSize < size Then
    x2 = PictureSize.Width
    y2 = PictureSize.Height
    size = TempSize
    End If
    Next


    Log(x2&": "& y2)
    camera1.SetPreviewSize(x2,y2)

    camera1.CommitParameters
    camera1.StartPreview
    Else
    ToastMessageShow("Cannot open camera."True)
    End If

    End Sub
    is the preview size need to be a supported size ? or i can set it on any custom size even if its not supported ?
     
  8. DonManfred

    DonManfred Expert Licensed User

    as far as i know you can only use one of the supported sizes.
     
    PassionDEV likes this.
  9. Erel

    Erel Administrator Staff Member Licensed User

    You must be more accurate...

    CamEx.GetSupportedPreviewSizes
     
    PassionDEV likes this.
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