AVAX-software.com Forums: Retrieving an image from an AVX file - AVAX-software.com Forums

Jump to content

Page 1 of 1

Retrieving an image from an AVX file Can images added with Add_Picture be retrieved?

#1 User is offline   lib Icon

  • Newbie
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 11-May 07

Posted 11 July 2007 - 03:53 PM

Greetings,

I'm using the current Avax OCX version with VB.NET 2005 Express.

I usually store a background image, added with the Add_Picture method, inside my AVX files.

I know I can use SetHandleKey to be able to retrieve the handle associated to the image, but
how can I retrieve the full image from an AVX file as a stream|Bitmap object|file?

Thanks.

#2 User is offline   Athanasios Gardos Icon

  • Administrator
  • Icon
  • Group: Admin
  • Posts: 333
  • Joined: 21-March 05
  • Gender:Male

Posted 22 July 2007 - 12:21 PM

Have a look in the following VB6 source code:

Function GetShapeImage(hShape As Long) As Boolean
	Dim sXMLFile As String, sPicID As String, lPicID As Long
	Dim XMLDoc As MSXML2.DOMDocument30
	Dim root As MSXML2.IXMLDOMElement
	Dim nod As MSXML2.IXMLDOMNode
	Dim xmlList As MSXML2.IXMLDOMNodeList
	Dim bOk As Boolean, sData As String
	Dim iFr As Integer, sPicFile As String
	sXMLFile = App.Path & "\~temp.xml"
	sPicFile = App.Path & "\~temp.bmp"
	Call cAvax1.PrintToXML(sXMLFile)
	Set XMLDoc = New MSXML2.DOMDocument30
	bOk = XMLDoc.Load(sXMLFile)
	If Not bOk Then
		MsgBox "Error loading XML file.", vbCritical
		GoTo Lab_Exit
	End If
	Set root = XMLDoc.documentElement
	If Not root.selectSingleNode("Drawings/Drawing/Shape[@Handle='" & Format$(hShape) & "']") Is Nothing Then
	   sPicID = root.selectSingleNode("Drawings/Drawing/Shape[@Handle='" & Format$(hShape) & "']").Attributes.getNamedItem("FillPattern").nodeTypedValue
	   lPicID = root.selectSingleNode("Drawings/Drawing/Shape[@Handle='" & Format$(hShape) & "']").Attributes.getNamedItem("FillType").nodeTypedValue
	   sData = GetImageData(root, sPicID, lPicID)
	   If sData <> "" Then
		  iFr = FreeFile
		  Open sPicFile For Binary As #iFr
		  Put #iFr, , BytesFromHexString(sData)
		  Close #iFr
		  Picture1.Picture = LoadPicture(sPicFile)
		  GetShapeImage = True
	   End If
	End If
Lab_Exit:
	Set xmlList = Nothing
	Set root = Nothing
	Set XMLDoc = Nothing
End Function

Function GetImageData(root As MSXML2.IXMLDOMElement, sName As String, lType As Long) As String
	Dim nod As MSXML2.IXMLDOMNode
	On Local Error Resume Next
	If Not root.selectSingleNode("Images/Image[@Name='" & sName & "' and @Type='" & lType & "']") Is Nothing Then
	   GetImageData = root.selectSingleNode("Images/Image[@Name='" & sName & "' and @Type='" & lType & "']").Attributes.getNamedItem("Data").nodeTypedValue
	End If
End Function

Function BytesFromHexString(sString As String) As Byte()
	Dim I As Long, lCount As Long
	Dim myByte() As Byte
	ReDim myByte(Len(sString) / 2 - 1) As Byte
	For I = 1 To Len(sString) Step 2
		myByte(lCount) = Val("&H" & Mid$(sString, I, 2))
		lCount = lCount + 1
	Next I
	BytesFromHexString = myByte()
End Function

Athanasios Gardos
Avax-Software.com

Page 1 of 1


Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users