I have a big Canvas, 800 by 800 pix.
First I load a jpg file by using GetOpenFolderItem.
The picture is always in the left top of the canvas, but I like it to put it on a special position, how?
In the second step I will draw some lines and arcs in the same canvas but thats impossible together with the picture.
As the last step I will save the canvas (Picture and lines etc.) I a database but only the picture is stored.
Canvas is only the display method.
You need to assemble the thing is displays ‘offline’ and refresh the canvas when it needs to be painted.
Create a picture thePic which is 800 x 800
Load the jpg as a new picture theJPG
[code]//draw the theJPG onto thePic … the first 4 items are where is it placed
thePic.graphics.drawpicture theJPG, 100,120,300,300,0,0,theJPG.width,theJPG.height
//draw a line
thepic.graphics.drawline 0,0,800,800
[/code]
In the Canvas’ Paint event:
g.drawpicture thePic,0,0
Hai,
I have write the following but it doesent works.
[code]MyPic = New Picture(800,800,32)
Dim Thejpg As FolderItem = GetOpenFolderItem("")
MyPic.graphics.drawpicture theJPG, 100,120,300,300,0,0,80,175
MyPic.Graphics.DrawLine(100,100,600,100)
MyPic.Graphics.DrawOval(10,10,50,50)
MyPic.Graphics.DrawLine(100,0,100,600)[/code]
@Hans: a little bit more information about “doesn’t work” would be helpful. The code looks okay at first glance. Do you then draw the picture into the canvas?
Hans,
you do not tell the application what to do with MyPic. Either:
In the Canvas’ Paint event:
g.drawpicture MyPic,0,0
or
g.drawpicture MyPic,100,10
Or in Canvas1.Backdrop event:
Canvas1.Backdrop = MyPic
Hai,
Xojo gives a bug by :
MyPic.graphics.drawpicture theJPG, 100,120,300,300,0,0,80,175
Parameter “image” expects class Picture, but this is a class Folderintem
Hans,
if your Canvas does not already have a Paint (nor a Backdrop) event, just add one, then place the a code at the appropriate location.
Another thing you may do is to give us the name of your BigCanvas
if it is not Canvas1.
Use the code below to choose, open and display an image file into Canvas1:
[code] Dim picFile As FolderItem
picFile = GetOpenFolderItem("")
If picFile <> Nil Then
Dim pic As Picture
pic = Picture.Open(picFile)
Canvas1.Backdrop = pic
End If[/code]
From Language Reference
Emile,
I have Canvas1 with a Paint Event g.drawpicture MyPic,0,0
I have 2 properties: MyPic and TheJpg both as Picture.
Then i have a button with a Action event with the following Code.
MyPic = New Picture(800,800,32)
Dim Thejpg As FolderItem = GetOpenFolderItem("")
MyPic.graphics.drawpicture TheJPG, 100,120,300,300,0,0,80,175
MyPic.Graphics.DrawLine(100,100,600,100)
MyPic.Graphics.DrawOval(10,10,50,50)
MyPic.Graphics.DrawLine(100,0,100,600)
Canvas1.Backdrop = Picture.Open(Thejpg)
By running, Xojo gives a Bug by : MyPic.graphics.drawpicture TheJPG, 100,120,300,300,0,0,80,175
with the following text:
Parameter “image” expects class Picture, but this is a class Folderintem
If i comment this bug, then the Lines wil be displayd.
What is wrong??
The brain isn’t working. You are correct, you can’t directly paint a FolderItem. You need to read the data into a MemoryBlock and then you put it into a picture. See http://documentation.xojo.com/index.php/Picture.GetData
You know how to handle the combination of FolderItem, BinaryStream and MemoryBlock?
Hi Beatrix,
I have never works with a MemoryBlock.
The only thing i like to do is load a image, put it on a position in to the Canvas (or picture) and afterwards draw some linens and curves in to the Canvas or Picture.
At last the combination ot image and lines should be printed in a record.
But the only results i get is printing the image or printing the lines but never together.
Hans,
I continued to wrote the example 'till now and here I am:
[code] Dim picFile As FolderItem
picFile = GetOpenFolderItem("")
If picFile <> Nil Then
Dim pic As Picture
pic = Picture.Open(picFile)
// Create an offscreen Picture
gPict = New Picture(pic.Width,pic.Height)
// Draw the loaded Picture into the Offscreen Picture
gPict.Graphics.DrawPicture pic,10,10
// Draw a line
gPict.Graphics.ForeColor = &cFF0000
gPict.Graphics.DrawLine 10,10,100,10
// Apply the image to the Backdrop property
Canvas1.Backdrop = gPict
End If[/code]
I added a window property: gPict As Picture
The code above is in a PushButton and ask you to choose an image file (here I load a png file).
The result in the screen is your image and a red line.
Copy paste the example in your project, as is and get back here if needed.
The code above is rough:
a. no error checking on the image loading,
b. allows you to load any file (no restriction to an image file format),
c. etc.
It is meant to allow you to understand (I hope so) how to achieve your goal /
and mine (a different one).
BTW: if you want to save the whole image, add another button in your window (for example) and use:
[code] If Canvas1.Backdrop <> Nil Then
// Save the Canvas Backdrop
Dim SavedBool As Boolean
Dim f As FolderItem
f = GetSaveFolderItem("public.png","Result Picture.png")
If f <> Nil Then
Canvas1.Backdrop.Save(f,Picture.SaveAsPNG)
End if
End If[/code]
Of course, you can save the Offscreen Picture contents instead: replace Canvas1.Backdrop
by gPict
and youre done.
Time to go back home to eat, nap, tv, whatever.
I will read any answer by tomorrow.
Back to basics:
[code]
dim myPic as picture
Dim TheJPG As picture
Dim picFile As FolderItem
MyPic = New Picture(800,800,32)
picFile = GetOpenFolderItem("")
If picFile <> Nil Then
TheJPG = Picture.Open(picFile)
MyPic.graphics.drawpicture TheJPG, 100,120,300,300,0,0,80,175
MyPic.Graphics.DrawLine(100,100,600,100)
MyPic.Graphics.DrawOval(10,10,50,50)
MyPic.Graphics.DrawLine(100,0,100,600)
//now, if you must…
Canvas1.Backdrop = MyPic
end if[/code]
But you may be better off just drawing MyPic in the Canvas paint event
When you want to save the picture plus the lines, just save MyPic
Hi Jeff,
Thanks, it’s working.
But… only one question,
How can i copy MyPic in a Report Picture.
In a other program i have use a Intern SQLite DataBase but a direct way is maybe more simple?
What is a report picture?
In Xoyo you can make a Report, that means you can printout a lot of information.
In a report you can have different fields, fields like a Label and allso fields for pictures and other variables.
But in all the proposels they work with a DataBase and the varables of the DaraBase feed the report.
But i like to connect the Propertie Picture with this ReportPicture.