CadImage.dll SetDefaultColor - Function

Discuss and ask questions about CAD DLL (CAD Image DLL, CAD Importer DLL).

Moderators: SDS, support, admin

Post Reply
Thomas
Posts: 2
Joined: 29 Jun 2006, 15:47
Location: Germany

CadImage.dll SetDefaultColor - Function

Post by Thomas » 29 Jun 2006, 15:50

Hello,

IÒ‘m testing your CadImage.dll example program that iÒ‘ve downloaded from your website (http://www.cadsofttools.com/download/cadimage.zip). Im developing in VB.net so iÒ‘ve picked the demovb.net projekt. Loading DWG-files and saving as Bitmap works fine. IÒ‘ve tried a simple modifiaction to change the DefaultColor. Therefore iÒ‘ve added following code to the imports list:

Code: Select all

<DllImport("cadimage.dll", _
    SetLastError:=<b>True</b>, CharSet:=CharSet.Ansi, _
    ExactSpelling:=<b>True</b>, _
    CallingConvention:=CallingConvention.StdCall)> _
    <b>Public Shared Function</b> SetDefaultColor(<b>ByVal</b> hObject <b>As</b> IntPtr, <b>ByVal</b> ADefaultColor <b>As</b> System.Drawing.Pen) <b>As Integer
  End Function</b>
IÒ‘ve also modified the function that saves the Bitmap:

Code: Select all

  <b>Private</b> Sub MenuItem11_Click(<b>ByVal</b> sender <b>As</b> System.Object, <b>ByVal</b> e <b>As</b> System.EventArgs) <b>Handles</b> MenuItem11.Click
        <b>Dim</b> CrDraw <b>As</b> CADDRAW = <b>New CADDRAW</b>
        <b>Dim</b> K <b>As Single</b>
        <b>Dim</b> AbsWidth <b>As Single</b>
        <b>Dim</b> AbsHeight <b>As Single</b>
        CD.FileName = ""
        CD.Filter = "Bmp files (bmp)|*.bmp"
        CD.ShowDialog()
        GetBoxCAD(CADImage, AbsWidth, AbsHeight)
        <b>If</b> AbsWidth = 0 <b>Then</b>
            K = 1
        <b>Else</b>
            K = AbsHeight / AbsWidth
        <b>End If</b>
        CrDraw.Size = Len(CrDraw) 'size of CADDRAW
        CrDraw.R = <b>New</b> Rect
        GetClientRect(panel1, CrDraw.R)
        CrDraw.R.Bottom = CrDraw.R.Right * K
        CrDraw.R.Right = CrDraw.R.Right * FScale / 100
        CrDraw.R.Bottom = CrDraw.R.Bottom * FScale / 100
        CrDraw.DrawMode = 0 ' color mode

<b>    SetDefaultColor(CADImage, New Pen(Color.White))</b> 
       <b>Dim</b> i = SaveCADtoBitmap(CADImage, CrDraw, CD.FileName)
    <b>End Sub</b>
I changed the DefaultColor "white" and I guess IÒ‘ve got the right function, but the results are a little bit funny:

The first time I save the bitmap the color gets blue. The second time I save the bitmap it gets white. The third time I save the bitmap it gets turquise.

IÒ‘ve launched the compiled vbdemo.exe and try it again with the following results:
1. Call -> Color gets Brown
2. Call -> Color gets Green
3. Call -> Color gets Black

IÒ‘ve no idea how to fix this problem. Please help me.

support
Posts: 3254
Joined: 30 Mar 2005, 11:36
Contact:

Post by support » 30 Jun 2006, 18:07

Hello Tomas,

Please try the following construction:

Code: Select all

    <DllImport("Cadimage.dll", _
    SetLastError:=<b>True</b>, CharSet:=CharSet.Ansi, _
    ExactSpelling:=<b>True</b>, _
    CallingConvention:=CallingConvention.StdCall)> _
    <b>Public</b> Shared Function SetDefaultColor(<b>ByVal</b> hObject <b>As</b> IntPtr, <b>ByVal</b> ADefaultColor <b>As</b> Integer) <b>As Integer
    End Function</b>

    Private Sub MenuItem14_Click(<b>ByVal</b> sender <b>As</b> System.Object, <b>ByVal</b> e <b>As</b> System.EventArgs) <b>Handles</b> MenuItem14.Click
        <b>Dim</b> CrDraw <b>As</b> CADDRAW = <b>New</b> CADDRAW
        <b>Dim</b> K <b>As Single</b>
        <b>Dim</b> AbsWidth <b>As Single</b>
        <b>Dim</b> AbsHeight <b>As Single</b>
        CD.FileName = ""
        CD.Filter = "Bmp files (bmp)|*.bmp"
        CD.ShowDialog()
        GetBoxCAD(CADImage, AbsWidth, AbsHeight)
        <b>If</b> AbsWidth = 0 <b>Then</b>
            K = 1
        <b>Else</b>
            K = AbsHeight / AbsWidth
        <b>End If</b>
        CrDraw.Size = Len(CrDraw) 'size of CADDRAW
        CrDraw.R = <b>New</b> Rect
        GetClientRect(panel1, CrDraw.R)
        CrDraw.R.Bottom = CrDraw.R.Right * K
        CrDraw.R.Right = CrDraw.R.Right * FScale / 100
        CrDraw.R.Bottom = CrDraw.R.Bottom * FScale / 100
        CrDraw.DrawMode = 0 ' color mode

        SetDefaultColor(CADImage, ConvertColorToInt(Color.BlanchedAlmond))
        <b>Dim</b> i = SaveCADtoBitmap(CADImage, CrDraw, CD.FileName)
    <b>End Sub</b>

    <b>Public Function</b> ConvertColorToInt(ByVal sender As Color) <b>As Integer</b>
        <b>Dim</b> r, g, b, nColor <b>As Integer</b>
        r = sender.R
        g = sender.G
        b = sender.B
        nColor = (b << 16) + (g << 8) + r
        Return nColor
    <b>End Function</b>
<b>End Class</b>
Sergey.

please post questions to the forum or write to support@cadsofttools.com

Thomas
Posts: 2
Joined: 29 Jun 2006, 15:47
Location: Germany

Post by Thomas » 03 Jul 2006, 10:31

It worked!

Thanks a lot :-)

Post Reply