Silverfrost Forums

Welcome to our forums

Export image of %pl or %dw

17 Jun 2014 9:19 #14219

Greetings,

I have an application using Simpleplot and would like to export the plots preferably as PNG, or any other format, whatever is possible. I tried using create_graphics_region@/select_graphics_object@ in combination with export_image@, but I couldn't get any useful results. Is it even possible to export from Simpeplot, and if so, how?

17 Jun 2014 11:17 #14221

create_graphics_region@ and select_graphics_object@ relate to %gr only.

If you only need to do this a few times for your own use then just use the Print Screen key on the keyboard and paste in Microsoft Paint.

17 Jun 2014 12:00 #14222

Unfortunately I'd need an automated way of exporting the plot. So you say it's not possible?

17 Jun 2014 2:42 #14224

I cannot think of a way to do this. Maybe you should try using %gr instead of %pl.

There will be lots of alternatives and perhaps others can advise.

17 Jun 2014 4:01 #14226

You have two options using the Simpleplot subroutine DEVNAM (=device name):

  1. if you like to use %pl, use it but with [user_drawn] option and Simpleplot_redraw@ subroutine Program simple5 use mswin INTEGER winio@,i,StartCB EXTERNAL StartCB i=winio@('%sy[no_border]%ca[User drawn]&') i=winio@('%pl[user_drawn]&',800,800) i=winio@('%sc',StartCB) END !--The start-up callback INTEGER FUNCTION StartCB() use mswin INTEGER N,i PARAMETER(N=101) REAL x(N),y(N) !--Create the data. DO i=1,N x(i)=i-1 y(i)=x(i)2 ENDDO !--Call SIMPLEPLOT routines to plot the graph. call devnam('windows_metafile')!shows in screen and creates a wmf file call picpos(4.0,5.0) ! locate the graph in the page so that everything enters CALL TITLE7('centre','Centre','Sample for Dan') CALL SCALES(0.0,10.0,1,0.0,100.0,1) call thckmg('LINE',1.0) !thickness of lines CALL NEWPIC CALL TITLE7('t','Centre','Sample') call textmg(1.5) !size of the text call axsbtk('XC','I') !ticks inside for x axis call axsbtk('YC','O') ! ticks outside for y axis CALL AXLBJS('', 'Centre') ! labels centred call chset(8) ! character set call cvtype(ctype) ! curve type call thckmg('LINE',3.0) !thickness of lines call pen(4) !pen colour CALL AXIS7('XCartesian','x-axis') CALL AXIS7('YCartesian',' ') CALL AXLOCN('YCartesian', 'Following') ! locate a new y axis on right call axlban('yc','O') ! tick labels towards the outside call axsbtk('yc','O') !ticks outside for y axis on the right !call axclr('yc',1)! only axis is drawn without ticks if you prefer CALL AXIS7('YCartesian','y-axis') call axis7('YC',' ') ! draw the new y axis without title
    CALL AXLOCN('XCartesian', 'Following') !locate a new x axis on top call axlban('xc','N') ! no tick labels
    call axsbtk('xc','I') ! ticks inside call axis7('XC',' ') ! no axis label
    call thckmg('L',1.0) !line thickness = 1 call pen(2)! colour red CALL BRKNCV(x,y,N,-1) CALL SIMPLEPLOT_REDRAW@ StartCB=1 END
  1. or use Simpleplot routines directly

    program Simpleplot_plots !requires simpleplot.dll implicit none real4,dimension(70) ::xarr,yarr integer4 :: narr,ltype,xscale,yscale integer4 :: ctype,i,ans character(8) :: xlabel='x',ylabel='y' real4 :: minx,maxx,miny,maxy narr=0 do i=1,70 xarr(i)=2i yarr(i)=ii narr=narr+1 end do !call devnam('window') !screen only !call devnam('windows_printer')! prints directly to the default printer !call devnam('windows_metafile')!shows in screen and creates a wmf file call textmg(1.5) call axsbtk('XC','I') call axsbtk('YC','O') call thckmg('L',2.0) CALL AXLBJS('**', 'Centre') minx=minval(xarr) maxx=maxval(xarr) miny=minval(yarr) maxy=maxval(yarr) xscale=1;yscale=1 CALL SCALES(minx,maxx,xscale,miny,maxy,yscale) call axcrss('YC',minx) call pen(2) ltype=0 ctype=3 call chset(ans) call cvtype(ctype) CALL AXES7(xlabel, ylabel) call pen(1) call title7('t','c','A Simple......Plot') call pen(4) CALL BRKNCV(real(xarr,1),real(yarr,1),narr,ltype) call endplt end program simpleplot_plots

Hope this helps,

Agustin

17 Jun 2014 11:48 #14228

Thank you very much aebolzan, this seems to be exactly what I'm looking for. I'll try it out.

18 Jun 2014 9:21 #14229

Quoted from PaulLaidler I cannot think of a way to do this. Maybe you should try using %gr instead of %pl.

If you can get a handle for the %pl window, you could probably get a snapshot from the window using something like (untested code and in MiniBASIC-syntax):

HDC hdc = GetWindowDC(hwnd)
if hdc
  HDC hdcMem = CreateCompatibleDC(hdc)
  if hdcMem
    RECT rc
    GetWindowRect(hwnd, &rc)

    HBITMAP hbitmap = CreateCompatibleBitmap(hdc, rc.right, rc.bottom)
    if hbitmap
      SelectObject(hdcMem, hbitmap)
      PrintWindow(hwnd, hdcMem, 0)

      ' Here do something with the bitmap or memory device context
      ' Save bitmap into file maybe?

      DeleteObject(hbitmap)
    endif
    DeleteObject(hdcMem)
  endif
  ReleaseDC(hwnd, hdc)
endif
Please login to reply.