Image display Problem

aavioaavio Member Posts: 143
Hello,
I had created a com dll that converts text to image (bmp) file,i hav a function 'DrawText' to convert it.In the C/AL Symbol Menu functions argument is shown as [VARIANT DrawText :=]DrawText(BSTR My Text)

when i tried to assign SourceExpr of picture box as the same function, it doesnt works...(not the problm with dll thats sure)

I also tried to assign Output of function to a variant type,But variant datatype cant hold a blob datatype naa...then
how can i assign variant datatype to a Picture Box?? plz help :?
aav!o

Comments

  • XypherXypher Member Posts: 297
    Since you wrote a COM DLL just use a Stream and write to a temporary blob with it. :wink:

    There is a nice example of Streaming on the downloads section, but if you can't manage to get it to work let me know and I'll post some code. (Although the example in the downloads section is written in C# if I remember correctly; my example would be in VB.NET :?)
  • aavioaavio Member Posts: 143
    Thanks for ur reply,... :)

    sorry i didnt find any example with streaming....can u plz provide exact path.. :?:

    and also, iam calling this image convertion function from a report,... there i need to print it on...so in reports, blob global variables are not available. otherwise , i need to import these images to a table,but thr will be many images corresponding to a particular record, so if i could get a solution,that after converting to image and assigning it to a picture box that will be better.... do you hav a solution... [-o<
    aav!o
  • XypherXypher Member Posts: 297
    For now here is a link to the Stream example found in the Downloads section.

    "Access Navision Stream From DotNet" http://www.mibuso.com/dlinfo.asp?FileID=776

    What language have you programmed the COM dll in?

    I will have to test a little when I have some free time (lately which has been never); But I am sure you can pass a temporary table to a report. As far as sending a temp. table full of image BLOBs that will show up on the report, not sure. :?
  • XypherXypher Member Posts: 297
    Anyways,

    Here is my take on the COM <-> Navision stream handling (In VB.NET).

    Based on Alexey Pavlov's code provided by the above link.
    Imports System.IO
    Imports System.Text
    Imports System.Runtime.InteropServices
    Imports System.Runtime.InteropServices.ComTypes
    
    Friend Class Stream
      Private utf8 As New UTF8Encoding
    
      Public Function WriteToStream(ByVal StreamData As String, _
                                    <MarshalAs(UnmanagedType.AsAny)> ByVal ComObjOut As Object) As Integer
        Dim stream As IStream = TryCast(ComObjOut, IStream)
        Dim memStream As New MemoryStream
        Dim buffStreamData As Byte() = Nothing
        Dim buffStream As Byte() = New Byte(&HAFC8) {}
        Dim wBytes As IntPtr = IntPtr.Zero
        Dim _wBytes As Integer = 0
        Dim twBytes As Integer = 0
    
        If utf8.GetBytes(StreamData, 0, StreamData.Length, buffStreamData, 0) > 0 Then
          memStream.Write(buffStreamData, 0, buffStreamData.Length)
    
          wBytes = Marshal.AllocHGlobal(4)
    
          Do
            _wBytes = memStream.Read(buffStream, 0, buffStream.Length)
            Marshal.WriteInt32(wBytes, _wBytes)
            stream.Write(buffStream, _wBytes, wBytes)
            twBytes += _wBytes
          Loop While _wBytes > 0
    
          Marshal.FreeHGlobal(wBytes)
    
          Return twBytes
        Else
          Return -1
        End If
      End Function
    
      Public Function ReadFromStream(ByRef StreamData As String, _
                                     <MarshalAs(UnmanagedType.AsAny)> ByVal ComObjIn As Object) As Integer
        Dim stream As IStream = TryCast(ComObjIn, IStream)
        Dim memStream As New MemoryStream
        Dim buffStream As Byte() = New Byte(&HAFC8) {}
        Dim rBytes As IntPtr = IntPtr.Zero
        Dim _rBytes As Integer = 0
        Dim trBytes As Integer = 0
    
        rBytes = Marshal.AllocHGlobal(4)
    
        Try
          Do
            stream.Read(buffStream, buffStream.Length, rBytes)
            _rBytes = Marshal.ReadInt32(rBytes)
            memStream.Write(buffStream, 0, _rBytes)
            trBytes += _rBytes
          Loop While _rBytes > 0
        Finally
          Marshal.FreeHGlobal(rBytes)
        End Try
    
        If trBytes > 0 Then StreamData = utf8.GetString(memStream.ToArray)
    
        Return trBytes
      End Function
    End Class
    
Sign In or Register to comment.