Android Question Crop and save image

ykucuk

Well-Known Member
Licensed User
Longtime User
Hello

How can i crop and save faces from face detect ?



My code
Face Detection:
    cvs.ClearRect(cvs.TargetRect)
        Dim frameBuilder As JavaObject
        Dim bb As JavaObject
        bb = bb.InitializeStatic("java.nio.ByteBuffer").RunMethod("wrap", Array(data))
        frameBuilder.InitializeNewInstance("com/google/android/gms/vision/Frame.Builder".Replace("/", "."), Null)
        Dim cs As CameraSize = camEx.GetPreviewSize
        frameBuilder.RunMethod("setImageData", Array(bb, cs.Width, cs.Height,  842094169))
        Dim frame As JavaObject = frameBuilder.RunMethod("build", Null)
        Dim SparseArrayFace As JavaObject = facedetector.RunMethod("detect", Array(frame))
        LastPreview = DateTime.Now
        Dim MatchesFaces As Int = SparseArrayFace.RunMethod("size", Null)
        For i = 0 To MatchesFaces - 1
          
            Dim face As JavaObject = SparseArrayFace.RunMethod("valueAt", Array(i))
            'How can i crop and save faces as image file.
        Next
 
Last edited:

ykucuk

Well-Known Member
Licensed User
Longtime User
i found a solution. Let me know id there is better solution

B4X:
Dim faceLoc As JavaObject=face.RunMethod("getPosition",Null)
Dim jpeg() As Byte = camEx.PreviewImageToJpeg(data, 100)
Dim bmp As Bitmap
Dim ins As InputStream
ins.InitializeFromBytesArray(jpeg, 0, jpeg.Length)
bmp.Initialize2(ins)
ins.Close
bmp=bmp.Crop(faceLoc.GetField("x"),faceLoc.GetField("y"),face.RunMethod("getWidth",Null),face.RunMethod("getHeight",Null))
 
Upvote 0
Top