forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to create a graphics without showing on the screen?

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+
View previous topic :: View next topic  
Author Message
johannes



Joined: 21 Jan 2011
Posts: 65
Location: Leimen, Germany

PostPosted: Wed Dec 28, 2011 10:39 am    Post subject: How to create a graphics without showing on the screen? Reply with quote

Hi all,
I want to create a bitmap graphics (black on white) completely under algorithmic control, without any user interaction and without any visible graphics window on the screen. At the end the result should be a bmp file.

Given the manual example below (already modified), I experimententally started with
i=CREATE_GRAPHICS_REGION@( hnd1,400,300 )
and finished with
i= EXPORT_IMAGE@( 'filename.bmp' ) .

The result is a bit unstable (sometomes just black background, sometimes the ellipse is black), because I do not know how %gr and CREATE do interact. Without any %gr, the result is a black rectangle.

Question 1: who has a receipe for my task?
Question 2: what means "L" in 300L in the %gr parameters?

My junky test program:

! test to draw with %gr
program drawtests
INCLUDE <windows.ins>
INTEGER ctrl,hnd1
DATA hnd1/1/
! ----Graphics handles are input values to %gr ---
!
CALL SYSTEM ('del filename.bmp')
i=CREATE_GRAPHICS_REGION@( hnd1,400,300 ) ! silent mode?
CALL set_rgb_colours_default@(1)
CALL SET_CONTROL_BACK_COLOUR@(hnd1,RGB@(255,255,255))

! without the next two lines the result is a black rectangle
i=winio@('%`gr[white,rgb_colours]&',400L,300L,hnd1)
i=winio@('%ww%lw',ctrl)

i=select_graphics_object@(hnd1)

CALL SET_LINE_WIDTH@( 5 )
CALL draw_line_between@(100,100,300,200,RGB@(0,0,255))
CALL draw_filled_ellipse@(200,150,75,50,RGB@(255,0,0))
i= EXPORT_IMAGE@( 'filename.bmp' )
end
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7924
Location: Salford, UK

PostPosted: Wed Dec 28, 2011 11:07 am    Post subject: Reply with quote

I cannot give you a full answer but you are right to use CREATE_GRAPHICS_REGION@ and the L in 300L defines a 32 bit (long) integer value of 300. This would be the default so the L could be left out. It is also the same as 300_3 (for FTN95, meaning kind = 3).

You could search for CREATE_GRAPHICS_REGION@ in the help file and in the samples for further information.
Back to top
View user's profile Send private message AIM Address
johannes



Joined: 21 Jan 2011
Posts: 65
Location: Leimen, Germany

PostPosted: Wed Dec 28, 2011 1:12 pm    Post subject: Reply with quote

Hi Paul,
the online help does not tell much about examples, I guess.

Another question, for which I couldn't find an answer:
Is there an option for a %gr drawing surface to make it invisible?
Johannes
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Wed Dec 28, 2011 4:49 pm    Post subject: Reply with quote

Hi Johannes,

Drawing graphics to invisible regions is pretty difficult to debug! Maybe the development stage is best done with a visible (i.e. %gr) region.

My understanding of CREATE_GRAPHICS_REGION@ (and related routines) is that they imagine that once you have an image, you copy it to a %gr region so that the user can see it. Certainly the documentation for EXPORT_IMAGE@ says that it is for exporting a %gr to a file, not from some internal graphics region.

You can make a whole window invisible using SET_CONTROL_VISIBILITY@, so there is really no reason for not writing direct to a %gr region anyway, and only make the window invisible when you are sure that your code works.

Eddie

... and if you give the window the toolwindow property in %ww it won't show on the taskbar either.

E
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7924
Location: Salford, UK

PostPosted: Thu Dec 29, 2011 9:55 am    Post subject: Reply with quote

There is a sample program in the help file at Wn32 Platform->ClearWin+->Graphics->Offscreen graphics
Back to top
View user's profile Send private message AIM Address
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Thu Dec 29, 2011 11:29 am    Post subject: Reply with quote

Paul,

The example is using the offscreen graphics area as somewhere to prepare something so that it can be copied to the screen later, not as an area to prepare an image so that it can be written to a file (say at a specified resolution, larger than the screen) - I couldn't find any mention of that latter action either.

It looks to me as though Johannes is going to need to write his image to an invisible window first!

Eddie
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Thu Dec 29, 2011 12:52 pm    Post subject: Reply with quote

I have used a virtual screen to draw and dump to a .pcx, .jpg or .gif file.

I'd suggest:
1) use different handles for the %gr and virtual screen, say w_handle =1 and v_handle = 2, and give them a different value.
2) after %gr, call create_Graphics_region@ (v_handle... then select_graphics_region@ (v_handle.. to initiate the virtual window.
3) Proceed with your graphics drawing calls.
4) After drawing to the graphics region, call perform_graphics_update@ then export_image@ (or other suitable export routine)
5) finally, select the %gr screen and then delete the vitrual screen, using:
i = select_graphics_object@ (w_handle)
i = delete_graphics_region@ (v_handle)

This should produce your appropriate image in the selected export file.

My implementation encloses this in a menu system for easier control of the graphics, but %lw should work.

John
Back to top
View user's profile Send private message
johannes



Joined: 21 Jan 2011
Posts: 65
Location: Leimen, Germany

PostPosted: Thu Dec 29, 2011 2:56 pm    Post subject: Reply with quote

Hi guys,
before I test John's receipe, just a note about Paul's last suggestion to use the offscreen graphics demo.

When I delete all the winio lines and some others, the graphics is created silently in a bmp file. However, tha backgound color is always black.
Who knows how to make a white background here?

