Here is the code:
Code: Select all
Global gdiplusToken.l,ImageObject.l,ImageWidth.l,ImageHeight.l,GraphicObject.l,IsInit.l,but.l,myimg.l
#GDIPlusDll = 0
Structure GdiplusStartupInput
GdiplusVersion.l
DebugEventCallback.l
SuppressBackgroundThread.l
SuppressExternalCodecs.l
EndStructure
Procedure.l gdipLoadImage(Image.s)
Protected RetVal.l,Bitmap.l
RetVal = 0
FileWSize = (Len(Image)*2)+2
*FileW = CallFunction(#GDIPlusDll,"GdipAlloc",FileWSize)
MultiByteToWideChar_(0, 0, Image, -1, *FileW, FileWSize)
CallFunction(#GDIPlusDll,"GdipCreateBitmapFromFile",*FileW,@Bitmap)
CallFunction(#GDIPlusDll,"GdipFree",*FileW)
If Bitmap
RetVal = Bitmap
EndIf
ProcedureReturn RetVal
EndProcedure
Procedure.l InitGDIPlus()
If OpenLibrary(#GDIPlusDll,"GDIPlus.DLL")
gdpsi.GdiplusStartupInput
gdpsi\GdiplusVersion = 1
gdpsi\DebugEventCallback = 0
gdpsi\SuppressBackgroundThread = 0
gdpsi\SuppressExternalCodecs = 0
CallFunction(#GDIPlusDll,"GdiplusStartup",@gdiplusToken,@gdpsi,0)
RetVal = gdiplusToken
Else
RetVal = 0
EndIf
ProcedureReturn RetVal
EndProcedure
Procedure ExecuteGDIPlus(file.s)
gdiplusToken = InitGDIPlus()
If gdiplusToken
ImageObject = gdipLoadImage(file)
CallFunction(#GDIPlusDll,"GdipImageSelectActiveFrame",ImageObject,?MultiPageGUID,0) ;just looking at the first page
CallFunction(#GDIPlusDll,"GdipGetImageWidth",ImageObject,@ImageWidth)
CallFunction(#GDIPlusDll,"GdipGetImageHeight",ImageObject,@ImageHeight)
CallFunction(#GDIPlusDll,"GdipCreateFromHWND",WindowID(),@GraphicObject)
IsInit = 1
;RepaintImage()
EndIf
EndProcedure
Procedure DisplayTiff(Bitmap.l)
RetVal = 0
If CreateImage(0,ImageWidth,ImageHeight)
IDC = StartDrawing(ImageOutput())
If CallFunction(#GDIPlusDll,"GdipCreateFromHDC",IDC,@GraphicObject1) = 0
If CallFunction(#GDIPlusDll,"GdipDrawImageI",GraphicObject1,Bitmap,0,0) = 0
If CallFunction(#GDIPlusDll,"GdipDeleteGraphics",GraphicObject1) = 0
StopDrawing()
ResizeImage(0,380,455)
;ResizeImage(0,ImageWidth/5,ImageHeight/5)
SetGadgetState(myimg,UseImage(0))
RetVal = 1
FreeImage(0)
EndIf
EndIf
EndIf
EndIf
ProcedureReturn RetVal
EndProcedure
If OpenWindow(0,0,0,400,500,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"View Tiff images with GDIPlus") And CreateGadgetList(WindowID(0))
img = CreateImage(#PB_Any,50,50)
myimg = ImageGadget(#PB_Any,10,10,620,460,UseImage(img))
but = ButtonGadget(#PB_Any,170,475,60,18,"Load Tiff")
EndIf
Repeat
EventID.l = WaitWindowEvent()
If EventID = #PB_Event_Gadget
If EventGadgetID() = but
myfile$ = OpenFileRequester("Please choose a tiff file", "", "Tiff files (*.tif)|*.tif","")
If myfile$
ExecuteGDIPlus(myfile$)
DisplayTiff(ImageObject)
EndIf
EndIf
EndIf
Until EventID = #PB_Event_CloseWindow
DataSection
MultiPageGUID:
Data.l $7462DC86
Data.w $6180,$4C7E
Data.b $8E,$3F,$EE,$73,$33,$A7,$A4,$83
EndDataSection
Every tiff file I have tried shows the border but here is the multipage tiff file I used in the example:
MultiFrame.tif

