Android Question Crop image.jpg

Discussion in 'Android Questions' started by Devv, Jun 23, 2015.

  1. Devv

    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 ?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You can use Canvas to crop an image.
     
  3. Devv

    Devv Active Member Licensed User

    could you provide a link or example please ?
     
  4. Peter Simpson

    Peter Simpson Well-Known Member Licensed User

    Code:
    '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
     
    ilan, Yvon Steinthal, CHK and 3 others like this.
  5. Devv

    Devv Active Member Licensed User


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

    Code:
    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
     
  6. CHK

    CHK New Member Licensed User

    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.
     
Loading...