WINAPP
IMPLICIT NONE
INCLUDE <windows.ins>
INTEGER i,ictrl,width,depth,ierr,hdib
INTEGER g_handle,r_handle,white
PARAMETER (g_handle=7,r_handle=Cool
CALL set_rgb_colours_default@(1)
width=2.0*clearwin_info@('SCREEN_WIDTH')/3.0
depth=2.0*clearwin_info@('SCREEN_DEPTH')/3.0
white=RGB@(255,255,255)
!i=winio@('%ww%ca[Off-Screen Regions]&')
!i=winio@('%mn[&Exit]&','EXIT')
!i=winio@('%lw&',ictrl)
!i=winio@('%`gr[black]',width,depth,g_handle)
ierr=create_graphics_region@(r_handle,width,depth)
ierr=select_graphics_object@(r_handle)
! the next statement does not change the background color from black to white
CALL SET_CONTROL_BACK_COLOUR@(r_HANDLE,RGB@(255,255,255))
!hdib=import_bmp@('setup.bmp',ierr)
!ierr=dib_paint@(0,0,hdib,0,0)
!CALL release_screen_dib@(hdib)
CALL draw_characters@('This was drawn off screen',&
100,100,white)
CALL draw_filled_ellipse@(200,150,75,50,RGB@(255,0,0))
!ierr=select_graphics_object@(g_handle)
!CALL draw_characters@('This was drawn to a window',&
! 100,100,white)
!i=winio@('%bt[Show Off-Screen Block]')
!ierr=copy_graphics_region@(g_handle,0,0,width,depth,&
! r_handle,0,0,width,depth,SRCCOPY)
i= EXPORT_IMAGE@( 'filename.bmp' )
END
Back to top
View user's profile Send private message
johannes



Joined: 21 Jan 2011
Posts: 65
Location: Leimen, Germany

PostPosted: Thu Dec 29, 2011 3:02 pm    Post subject: Re: Reply with quote

But any %gr opens up a window, what I do not want. Doesn't it?
Johannes

JohnCampbell wrote:
I have used a virtual screen to draw and dump to a .pcx, .jpg or .gif file.

I'd suggest:
1) use different handles for the %gr and virtual screen, say w_handle =1 and v_handle = 2, and give them a different value.
2) after %gr, call create_Graphics_region@ (v_handle... then select_graphics_region@ (v_handle.. to initiate the virtual window.
3) Proceed with your graphics drawing calls.
4) After drawing to the graphics region, call perform_graphics_update@ then export_image@ (or other suitable export routine)
5) finally, select the %gr screen and then delete the vitrual screen, using:
i = select_graphics_object@ (w_handle)
i = delete_graphics_region@ (v_handle)

This should produce your appropriate image in the selected export file.

My implementation encloses this in a menu system for easier control of the graphics, but %lw should work.

John
Back to top
View user's profile Send private message
johannes



Joined: 21 Jan 2011
Posts: 65
Location: Leimen, Germany

PostPosted: Thu Dec 29, 2011 8:12 pm    Post subject: Re: Reply with quote

Hi all,
probably the simplest solution is to draw a white rectangle before all other drawing routines: CALL draw_filled_rectangle@(0,0,width,depth,RGB@(255,255,255))

Now my final core routine based on 'off screen graphics demo' seems to work:

WINAPP
IMPLICIT NONE
INCLUDE <windows.ins>
INTEGER i,width,depth
INTEGER r_handle
PARAMETER (r_handle=7)
CALL set_rgb_colours_default@(1)
width=2.0*clearwin_info@('SCREEN_WIDTH')/3.0
depth=2.0*clearwin_info@('SCREEN_DEPTH')/3.0
i=create_graphics_region@(r_handle,width,depth)
i=select_graphics_object@(r_handle)
! next is to create a white background
CALL draw_filled_rectangle@(0,0,width,depth,RGB@(255,255,255))
! now all other plotting calls
CALL draw_characters@('This was drawn off creen',100,100,RGB@(0,0,0))
CALL draw_filled_ellipse@(200,150,75,50,RGB@(255,0,0))
! etc etc
i= EXPORT_IMAGE@( 'filename.bmp' )
END

Thanks to all who contributed.
Back to top
View user's profile Send private message
johannes



Joined: 21 Jan 2011
Posts: 65
Location: Leimen, Germany

PostPosted: Fri Dec 30, 2011 11:13 am    Post subject: Re: Reply with quote

SET_CONTROL_VISIBILITY@ always responded with a handle error/problem, regardless where called in the test program (think so).
Johannes

LitusSaxonicum wrote:
Hi Johannes,

Drawing graphics to invisible regions is pretty difficult to debug! Maybe the development stage is best done with a visible (i.e. %gr) region.

My understanding of CREATE_GRAPHICS_REGION@ (and related routines) is that they imagine that once you have an image, you copy it to a %gr region so that the user can see it. Certainly the documentation for EXPORT_IMAGE@ says that it is for exporting a %gr to a file, not from some internal graphics region.

You can make a whole window invisible using SET_CONTROL_VISIBILITY@, so there is really no reason for not writing direct to a %gr region anyway, and only make the window invisible when you are sure that your code works.

Eddie

... and if you give the window the toolwindow property in %ww it won't show on the taskbar either.

E
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7924
Location: Salford, UK

PostPosted: Fri Dec 30, 2011 1:35 pm    Post subject: Reply with quote

For SET_CONTROL_VISIBILITY@ you will need a handle that you obtain using %lc (or %hw). For %gr you would put %lc after %gr and before the percent (%) for the next control.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+ All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group