Wilfred,
You have provided a very useful example, which I have expanded to show a few more features that can be confusing.
Moving to a rank 3 allocatable array makes it easier to import a graphics file of general size, using GET_DIB_BLOCK@. Again I don't know what graphics formats are now supported, but if others aren't then we need to transfer via a graphics region.
You need to be careful with the start coordinates. I think they should be 0,0. You can blame a C programmer for this. The following will work, but if you use 1,1 it will not.
It is also useful to compare the different sizes of the resulting graphics files. In this case .png has the best compression.
winapp
program test3
implicit none
include <windows.ins>
integer*4 i,j,A,lins,cols
integer*4 x,y, HANDLE
real*8 r
character*1, dimension(:,:,:), allocatable :: image
character*1 :: red(3), blue(3), black(3)
! create 24-bit test image (replace by your own)
handle = 4
lins = 250
cols = 550
allocate ( image(3,cols,lins) )
!
red = char(1) ; red(1) = char(255)
blue = char(1) ; blue(3) = char(255)
black = char(1)
!
image = char(255) ! white
do y = 1,lins
image(:,1,y) = red
image(:,cols,y) = red
end do
do x = 1,cols
image(:,x,1) = blue
image(:,x,lins) = blue
end do
!
do y = 2,lins-1
do x = 2,cols-1
if (mod(y,50) .eq. 0 .or. mod(x,50) .eq. 0) image(:,x,y) = black
end do
end do
! off-screen graphics & export
j = create_graphics_region@ (handle,cols,lins)
j = select_graphics_object@ (handle)
!
call display_dib_block@ (0,0,image,cols,lins,0,0,cols,lins,0,0,i)
!
r = set_jpeg_quality@ (1.D0)
j = export_image@ ('c:\\temp\\test3.jpg') ! works
j = export_image@ ('c:\\temp\\test3.bmp') ! works
j = export_image@ ('c:\\temp\\test3.gif') ! works
j = export_image@ ('c:\\temp\\test3.png') ! does not work !!
j = delete_graphics_region@ (handle)
!
end