problems with Image() in wxPDFdocument

BlitzMax Modules Forums/Brucey's Modules/problems with Image() in wxPDFdocument

When I run this code I get an 'Unhandled Memory Exception' Error. But the pdfdocument.bmx in the samples folder runs fine. I just can't get my head around this :-(

SuperStrict

Import wx.wxPdfDocument
Import wx.wxApp
Import brl.filesystem

Extern "win32"
	'Function WinExec(lpCmdLine$z, nCmdShow)
	Function ShellExecuteA(hwnd:Int, op:Byte Ptr, file:Byte Ptr, param:Byte Ptr, dir:Byte Ptr, show:Int) 
End Extern

' run the test
test() 

Function test() 
	Local doc:wxPdfDocument = New wxPdfDocument.Create() 
	doc.AddPage() 
	doc.SetFont("Arial", "B", 24) 
	doc.Cell(0, 20, "Testing Image drawing", 0, 0, wxPDF_ALIGN_CENTER) 
	
	' image width
	Local w:Double = 25
	
	' image file name
	Local sImg:String = "apple.gif"

	' draw a testing rectangle - this works
	'doc.Rect((doc.GetPageWidth() - w) / 2, doc.GetY() + 20, w, w) 
	
	' check if the file exists
	If Not FileExists(sImg) 
		DebugLog "Can't find image file: " + sImg
	Else
		' draw an image which is located in the same folder as this testing file
		' this produces a 'Unhandled Memory Exception Error' in wxPDFdocument.bmx
		doc.Image(sImg, (doc.GetPageWidth() - w) / 2, doc.GetY() + 20, w) 
	End If
	
	' save the pdf file
	Local fn:String = "image-test.pdf"
	doc.SaveAsFile(fn) 
	
	' open the pdf file with the default reader
	ShellExecuteA(0, "open", "~q" + fn + "~q", "", Null, 1) 
End Function

Function FileExists:Int(fn:String) 
	If FileType(fn) = 1 Return True
	Return False
End Function


Thanx for any help!

Rather than running test() like that, you should probably do it from inside wxMax :
New MyApp.run()


Type MyApp Extends wxApp

	Method OnInit:Int()
		test()
	End Method
	
End Type


I imagine that wxWidgets has things it needs to initialize, and without kicking off a wxApp instance it never gets the chance to.

Oh, and interestingly, if your gif has alpha transparency Acrobat Reader won't show it (at least on my v7 it won't).

:o)

Wow!!! Thanx so much, it works now! Brucey, your support is just fantastic!

I've tried a gif with alpha and another with index transparency but my version of Acrobat Reader (v8) won't show any of them. PNG pics with alpha works fine.

Try a gif with no transparency at all - worked fine here.

Mind you, these days you probably want to stay away from gifs altogether. You can always convert them to something better ;-)

Yup, gif's with no transparency work ok but as you say, gif's are not worth the trouble anymore and I converted that beautiful green apple into a PNG32 file, drilled a big whole into it and alpha masked the shadow and it renders great in the pdf doc!

Nadia, you could, btw, use OpenURL() to open the PDF for you. This should work on Linux and Mac too.
...rather than tying yourself to platform specific code ;-)

Thanx for the tip about OpenURL()! The nice part about ShellExecuteA(), which I used in the code above is, that I can replace the "open" parameter with "print" and it will send my pdf file direct to the default printer (via Acrobat Reader). But yes, it is win32 specific code :-(