Android Question Crop image.jpg

Devv

Active Member
Licensed User
How could i crop an image file on the sdcard ?
i want fixed size, 10% from the height and 100 of width
how to do so without user interaction or GUI ?
 

Peter Simpson

Expert
Licensed User
B4X:
'CROPPED BITMAP Image
Sub CropBitmap(Image As Bitmap, AcrossX As Int, DownY As Int, WidthX As Int, HeightY As Int) As Bitmap
    Dim JO As JavaObject
    Dim BmpCropped As Bitmap
        BmpCropped = JO.InitializeStatic("android.graphics.Bitmap").RunMethod("createBitmap", Array(Image, AcrossX, DownY, WidthX, HeightY))
    Return BmpCropped
End Sub
 

Devv

Active Member
Licensed User
B4X:
'CROPPED BITMAP Image
Sub CropBitmap(Image As Bitmap, AcrossX As Int, DownY As Int, WidthX As Int, HeightY As Int) As Bitmap
    Dim JO As JavaObject
    Dim BmpCropped As Bitmap
        BmpCropped = JO.InitializeStatic("android.graphics.Bitmap").RunMethod("createBitmap", Array(Image, AcrossX, DownY, WidthX, HeightY))
    Return BmpCropped
End Sub

this code is working but it is cropping the image but rotated

B4X:
    camEx.SavePictureToFile(Data, File.DirRootExternal, "1.jpg")
    b = CropBitmap(LoadBitmap(File.DirRootExternal,"1.jpg"),0,0,3000,500)
   
   
    Dim out As OutputStream
    out = File.OpenOutput(File.DirRootExternal, "1cr.jpg", False)
    b.WriteToStream(out, 100, "JPEG")
    out.Close
 

CHK

Member
Licensed User
B4X:
'CROPPED BITMAP Image
Sub CropBitmap(Image As Bitmap, AcrossX As Int, DownY As Int, WidthX As Int, HeightY As Int) As Bitmap
    Dim JO As JavaObject
    Dim BmpCropped As Bitmap
        BmpCropped = JO.InitializeStatic("android.graphics.Bitmap").RunMethod("createBitmap", Array(Image, AcrossX, DownY, WidthX, HeightY))
    Return BmpCropped
End Sub
I have now been searching for quite some time in this forum ... but this is by far the most elegant solution to crop an image. Many thanks to Peter Simpson.
 
Top