Using FreeImage to fit a PNG file in an image control

Hi,

As I am using clarion 6.3 and it does not support PNG display. I tried using the FreeImage examples (because I did not find a documentation for using clarion with FreeImage ) but there was always a problem with aspect ratio or the height and width which exceed the control limits.

Any suggestions are appreciated.

Regards

Larry Sand created ClarionFreeImage. Have you looked at that?

http://www.clarionfreeimage.com/

Mark Riffey created this repo for it, as well. GitHub - mriffey/ClarionFreeImage: A backup of Larry Sand's Clarion Free Image product

GDI+ is much simplier:

  PROGRAM

  INCLUDE('gdiplus.inc'), ONCE

  MAP
  END

Window                        WINDOW('PNG image in C6'),AT(,,208,120),CENTER,GRAY,SYSTEM
                                IMAGE,AT(9,14,64,59),USE(?IMAGE1)
                              END

bm                            TGdiPlusBitmap
sBits                         &STRING, AUTO
  CODE
  OPEN(Window)
  
  bm.FromFile('CristmasTree.png')
  sBits &= bm.ToString('image/bmp')
  ?IMAGE1{PROP:ImageBits} = sBits
  DISPOSE(sBits)
  
  ACCEPT
  END
1 Like

Hello,

I tried the code but I am getting this error about “ToString” : Unknown function label.

I checked the class but could not find it there. Am I missing something?

Regards

Perhaps you have outdated classes.

This is the one I have:

!* GdiPlus support
!* mikeduglas 2022
!* [email protected]

INCLUDE(‘svapi.inc’), ONCE
INCLUDE(‘gdiplustypes.inc’), ONCE

TGdiPlusImage CLASS, TYPE, MODULE(‘gdiplus.clw’), LINK(‘gdiplus.clw’)
nativeImage LONG, PROTECTED !- GpImage*
lastResult GpStatus, PROTECTED

Construct PROCEDURE()
Destruct PROCEDURE(), VIRTUAL

GetLastStatus PROCEDURE(), GpStatus

FromFile PROCEDURE(STRING pFileName, BOOL pUseICM=FALSE), GpStatus, PROC
FromString PROCEDURE(STRING pImageData, BOOL pUseICM=FALSE), GpStatus, PROC
DisposeImage PROCEDURE(), GpStatus, PROC
!!!

Gets the width, in pixels, of this image.
GetWidth PROCEDURE(), ULONG
!!!Gets the height, in pixels, of this image.
GetHeight PROCEDURE(), ULONG
!!!Gets the horizontal resolution, in dots per inch, of this image.
GetHorizontalResolution PROCEDURE(), SREAL
!!!Gets the vertical resolution, in dots per inch, of this image.
GetVerticalResolution PROCEDURE(), SREAL
!Clone PROCEDURE(), *TGdiPlusImage
!ToFile PROCEDURE(STRING pFileName), GpStatus, PROC
!GetType PROCEDURE(), GpImageType
!GetPhysicalDimension PROCEDURE(*GpSizeF pSize), GpStatus, PROC
!GetBounds PROCEDURE(*GpRectF pRect, *GpUnit pUnit), GpStatus, PROC
END

TGdiPlusBitmap CLASS(TGdiPlusImage), TYPE, MODULE(‘gdiplus.clw’), LINK(‘gdiplus.clw’)
GetHBITMAP PROCEDURE(ULONG pBackground), HBITMAP
END

I just downloaded the latest one.

thank you

I updated everything and it all ran smooth.

Thanks a lot and best regards

interested in your PDF reader and writer classes. you dont appear to be taking messages the moment .

mIss attending the ballet in Moscow…

Hello Mike,

Using:

  bm.FromFile('CristmasTree.png')
  sBits &= bm.ToString('image/bmp')
  ?IMAGE1{PROP:ImageBits} = sBits
  DISPOSE(sBits)

Works great but what if I need to scale a large image down to fit inside the IMAGE control?

Thanks!!!

Don,

IMAGE control iteslf scales the images, so same code should work, if I understood you correctly.

Say the IMAGE control is 500x500 and the image is 2000x2000.

Currently the large image loads and most of it is not visible. I would like the image to be scaled so that the entire image is visible in the image control.

Thank you!

Your image probably has extra attributes set like CENTERED or HVSCROLL, try just IMAGE,AT(10,10,110,110),USE(?IMAGE1)

Yes sir. I did. But the PROP:VSCROLL isn’t working for some reason.

Not an emergency for me. Just playing around with your code.

:slightly_smiling_face:

If you really want to get resized image, then several ways exist. You can clone the image, or you can create an image with desired size and draw original image on it, you can ask google :slight_smile:

1 Like

Sorry, Clone isn’t for resizing. The simplest way is

  1. Load original bitmap: bm1.FromFile(‘image.png’)
  2. Create new bitmap: bm2.CreateBitmap(1000, 1000, format)
  3. Create Graphics object over bitmap2: g.FromImage(bm2)
  4. Draw 1 on 2: g.DrawImage(bm1, 0, 0, 1000, 1000)
2 Likes

Nice!

Looking forward to digging deeper into GDI+.

Thank you!!

Revisiting this.

SetDiagramImage ROUTINE bm1.FromFile(PGP:DIAGRAM_IMAGE) Debug(bm.GetWidth() & ' x ' & bm.GetHeight()) bm2.CreateBitmap(?Diagram_Image{PROP:Width},?Diagram_Image{PROP:Height}, format)

sBits &= bm2.ToString(‘image/bmp’)
?Diagram_Image{PROP:ImageBits} = sBits
DISPOSE(sBits)

I am not sure how to copy the image and then scale and crop from bm1 to bm2 and then display to the IMAGE control,

Any help would be appreciated.

Ron

Create Graphics object over bm2: g.FromImage(bm2) then draw on it what you need.

Also keep in mind that TGdiPlusBitmap.CreateBitmap expects width and height parameters in pixels, while ?Image{PROP:Width} and ?Image{PROP:Height} by default return the values in dialog units.