Save image to file from imageView

TrisectDevelopment

Active Member
Licensed User
Longtime User
I have an imageView with an image.
The image is loaded from gallery or taken from camera.

But how do I save the imageView content as a file ex. jpg.

:sign0104:
Trisect Development
 

kickaha

Well-Known Member
Licensed User
Longtime User
B4X:
Dim tempbitmap as Bitmap
tempbitmap = YourImageView.Bitmap
tempbitmap.WriteToStream ...........
 
Upvote 0

TrisectDevelopment

Active Member
Licensed User
Longtime User
Hi Erel

I'm really a noob when it comes to Basic4Android.
My force so far is C#.NET and Obj-C in XCode.

If you could would you please post an example??
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim b As Bitmap
    b = ResizeBitmap(LoadBitmap(File.DirAssets, "image1.jpg"), 20, 20)
    Dim out As OutputStream
    out = File.OpenOutput(File.DirRootExternal, "1.jpg", False)
    b.WriteToStream(out, 100, "JPEG")
    out.Close
End Sub

Sub ResizeBitmap(original As Bitmap, width As Int, height As Int) As Bitmap
    Dim new As Bitmap
    new.InitializeMutable(width, height)
    Dim c As Canvas
    c.Initialize2(new)
    Dim destRect As Rect
    destRect.Initialize(0, 0, width, height)
    c.DrawBitmap(original, Null, destRect)
    Return new
End Sub
 
Upvote 0

Swissmade

Well-Known Member
Licensed User
Longtime User
Here:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim b As Bitmap
    b = ResizeBitmap(LoadBitmap(File.DirAssets, "image1.jpg"), 20, 20)
    Dim out As OutputStream
    out = File.OpenOutput(File.DirRootExternal, "1.jpg", False)
    b.WriteToStream(out, 100, "JPEG")
    out.Close
End Sub

Sub ResizeBitmap(original As Bitmap, width As Int, height As Int) As Bitmap
    Dim new As Bitmap
    new.InitializeMutable(width, height)
    Dim c As Canvas
    c.Initialize2(new)
    Dim destRect As Rect
    destRect.Initialize(0, 0, width, height)
    c.DrawBitmap(original, Null, destRect)
    Return new
End Sub

Great Job Erel,
Working in one Minute
:sign0188:
 
Upvote 0
Top