B4J Question Image crop

TomDuncan

Active Member
Licensed User
Longtime User
My old-timers error. It was working all along.
Hi All,
I have images that need to be copped.
However with the code below the images are not cropped.
I have put in a tiny crop for me to test.
Tom

B4X:
Sub Crop_ImageToJPEGByteArray(aImage As Object, x,y,w,h As Int, quality As Int) As Byte()
    'Sanity check incoming image
    Try
        Dim image As B4XBitmap = aImage
        Dim cropped As B4XBitmap
    Catch
        td_log("crop " & LastException)
        Return Array As Byte ()
    End Try
 
'    cropped = image.Crop(x, y, w , h)
   cropped = image.Crop(10,10,80,40)
    'Convert image to JPEG byte array
    Dim out As OutputStream
    out.InitializeToBytesArray(0)
    cropped.WriteToStream(out, quality, "JPEG")
    out.Close
 
    'Done
    Return out.ToBytesArray
End Sub
 
Last edited:
Top