Page 1 of 1
Posted: Sun Jun 23, 2002 12:00 pm
by BackupUser
Restored from previous forum. Originally posted by Branston.
I'm trying to create an image off screen so it can be displayed later.
The image is called 'store'.
I think this is how you do it, but it's not working as I expect.
If anyone wouldn't mind having a look at this code and tell me where I'm going wrong I'd be very grateful. Thanks!
;--------------------- code -------------------------
width=200
height=128
store=CreateImage(0, Width, Height)
Gosub dothewindow:
OpenWindow(store, 100, 100, Width, Height,#PB_Window_SystemMenu, Str(store))
Repeat
If WindowEvent() = #PB_EventCloseWindow
quit =1
EndIf
Until quit =1
End
;--------------------------- subroutine---------------------
dothewindow:
StartDrawing(0) ;<-- I want this to draw to store
; if i use StartDrawing(store) it causes a crash
For x = 0 To 100
boxx=Random(200)
boxy=Random(128)
r=Random(255)
g=Random(255)
b=Random(255)
size=5+Random(25)
Circle(boxx,boxy,size,RGB(r,g,b)) ; a nice random circle...
Next x
StopDrawing()
Return
Posted: Sun Jun 23, 2002 12:25 pm
by BackupUser
Restored from previous forum. Originally posted by El_Choni.
From the help file:
"Syntax
StartDrawing(OutputID)
Description
Change the current drawing output to the specified output. After setting this, all the Drawing commands are rendered on this output. Once all drawing operations are finished, StopDrawing() must be called.
OutputID can be get with the following commands:
WindowOutput(): Graphics will be rendered directly on the Window
ScreenOutput(): Graphics will be rendered directly on the Screen (for games)
ImageOutput(): Graphics will be rendered directly on the Image data (see CreateImage())
PrinterOutput(): Graphics will be rendered directly on the printer."
That is, you should use StartDrawing(ImageOutput()). The value stored in "store" is the bitmap handle, not the needed OutputID.
And you're not showing the image you've drawn!
Bye,
El_Choni
Posted: Sun Jun 23, 2002 1:18 pm
by BackupUser
Restored from previous forum. Originally posted by Branston.
Hi El_Choni.
I see.. StartDrawing(ImageOutput()) will fill up my CreateImage()
What is the use for the #Image field in the CreateImage(#Image, Width, Height)command?
I would like to display this stored image using the OpenWindow command
Can this be done by correctly setting the #Window field? Or (probably) am I completely misunderstanding how this all works?
Thanks in advance for being patient!

Posted: Sun Jun 23, 2002 11:55 pm
by BackupUser
Restored from previous forum. Originally posted by El_Choni.
Hi,
What is the use for the #Image field in the CreateImage(#Image, Width, Height)command?
#Image is just an index number, like #Gadget in gadgets.
I would like to display this stored image using the OpenWindow command
Can this be done by correctly setting the #Window field?
I think you must use the DrawImage(UseImage(0)) command, but I'm not sure (I'm not home, can't test it, sorry).
Hope it helps, bye,
El_Choni
Edited by - El_Choni on 24 June 2002 00:58:20
Posted: Wed Jun 26, 2002 1:01 pm
by BackupUser
Restored from previous forum. Originally posted by MrVainSCL.
Branston wrote:
I'm trying to create an image off screen so it can be displayed later.
The image is called 'store'.
I think this is how you do it, but it's not working as I expect.
If anyone wouldn't mind having a look at this code and tell me where I'm going wrong I'd be very grateful. Thanks!
Hi Branston
I checked your source and there are some small mistakes... If you declare "width=200" and "height=128" for example, you have to use the same for OpenWindow(), instead of Width,Height... because width and Width are not the same
StartDrawing(0) cant work! You have you tell the program the output for the drwaing, and this could be:
WindowOutput(): Graphics will be rendered directly on the Window
ScreenOutput(): Graphics will be rendered directly on the Screen (for games)
ImageOutput(): Graphics will be rendered directly on the Image data (see CreateImage())
PrinterOutput(): Graphics will be rendered directly on the printer."
Another point i noticed: "OpenWindow(store, 100, 100, Width, Height,#PB_Window_SystemMenu, Str(store))" is not correct too! You have to give and window, image, sound an OWN (!) number/handle... I have rewrote your source a bit (working fine now)... Have a look to it and learn about it... Hope this will help you... Have fun...
PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...
greetz
MrVainSCL! aka Thorsten
Posted: Wed Jun 26, 2002 1:04 pm
by BackupUser
Restored from previous forum. Originally posted by MrVainSCL.
Hi Branston
Here is now the source... Hope it will help you...
Code: Select all
;-----------------------------------
;
; Just a working CreateImage Example
;
; (26-Jun-2002 - 14:50m)
;
;-----------------------------------
;
winw = 240 ; window width
winh = 168 ; window height
;
xpos = (GetSystemMetrics_(#SM_CXSCREEN)-winw) / 2 ; only to center window on desktop
ypos = (GetSystemMetrics_(#SM_CYSCREEN)-winh) / 2 ; only to center window on desktop
;
;-------- Define the #Flags for our opening Window --------
;
#Win_Flag1 = #PB_Window_SystemMenu
#Win_Flag2 = #PB_Window_MinimizeGadget
#Win_Flags = #Win_Flag1|#Win_Flag2
;
;-------- Define some other stuff ---------
;
#Img_Image1 = 0 ; Image Number
#Img_Image1w = 200 ; Image width
#Img_Image1h = 128 ; Image height
;
;======== Init all the needed system stuff ========
;
If OpenWindow (0, xpos, ypos, winw, winh, #Win_Flags, "Just a working CreateImage Example") = 0
MessageBox_ (0,"Could not open Window", "Just a working CreateImage Example", #MB_ICONINFORMATION|#MB_OK)
End
EndIf
;
;-------- Create our Image --------
;
Gosub SUB_CreateImage
;
StartDrawing(WindowOutput(()
DrawImage(ImageID, 20, 20)
StopDrawing()
;
;----------------------------------------
; M a i n l o o p
;----------------------------------------
;
Repeat
EventID.l = WaitWindowEvent()
;
Select EventID
Case #PB_EventCloseWindow
quit = 1
EndSelect
;
Until quit = 1
;
End
;
;----------------------------------------
; Subroutine -> CreateImage
;----------------------------------------
SUB_CreateImage:
;
ImageID.l = CreateImage (#Img_Image1, #Img_Image1w, #Img_Image1h) ; First we have to create a temp image
;
StartDrawing(ImageOutput()) ; Now we can start to draw any stuff
; ; to our image :wink:
For x = 0 To 100
cirx = Random(#Img_Image1w)
ciry = Random(#Img_Image1h)
colr = Random(255)
colg = Random(255)
colb = Random(255)
;
size = 5+Random(25)
;
Circle(cirx,ciry,size,RGB(colr,colg,colb))
Next x
;
StopDrawing()
;
Return
;
;----------------------------------------
PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...
greetz
MrVainSCL! aka Thorsten
Posted: Wed Jun 26, 2002 1:07 pm
by BackupUser
Restored from previous forum. Originally posted by MrVainSCL.
Hi again
Upppss... there is small mistake but it works... i cant edit my posting
Please change: StartDrawing(WindowOutput(() to StartDrawing(WindowOutput())
Thanks!
PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...
greetz
MrVainSCL! aka Thorsten
Posted: Wed Jun 26, 2002 7:04 pm
by BackupUser
Restored from previous forum. Originally posted by Branston.
Hi MrVainSCL
Thank you very much for such a comprehensive explanation with code too!
I have copied and pasted it and understand it!
I could understand how drawing to one Window worked. But, I was having difficulty understanding the way images and windows were controlled seperately. I wasn't realizing that the 'output' of StartDrawing() could be 'switched' to an image in memory or to a Window on the screen - despite having read the help file a lot of times. I just wasn't 'seeing' it. (oops)
Thank you very much.
You've also just answered another question I had about multiple Images....
... they're selected with the UseImage() command.
Code: Select all
CreateImage (#Img_Image1, #Img_Image1w, #Img_Image1h)
CreateImage (#Img_Image2, #Img_Image1w, #Img_Image1h)
which = UseImage(#Img_Image1);
Registered PB 3.2 Win98SE
Edited by - branston on 26 June 2002 20:07:18
Posted: Wed Jun 26, 2002 11:16 pm
by BackupUser
Restored from previous forum. Originally posted by MrVainSCL.
Branston wrote:
You've also just answered another question I had about multiple Images....
... they're selected with the UseImage() command.
CreateImage (#Img_Image1, #Img_Image1w, #Img_Image1h)
CreateImage (#Img_Image2, #Img_Image1w, #Img_Image1h)
which = UseImage(#Img_Image1); <-- chooses which Img_Image will be
which = UseImage(#Img_Image2); selected - for drawing into.
; Image can then be displayed
; with DrawImage(which, x, y)
Thanks!
Hi Branston
Yes, you are right.. but if you want use pictures with different size, then use for any picture/image an own variable... else you could very fast get wrong results, due fact of having no real view over your stuff...
CreateImage (#Img_Image1, #Img_Image1w, #Img_Image1h) ; 1 = for Image1,#num,#width,#height
CreateImage (#Img_Image2, #Img_Image2w, #Img_Image2h) ; 2 = for Image2, #num,#width,#height
the rest is ok... Happy coding
PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...
greetz
MrVainSCL! aka Thorsten