'
'
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Drawing
Imports System.Runtime.InteropServices
Imports Matrox.MatroxImagingLibrary
Namespace MDispOverlay
Friend Class Program
Private Const IMAGE_FILE As String = MIL.M_IMAGE_PATH & "Board.mim"
Private Const WINDOW_TITLE As String = "Custom Title"
Shared Sub Main(ByVal args() As String)
Dim MilApplication As MIL_ID = MIL.M_NULL
Dim MilSystem As MIL_ID = MIL.M_NULL
Dim MilDisplay As MIL_ID = MIL.M_NULL
Dim MilDigitizer As MIL_ID = MIL.M_NULL
Dim MilImage As MIL_ID = MIL.M_NULL
MIL.MappAllocDefault(MIL.M_DEFAULT, MilApplication, MilSystem, MilDisplay, CType(MIL.M_NULL, IntPtr), CType(MIL.M_NULL, IntPtr))
If MIL.MsysInquire(MilSystem, MIL.M_DIGITIZER_NUM, MIL.M_NULL) > 0 Then
MIL.MdigAlloc(MilSystem, MIL.M_DEFAULT, "M_DEFAULT", MIL.M_DEFAULT, MilDigitizer)
MIL.MbufAllocColor(MilSystem, MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_BAND, MIL.M_NULL), MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_X, MIL.M_NULL), MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_Y, MIL.M_NULL), 8 + MIL.M_UNSIGNED, MIL.M_IMAGE + MIL.M_DISP + MIL.M_PROC + MIL.M_GRAB, MilImage)
MIL.MbufClear(MilImage, 0)
Else
MIL.MbufRestore(IMAGE_FILE, MilSystem, MilImage)
End If
MIL.MdispControl(MilDisplay, MIL.M_TITLE, WINDOW_TITLE)
MIL.MdispSelect(MilDisplay, MilImage)
OverlayDraw(MilDisplay)
If MilDigitizer <> MIL.M_NULL Then
MIL.MdigGrabContinuous(MilDigitizer, MilImage)
End If
Console.Write(Constants.vbLf + "OVERLAY ANNOTATIONS:" + Constants.vbLf)
Console.Write("--------------------" + Constants.vbLf + Constants.vbLf)
Console.Write("Displaying an image with overlay annotations." + Constants.vbLf)
Console.Write("Press <Enter> to continue." + Constants.vbLf + Constants.vbLf)
Console.ReadKey()
If MilDigitizer <> MIL.M_NULL Then
MIL.MdigHalt(MilDigitizer)
MIL.MdigFree(MilDigitizer)
Console.Write("Displaying the last grabbed image." + Constants.vbLf)
Console.Write("Press <Enter> to end." + Constants.vbLf + Constants.vbLf)
Console.ReadKey()
End If
MIL.MbufFree(MilImage)
MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL)
End Sub
Private Shared Sub OverlayDraw(ByVal MilDisplay As MIL_ID)
Dim DefaultGraphicContext As MIL_ID = MIL.M_DEFAULT
Dim MilOverlayImage As MIL_ID = MIL.M_NULL
Dim ImageWidth, ImageHeight As MIL_INT
Dim hCustomDC As IntPtr = IntPtr.Zero
MIL.MdispControl(MilDisplay, MIL.M_OVERLAY, MIL.M_ENABLE)
MIL.MdispInquire(MilDisplay, MIL.M_OVERLAY_ID, MilOverlayImage)
MIL.MdispControl(MilDisplay, MIL.M_OVERLAY_CLEAR, MIL.M_DEFAULT)
MIL.MdispControl(MilDisplay, MIL.M_OVERLAY_SHOW, MIL.M_DISABLE)
ImageWidth = MIL.MbufInquire(MilOverlayImage, MIL.M_SIZE_X, MIL.M_NULL)
ImageHeight = MIL.MbufInquire(MilOverlayImage, MIL.M_SIZE_Y, MIL.M_NULL)
MIL.MgraControl(DefaultGraphicContext, MIL.M_BACKGROUND_MODE, MIL.M_TRANSPARENT)
MIL.MgraColor(DefaultGraphicContext, MIL.M_COLOR_WHITE)
MIL.MgraText(DefaultGraphicContext, MilOverlayImage, ImageWidth / 9, ImageHeight / 5, " -------------------- ")
MIL.MgraText(DefaultGraphicContext, MilOverlayImage, ImageWidth / 9, ImageHeight / 5 + 25, " - MIL Overlay Text - ")
MIL.MgraText(DefaultGraphicContext, MilOverlayImage, ImageWidth / 9, ImageHeight / 5 + 50, " -------------------- ")
MIL.MgraColor(DefaultGraphicContext, MIL.M_COLOR_GREEN)
MIL.MgraText(DefaultGraphicContext, MilOverlayImage, ImageWidth * 11 / 18, ImageHeight / 5, " ---------------------")
MIL.MgraText(DefaultGraphicContext, MilOverlayImage, ImageWidth * 11 / 18, ImageHeight / 5 + 25, " - MIL Overlay Text - ")
MIL.MgraText(DefaultGraphicContext, MilOverlayImage, ImageWidth * 11 / 18, ImageHeight / 5 + 50, " ---------------------")
MIL.MdispControl(MilDisplay, MIL.M_OVERLAY_SHOW, MIL.M_ENABLE)
MIL.MappControl(MIL.M_ERROR, MIL.M_PRINT_DISABLE)
MIL.MbufControl(MilOverlayImage, MIL.M_DC_ALLOC, MIL.M_DEFAULT)
hCustomDC = CType(MIL.MbufInquire(MilOverlayImage, MIL.M_DC_HANDLE, MIL.M_NULL), IntPtr)
MIL.MappControl(MIL.M_ERROR, MIL.M_PRINT_ENABLE)
If (Not hCustomDC.Equals(IntPtr.Zero)) Then
Using DrawingGraphics As Graphics = Graphics.FromHdc(hCustomDC)
Using DrawingPen As New Pen(Color.Blue)
DrawingGraphics.DrawLine(DrawingPen, 0, CInt(Fix(ImageHeight / 2)), ImageWidth, CInt(Fix(ImageHeight / 2)))
DrawingGraphics.DrawLine(DrawingPen, CInt(Fix(ImageWidth / 2)), 0, CInt(Fix(ImageWidth / 2)), ImageHeight)
Using LeftBrush As New SolidBrush(Color.Red)
Using RightBrush As New SolidBrush(Color.Yellow)
Using OverlayFont As New Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold)
Dim GDITextSize As SizeF = DrawingGraphics.MeasureString("GDI Overlay Text", OverlayFont)
DrawingGraphics.DrawString("GDI Overlay Text", OverlayFont, LeftBrush, System.Convert.ToInt32(CSng(ImageWidth) / 4 - GDITextSize.Width / 2), System.Convert.ToInt32(CSng(ImageHeight) * 3 / 4 - GDITextSize.Height / 2))
DrawingGraphics.DrawString("GDI Overlay Text", OverlayFont, RightBrush, System.Convert.ToInt32(CSng(ImageWidth) * 3 / 4 - GDITextSize.Width / 2), System.Convert.ToInt32(CSng(ImageHeight) * 3 / 4 - GDITextSize.Height / 2))
End Using
End Using
End Using
End Using
End Using
MIL.MbufControl(MilOverlayImage, MIL.M_DC_FREE, MIL.M_DEFAULT)
MIL.MbufControl(MilOverlayImage, MIL.M_MODIFIED, MIL.M_DEFAULT)
End If
End Sub
End Class
End Namespace