Android Question ScalmageView Save to file

Nkalampika

Active Member
Licensed User
how to do
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim ScaleImageView1 As ScaleImageView   

    Private Canvas As Canvas

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Viewer")
    
    gestures.SetOnGestureListener(Panel1, "Panel1")
    
    Canvas.Initialize(ScaleImageView1)
End Sub



Sub ScaleImageView1_OnDraw(viewcanvas As Canvas) 'The view is being redrawn. Use viewcanvas to draw on it.
    
    canvas=viewcanvas
    
    Log("draw")
End Sub

Private Sub Button_save_Click
    Dim Out As OutputStream
    Out = File.OpenOutput( File.DirRootExternal & "/Download/", "Testxv.jpg", False)
    canvas.bitmap.WriteToStream(Out, 90, "JPEG")
    Out.Close
    
End Sub

NOT WORKING
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
I've looked back at my source for ScaleImageView and found this comment in Initialize that I had forgotten about. 'cw' is the Canvas passed as the parameter to the OnDraw method.
Java:
//the bitmap is only used to initialize CanvasWrapper. Note that Canvas.getBitmap will not return something meaningful.
cw.Initialize2(Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888));
This is the source of the black 2 x 2 bitmap that gets saved so it looks like I'm wrong about being about being able to access the image. It seems you can draw on the view using the passed Canvas but not get it back as a Bitmap.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
OK - I've worked out how to do it. ScaleImageView v2.3 has a new readable property Image
B4X:
    Dim b As Bitmap
    b.Initialize3(ScaleImageView1.Image)   
    Dim Out As OutputStream
    Out = File.OpenOutput( File.DirRootExternal & "/Download/", "Testxv.jpg", False)
    b.WriteToStream(Out, 90, "JPEG")
    Out.Close
ScaleImageView - Pan and zoom large images | B4X Programming Forum
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…