Silverfrost Forums

Welcome to our forums

How to create a graphics without showing on the screen?

28 Dec 2011 9:39 #9403

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

28 Dec 2011 10:07 #9405

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.

28 Dec 2011 12:12 #9406

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

28 Dec 2011 3:49 #9407

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

29 Dec 2011 8:55 #9409

There is a sample program in the help file at Wn32 Platform->ClearWin+->Graphics->Offscreen graphics

29 Dec 2011 10:29 #9410

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

29 Dec 2011 11:52 #9411

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

29 Dec 2011 1:56 #9412

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=8)
  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]&amp;')
  !i=winio@('%mn[&amp;Exit]&amp;','EXIT')
  !i=winio@('%lw&amp;',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',&amp;
                  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',&amp;
  !                100,100,white)
  !i=winio@('%bt[Show Off-Screen Block]')
  !ierr=copy_graphics_region@(g_handle,0,0,width,depth,&amp;
  !                  r_handle,0,0,width,depth,SRCCOPY)
  i= EXPORT_IMAGE@( 'filename.bmp' ) 
  END
29 Dec 2011 2:02 #9413

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

Quoted from JohnCampbell 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

29 Dec 2011 7:12 #9414

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.0clearwin_info@('SCREEN_WIDTH')/3.0 depth=2.0clearwin_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.

30 Dec 2011 10:13 #9420

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

Quoted from LitusSaxonicum 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

30 Dec 2011 12:35 #9422

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.

Please login to reply.