Android Question Crop an image and save it.

hub73

Active Member
Licensed User
Longtime User
Hello b4a community !
I'm newbie with b4a.

To explain what i want :

1) I've loaded an 3000x2000 image (png or jpg) into an ImageView. Now i want crop the image to rectangle 1280x720.
2) On the ImageView i move my selection rectangle.
3) Next i press the 'crop' button. The ImageView now show the cropped image.

4) I'm happy with it and press the 'Save button' to save the result (as png or jpg)."

Note that i don't want capture the screen image but a part of the image inside the ImageView. (As the image displayed on the screen is reduced).


Now how do this ? I'm need some links or ideas !

1) I know how to use the designer. So i've my ImageView and the buttons ! I know how to load an png and jpg image on the imageview.

2) ???

Next i don't know how to draw my rectangle on the ImageViewiew and move it. Perhaps wrong start and i should use a canvas ? I'm trying to determine a method to do the job ! I'm searching from doc or code sample without success.

I'm sure next code 3) and 4) without problem...

Many thanks for your help and code samples.
 
Last edited:

hub73

Active Member
Licensed User
Longtime User
Thanks Klauss.

B4X:
Dim BitMap_Source As Bitmap
Dim BitMap_Travail As BitmapExtended
Dim BitMap_Destination As Bitmap
Dim Sortie As OutputStream

ImageView1.Bitmap = LoadBitmap (Chemin_clef, Resultat)
BitMap_Source = LoadBitmapSample(Chemin_clef, Resultat, 4000,3000)

'no problem to trace Rect1 on the ImageView and display the picture.

Next ... capture

    BitMap_Destination.InitializeMutable(Rect1.Right - Rect1.Left, Rect1.Bottom - Rect1.Top)

    BitMap_Destination = BitMap_Travail.createBitmap3 (BitMap_Source, Rect1.Left, Rect1.Top, Rect1.Right - Rect1.Left, Rect1.Bottom - Rect1.Top)

    Sortie = File.OpenOutput (Chemin_clef, EditText1b.Text, False)
    BitMap_Travail.compress (BitMap_Destination, "JPEG", 100, Sortie)

But the file "Final.png" is an 0 bytes files ! What's wrong ? Please confirm if you think there is no problem with this code.

Many thanks to help me again !
 
Last edited:
Upvote 0

hub73

Active Member
Licensed User
Longtime User
Inside the BitmapExtended doc there are :

android.permission.BIND_WALLPAPER
android.permission.SET_WALLPAPERandroid.permission

Should i paste this inside my code ?
 
Upvote 0
Top