How to resize JPGs and save result

hgperli

Member
Licensed User
Longtime User
Hi there,
new to B4A, I'm currently trying to learn a bit about it, so I came across an interesting function 'LoadBitmapSample(..)', which I think is great when trying to reduce the memory required to display images/bitmaps/jpgs/...; however I was wondering how to save the reduced image back to the SD card. Is there an example out there, or any other help possible? Or are there other ways to resize jpg-images and save the result?
Thanks in advance
HG
 

Jost aus Soest

Active Member
Licensed User
Longtime User
I usualy use this subs:

B4X:
Public Sub SaveBitmap(Dir As String, FileName As String, Picture As Bitmap)
   Dim Out As OutputStream = File.OpenOutput(Dir, FileName, False)
   Picture.WriteToStream(Out, 90, "JPEG")
   Out.Close
End Sub

B4X:
Sub CreateScaledBitmap(Original As Bitmap, Width As Int, Height As Int, Filter As Boolean) As Bitmap
    Dim r As Reflector
    Dim b As Bitmap
    b = r.RunStaticMethod("android.graphics.Bitmap", "createScaledBitmap", _
        Array As Object(Original, Width, Height, Filter), _
        Array As String("android.graphics.Bitmap", "java.lang.int", "java.lang.int", "java.lang.boolean"))
    Return b
End Sub
 
Upvote 0
Top