B4J Question Canvas!!! ARRRGGHH!!! I'm losing my mind!

Cableguy

Expert
Licensed User
Longtime User
Hi, its me again!!!

So, I have 2 views that I need to combine into 1 "JPEG" image...
But I just can't make sense of canvas!!!
My Logic is, I create a blank, parentless canvas, to which I set the Image from a B4XImageView.
Then I take a snapshot of an "overlay" Panel and add it to the Canvas.
Then, Finally, export it to jpeg file.

But since canvas is an "invisible" thing, I just don't know what I am doing or why it doesn't work!
 

zed

Active Member
Licensed User
This works very well
B4J:
Private Sub Button1_Click
    fx.Clipboard.SetImage(Pane1.Snapshot)
End Sub

Private Sub Button2_Click
    If fx.Clipboard.HasImage Then
        Dim bmp As B4XBitmap = Pane1.Snapshot
        Dim fn As String =  "filename" & "_" & DateTime.Now & ".jpg"
        Dim Out As OutputStream
        Out = File.OpenOutput(File.DirTemp, fn, False)
        bmp.WriteToStream(Out, 100, "JPEG")
        Out.Flush
        Out.Close
    End If
    Dim myBmb As Image  =xui.LoadBitmap(File.DirTemp,fn)
    Log(myBmb)
    B4XImageView2.SetBitmap(myBmb)
End Sub
 

Attachments

  • Project.zip
    111 KB · Views: 112
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Why not put the two views inside a panel and take a snapshot of the panel?
Simply because the original image is most of the times bigger that the image shown (and thus limited in size) in the pane, and I need to keep the original image size.
Anyway, I got it working, going baby steps at a time.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
going baby steps at a time
It can be frustrating, but is usually the only way to make sure things are working 100%.

the original image is most of the times bigger that the image shown
You could try putting the canvas/Image on a scroll pane, that way the resultant image should be the full image and you can clip it if you need to.

Or a little more complex on a zoomable image view: https://www.b4x.com/android/forum/t...-zoomable-pannable-image-view.119987/#content
 
Last edited:
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
This works very well
B4J:
Private Sub Button1_Click
    fx.Clipboard.SetImage(Pane1.Snapshot)
End Sub

Private Sub Button2_Click
    If fx.Clipboard.HasImage Then
        Dim bmp As B4XBitmap = Pane1.Snapshot
        Dim fn As String =  "filename" & "_" & DateTime.Now & ".jpg"
        Dim Out As OutputStream
        Out = File.OpenOutput(File.DirTemp, fn, False)
        bmp.WriteToStream(Out, 100, "JPEG")
        Out.Flush
        Out.Close
    End If
    Dim myBmb As Image  =xui.LoadBitmap(File.DirTemp,fn)
    Log(myBmb)
    B4XImageView2.SetBitmap(myBmb)
End Sub
As you know, I got it working.
The snapshot as single canvas origin would result in a not optimal image file.

@stevel05 Thanks for the suggestions. Sometimes it's hard to know the views that are best suited for each one's needs.
Anyway, I got it running with "no brand snickers, so why go get some Jordan's?"
 
Upvote 0
Top