B4J Question [ non-ui ] How can i draw custom Canvas img ?

emexes

Expert
Licensed User
Longtime User
Did you try it?

My recollection is that you just include the graphics library (jFX, or maybe now it's jXUI) and then you can Dim a Canvas and have access to the associated drawing methods.

Then use .CreateBitmap to get the final pixels as a Bitmap which you can .WriteToStream as JPEG or PNG ready for emailing.

Admittedly, that does sound too easy to be true, so perhaps I am missing something ;-)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
so perhaps I am missing something
Maybe that he is writing a NONUI app. You can not include UI Elements in a NONUI app. At least that´s what i have in mind....
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Canvas is not a UI element so it can be used in non-ui apps, but the result cannot be attributed to a canvas capable UI element, like a button or imageview, it has to be saved thought using stream if I'm not mistaken
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
80% sure... But, I never tried it though
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You are right, it works.
Below my test code and project.

B4X:
Sub AppStart (Form1 As Form, Args() As String)
'    MainForm = Form1
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
'    MainForm.Show

    File.WriteString("D:\", "1.png", "")
    Private imv As Image
    imv.Initialize("D:\", "1.png")
    Private cvs As Canvas
    cvs.Initialize("")
    cvs.PrefWidth = 100
    cvs.PrefHeight = 100
    cvs.DrawLine(10, 10, 100, 100, fx.Colors.Red, 2)
    imv = cvs.Snapshot
    Private Out As OutputStream = File.OpenOutput("D:\", "1.png", False)
    imv.WriteToStream(Out)
    Out.Close
End Sub
 

Attachments

  • NoneUICanvasImage.zip
    1 KB · Views: 381
Last edited:
Upvote 0

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
You are right, it works.
Below my test code and project.

B4X:
Sub AppStart (Form1 As Form, Args() As String)
'    MainForm = Form1
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
'    MainForm.Show

    File.WriteString("D:\", "1.png", "")
    Private imv As Image
    imv.Initialize("D:\", "1.png")
    Private cvs As Canvas
    cvs.Initialize("")
    cvs.PrefWidth = 100
    cvs.PrefHeight = 100
    cvs.DrawLine(10, 10, 100, 100, fx.Colors.Red, 2)
    imv = cvs.Snapshot
    Private Out As OutputStream = File.OpenOutput("D:\", "1.png", False)
    imv.WriteToStream(Out)
    Out.Close
End Sub


this works on "Console Project" application ?
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Non-ui and console app behave the same, IDE wise... The major difference is that you can output to screen in text format and prompt the user for text input.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
dont works ... because javafx dont is initialized on non-ui ( console ) project ...
Can you share your test project and/or error message that is given!?
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
In a VPS, yes, it will.
It's a jar file, so it works in ANY system that is capable of running a jar file!
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
hmm, in a linux vps enviroment u can have trouble to make a ui app auto run (start at/after boot)
 
Upvote 0
Top