Miglioramento gestione grafica
This commit is contained in:
@@ -13,11 +13,13 @@ Namespace My
|
||||
|
||||
Private Sub MyApplication_Startup(sender As Object, e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
|
||||
If e.CommandLine.Count > 0 Then
|
||||
' Args: "0 #n" -> 0: avvio in modalità nascosta, #n: indice tavola
|
||||
If e.CommandLine(0) = "0" Then
|
||||
ModalitaNascosta = True
|
||||
Else
|
||||
'
|
||||
' avviare il programma in modalità standard
|
||||
End If
|
||||
' Salvo l'inidice della tavola come indice di processo
|
||||
If e.CommandLine.Count > 1 Then MainModule.IndexProc = e.CommandLine(1)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Generated
+2
-1
@@ -431,6 +431,7 @@ Partial Class FrmMain
|
||||
'
|
||||
resources.ApplyResources(Me.ImageControl1, "ImageControl1")
|
||||
Me.ImageControl1.BackColor = System.Drawing.SystemColors.GrayText
|
||||
Me.ImageControl1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
|
||||
Me.ImageControl1.Image = Nothing
|
||||
Me.ImageControl1.initialimage = Nothing
|
||||
Me.ImageControl1.MouseEnabled = True
|
||||
@@ -438,7 +439,7 @@ Partial Class FrmMain
|
||||
Me.ImageControl1.Origin = New System.Drawing.Point(0, 0)
|
||||
Me.ImageControl1.PanButton = System.Windows.Forms.MouseButtons.Middle
|
||||
Me.ImageControl1.PanMode = True
|
||||
Me.ImageControl1.ScrollbarsVisible = True
|
||||
Me.ImageControl1.ScrollbarsVisible = False
|
||||
Me.ImageControl1.StretchImageToFit = False
|
||||
Me.ImageControl1.ZoomFactor = 1.0R
|
||||
Me.ImageControl1.ZoomOnMouseWheel = True
|
||||
|
||||
+147
-84
@@ -94,6 +94,9 @@ Public Class FrmMain
|
||||
BtnLoad.Visible = bBtnLoad
|
||||
BtnTakeFoto.Visible = True
|
||||
GBDefAree.Visible = False
|
||||
' Abilito la modifica della configurazione Cmaera/Cfg
|
||||
ComboBoxCameras.Enabled = True
|
||||
ComboBoxCameraCfg.Enabled = True
|
||||
Case en_status.ImageFromCamera
|
||||
GBCalibration.Visible = False
|
||||
GBCorrected.Visible = False
|
||||
@@ -101,6 +104,9 @@ Public Class FrmMain
|
||||
BtnLoad.Visible = bBtnLoad
|
||||
BtnTakeFoto.Visible = True
|
||||
GBDefAree.Visible = False
|
||||
' Abilito la modifica della configurazione Cmaera/Cfg
|
||||
ComboBoxCameras.Enabled = True
|
||||
ComboBoxCameraCfg.Enabled = True
|
||||
Case en_status.Calibration
|
||||
GBCalibration.Visible = True
|
||||
GBCorrected.Visible = False
|
||||
@@ -108,6 +114,9 @@ Public Class FrmMain
|
||||
BtnLoad.Visible = False
|
||||
BtnTakeFoto.Visible = False
|
||||
GBDefAree.Visible = False
|
||||
' Disabilito la modifica della configurazione Cmaera/Cfg
|
||||
ComboBoxCameras.Enabled = False
|
||||
ComboBoxCameraCfg.Enabled = False
|
||||
Case en_status.ImgCorrected
|
||||
GBCalibration.Visible = False
|
||||
GBCorrected.Visible = True
|
||||
@@ -115,6 +124,9 @@ Public Class FrmMain
|
||||
BtnLoad.Visible = bBtnLoad
|
||||
BtnTakeFoto.Visible = True
|
||||
GBDefAree.Visible = False
|
||||
' Disabilito la modifica della configurazione Cmaera/Cfg
|
||||
ComboBoxCameras.Enabled = False
|
||||
ComboBoxCameraCfg.Enabled = False
|
||||
Case en_status.DefAree
|
||||
GBCalibration.Visible = False
|
||||
GBCorrected.Visible = False
|
||||
@@ -128,6 +140,9 @@ Public Class FrmMain
|
||||
BtnSaveAree.Visible = False
|
||||
BtnExpT.Enabled = _visione.ExpCorrType <> clsVisione.eExpCorrMode.none
|
||||
BtnAbortDefAree.Text = "Close"
|
||||
' Disabilito la modifica della configurazione Cmaera/Cfg
|
||||
ComboBoxCameras.Enabled = False
|
||||
ComboBoxCameraCfg.Enabled = False
|
||||
Case en_status.DefTexp, en_status.DefStone, en_status.DefVentosa
|
||||
GBCalibration.Visible = False
|
||||
GBCorrected.Visible = False
|
||||
@@ -141,19 +156,22 @@ Public Class FrmMain
|
||||
BtnSaveAree.Visible = True
|
||||
BtnExpT.Enabled = _visione.ExpCorrType <> clsVisione.eExpCorrMode.none
|
||||
BtnAbortDefAree.Text = "Abort"
|
||||
' Disabilito la modifica della configurazione Cmaera/Cfg
|
||||
ComboBoxCameras.Enabled = False
|
||||
ComboBoxCameraCfg.Enabled = False
|
||||
End Select
|
||||
|
||||
PosizionaControlli()
|
||||
End Sub
|
||||
|
||||
' carico l'elenco delle camere collegate
|
||||
' carico l'elenco delle camere attivo la connessione con quella selezionata/impostata nel file di configurazione
|
||||
Private Sub LoadCamerasList()
|
||||
ComboBoxCameras.Items.Clear()
|
||||
Camera.CameraList()
|
||||
For i As Integer = 0 To Camera.m_idList.Count - 1
|
||||
ComboBoxCameras.Items.Add(Camera.m_idList(i))
|
||||
Next
|
||||
|
||||
' Connessione alla camera
|
||||
If Camera.m_idList.Count > 0 Then
|
||||
ComboBoxCameras.SelectedIndex = 0
|
||||
If Not ModalitaNascosta Then
|
||||
@@ -164,15 +182,8 @@ Public Class FrmMain
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Sub Inizializza()
|
||||
SetDataRoot()
|
||||
' non visualizzo pagina programma
|
||||
If Not ModalitaNascosta Then FrmStart.Show()
|
||||
|
||||
Application.DoEvents()
|
||||
|
||||
SpessLastra = 0
|
||||
|
||||
' carico elenco CONFIGURAZIONI: se non esiste almeno una valida comunico errore
|
||||
Private Function LoadCfgList() As Boolean
|
||||
Dim TempListIndCfg As New List(Of String)
|
||||
SearchConfigDir(TempListIndCfg)
|
||||
For i As Integer = 0 To TempListIndCfg.Count - 1
|
||||
@@ -185,10 +196,23 @@ Public Class FrmMain
|
||||
Dim sTextMsg As String = String.Format("Nella cartella '{0}' non sono state trovate configurazioni valide. " &
|
||||
"(CameraMng, CameraMng1, CameraMng2..)", sDataRoot)
|
||||
MessageBox.Show(sTextMsg, "Avvertenza", MessageBoxButtons.OK, MessageBoxIcon.Warning)
|
||||
Me.Close()
|
||||
'Return
|
||||
Return False
|
||||
End If
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Sub Inizializza()
|
||||
SetDataRoot()
|
||||
' non visualizzo pagina programma
|
||||
If Not ModalitaNascosta Then FrmStart.Show()
|
||||
|
||||
Application.DoEvents()
|
||||
|
||||
SpessLastra = 0
|
||||
|
||||
' se non esiste almeno una configurazione valida chiudo il programma
|
||||
If Not LoadCfgList() Then Me.Close()
|
||||
' leggo la prima configurazione valida (e ID della camera per creare la commessione)
|
||||
LeggiFileConfigurazione()
|
||||
AggiornaPulsantiVIsibili()
|
||||
MostraStato()
|
||||
@@ -204,8 +228,7 @@ Public Class FrmMain
|
||||
ProgressBar.Value = 0
|
||||
|
||||
SetFormStatus()
|
||||
' connessione automatica
|
||||
'Camera.Connect(Camera.CameraID)
|
||||
' carico elenco camere attive è creo la connessione
|
||||
LoadCamerasList()
|
||||
|
||||
'Me.Text = "ID Camera = " & Camera.CameraID
|
||||
@@ -224,6 +247,7 @@ Public Class FrmMain
|
||||
End If
|
||||
End Sub
|
||||
|
||||
' avvio l'evento di comunicazione con il programma OmagCUT
|
||||
Private Sub StartThreadCmdProcess()
|
||||
RaiseEvent _waitingCmd()
|
||||
End Sub
|
||||
@@ -338,8 +362,9 @@ Public Class FrmMain
|
||||
Next
|
||||
End Sub
|
||||
|
||||
' procedo alla lettura del file *.cfg
|
||||
Private Sub LeggiFileConfigurazione()
|
||||
Console.WriteLine("LETTURA CONFIGURAZIONE '../CameraMng" & MainModule.IndexProc.ToString())
|
||||
|
||||
If String.IsNullOrEmpty(m_sDataRoot) Then SetDataRoot()
|
||||
Dim NomeFileCfg, TmpString As String
|
||||
Dim DirToReadCfg As String
|
||||
@@ -348,16 +373,18 @@ Public Class FrmMain
|
||||
Dim reader As StreamReader
|
||||
Dim nfi As NumberFormatInfo = New CultureInfo("en-US", False).NumberFormat
|
||||
|
||||
' tutto parte dal file DataRoot.ini che deve trovarsi nella stessa
|
||||
' cartelle dell'eseguibile
|
||||
' tutto parte dal file DataRoot.ini che deve trovarsi nella stessa cartelle dell'eseguibile
|
||||
DirToReadCfg = m_sDataRoot
|
||||
' Indirizzo il programma al processo desiderato
|
||||
' Indirizzo il programma alla configurazione associata al processo (indice tavola)
|
||||
If Not ModalitaNascosta Then
|
||||
Dim sCfgSelected As String = ComboBoxCameraCfg.SelectedItem
|
||||
DirToReadCfg = DirToReadCfg & If(sCfgSelected = CFG_DEFAULT, "", sCfgSelected)
|
||||
Else
|
||||
DirToReadCfg = DirToReadCfg & MainModule.IndexProc.ToString()
|
||||
DirToReadCfg = DirToReadCfg & MainModule.IndexProc
|
||||
End If
|
||||
|
||||
Console.WriteLine("LETTURA CONFIGURAZIONE: " & MainModule.IndexProc & " -- " & DirToReadCfg)
|
||||
|
||||
Debug.Assert(DirToReadCfg <> "")
|
||||
NomeFileCfg = DirToReadCfg & "\CameraMng.cfg"
|
||||
|
||||
@@ -370,6 +397,7 @@ Public Class FrmMain
|
||||
Return
|
||||
End If
|
||||
|
||||
' ------- INIZIO LETTURA -------
|
||||
' default sovrascritti dalla letture del file cfg
|
||||
LensCalibType = 0
|
||||
SaveDir = "c:\CameraMng\Data\"
|
||||
@@ -548,6 +576,8 @@ Public Class FrmMain
|
||||
Return ret
|
||||
End Function
|
||||
|
||||
#Region "METODI FOTOCAMERA"
|
||||
|
||||
Private Sub CorrezioneCompleta()
|
||||
'ImageMng.CorrezioneCompletaAsync()
|
||||
ImageMng.CorrezioneCompleta()
|
||||
@@ -598,15 +628,16 @@ Public Class FrmMain
|
||||
|
||||
Private Sub SalvaNuovoBackGround()
|
||||
Dim backSaved As Boolean = False
|
||||
|
||||
RichiestaBackGround = False
|
||||
Try
|
||||
Console.WriteLine("BACKIMAGE PRONTA: " & MainModule.IndexProc & " Save dir -> " & SaveDir)
|
||||
_visione.BackImage = Nothing
|
||||
FileCopy(Camera.PhotoFileName, SaveDir & "BackImage.jpg")
|
||||
FileCopy(Camera.PhotoFileName, SaveDir & "BackImage" & Format(Now, "yyMMdd_HHmmss") & ".jpg")
|
||||
RichiestaBackGround = False
|
||||
'TODO qui sarebbe utile salvare i dati di scatto dell'immagine
|
||||
backSaved = True
|
||||
Catch ex As Exception
|
||||
Console.WriteLine("BACKIMAGE PRONTA: " & MainModule.IndexProc & " - ERRORE - " & ex.Message)
|
||||
End Try
|
||||
|
||||
Try
|
||||
@@ -623,6 +654,10 @@ Public Class FrmMain
|
||||
End Sub
|
||||
|
||||
Private Sub RilevaBordi(img As Bitmap)
|
||||
If Not File.Exists(SaveDir & "BackImage.jpg") Then
|
||||
Console.WriteLine("BACK IMAGE NON TROVATA: " & MainModule.IndexProc)
|
||||
Return
|
||||
End If
|
||||
_visione.BackImageFile = SaveDir & "BackImage.jpg"
|
||||
_visione.Image1 = img
|
||||
'_visione.TrovaBordi(2)
|
||||
@@ -664,6 +699,7 @@ Public Class FrmMain
|
||||
End Sub
|
||||
|
||||
Private Sub SetThreshold()
|
||||
Console.WriteLine("SET TRESHHOLD: " & MainModule.IndexProc)
|
||||
_ActTh = SogliaPercentuale * 2.55
|
||||
_ActTh = Math.Min(_ActTh, 255)
|
||||
VisualizzaThreshold()
|
||||
@@ -749,6 +785,8 @@ Public Class FrmMain
|
||||
End If
|
||||
End Sub
|
||||
|
||||
#End Region ' Metodi fotocamera
|
||||
|
||||
<DllImport("kernel32")>
|
||||
Private Shared Function GetPrivateProfileString(ByVal section As String, ByVal key As String, ByVal def As String, ByVal retVal As StringBuilder, ByVal size As Integer, ByVal filePath As String) As Integer
|
||||
End Function
|
||||
@@ -1001,6 +1039,87 @@ Public Class FrmMain
|
||||
|
||||
#Region "EVENTS"
|
||||
|
||||
' Preparo il programma
|
||||
Private Sub FrmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||
Dim strWinXP As String = ""
|
||||
|
||||
#If WinXp Then
|
||||
strWinXP = " (WinXP)"
|
||||
#End If
|
||||
|
||||
Me.Text = "EgalTech Camera Manager" & strWinXP & " v" & System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()
|
||||
BtnLoad.Visible = bExtended
|
||||
ImageControl1.PanMode = True
|
||||
|
||||
' Carico la configurazione corrente
|
||||
Inizializza()
|
||||
TStatus.Text = "Initialized"
|
||||
If ModalitaNascosta Then Me.Visible = False
|
||||
|
||||
' Avvio su un nuvo processo la comunicazione con il programma OmagCUT
|
||||
Dim ThreadCmdProcess As New Thread(AddressOf StartThreadCmdProcess)
|
||||
ThreadCmdProcess.Start()
|
||||
End Sub
|
||||
|
||||
' NUOVA gestione comunicazione con OmagCUT
|
||||
Public Sub WaitingForInstruction() Handles Me._waitingCmd
|
||||
Dim sNewReadLine As String = Console.ReadLine
|
||||
'If Not String.IsNullOrWhiteSpace(varDebug) Then sNewReadLine = varDebug
|
||||
'varDebug = ""
|
||||
If Not String.IsNullOrEmpty(sNewReadLine) Then
|
||||
While sNewReadLine <> "CLOSE"
|
||||
Dim sVal() As String = sNewReadLine.Split(","c)
|
||||
If sVal.Count > 1 Then sNewReadLine = sVal(0)
|
||||
Select Case sNewReadLine
|
||||
Case "0"
|
||||
' Primo avvio di processo
|
||||
ModalitaNascosta = True
|
||||
Hide()
|
||||
Console.WriteLine("RICHIESTA LETTURA CONFIGURAZIONE: " & MainModule.IndexProc)
|
||||
LeggiFileConfigurazione()
|
||||
Case "1"
|
||||
ModalitaNascosta = False
|
||||
Visible = True
|
||||
Case "2"
|
||||
' Richiesta scatto foto e correzione
|
||||
CorrezioneAutomatica = True
|
||||
RichiestaBordi = False
|
||||
Console.WriteLine("CORREZIONE FOTO: " & MainModule.IndexProc)
|
||||
Console.WriteLine("PROCESSO: " & MainModule.IndexProc)
|
||||
Console.WriteLine("CAMERA BODY CFG: " & MainModule.IndexProc & " -- " & CameraID)
|
||||
Console.WriteLine("CAMERA BODY CONNECTED: " & MainModule.IndexProc & " -- " & Camera.CameraID)
|
||||
RichiestaClick()
|
||||
Case "3"
|
||||
RichiestaStatoCamera()
|
||||
Case "4"
|
||||
' Salvataggio di BackImage per riconoscimento contorno
|
||||
Console.WriteLine("RICHIESTA SFONDO: " & MainModule.IndexProc)
|
||||
Console.WriteLine("PROCESSO: " & MainModule.IndexProc)
|
||||
Console.WriteLine("CAMERA BODY CFG: " & MainModule.IndexProc & " -- " & CameraID)
|
||||
Console.WriteLine("CAMERA BODY CONNECTED: " & MainModule.IndexProc & " -- " & Camera.CameraID)
|
||||
ScattoBackGround()
|
||||
Case "5"
|
||||
' Richiesta DXF di contorno lastra
|
||||
RichiestaBordi = True
|
||||
If sVal.Count = 2 Then MainModule.SogliaPercentuale = sVal(1)
|
||||
Console.WriteLine("RICONOSCIMENTO CONTORNO: " & MainModule.IndexProc)
|
||||
Console.WriteLine("PROCESSO: " & MainModule.IndexProc)
|
||||
Console.WriteLine("CAMERA BODY CFG: " & MainModule.IndexProc & " -- " & CameraID)
|
||||
Console.WriteLine("CAMERA BODY CONNECTED: " & MainModule.IndexProc & " -- " & Camera.CameraID)
|
||||
RichiestaClick()
|
||||
Case "6"
|
||||
If sVal.Count = 2 Then MainModule.SogliaPercentuale = sVal(1)
|
||||
RipetiThreshold()
|
||||
Case "7"
|
||||
Console.WriteLine("PROCESSO ATTIVO: " & MainModule.IndexProc)
|
||||
Case Else
|
||||
Console.WriteLine("COMANDO '" & sNewReadLine & "' NON DECODIFICATO: " & MainModule.IndexProc)
|
||||
End Select
|
||||
sNewReadLine = Console.ReadLine
|
||||
End While
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub BtnTakeFoto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnTakeFoto.Click
|
||||
CorrezioneAutomatica = False
|
||||
EseguiScatto()
|
||||
@@ -1077,48 +1196,6 @@ Public Class FrmMain
|
||||
status = en_status.NoImage
|
||||
End Sub
|
||||
|
||||
Public Sub WaitingForInstruction() Handles Me._waitingCmd
|
||||
Dim sNewReadLine As String = Console.ReadLine
|
||||
'If Not String.IsNullOrWhiteSpace(varDebug) Then sNewReadLine = varDebug
|
||||
'varDebug = ""
|
||||
If Not String.IsNullOrEmpty(sNewReadLine) Then
|
||||
While sNewReadLine <> "CLOSE"
|
||||
Select Case sNewReadLine
|
||||
Case "0"
|
||||
ModalitaNascosta = True
|
||||
Hide()
|
||||
Console.WriteLine("RICHIESTA LETTURA CONFIGURAZIONE: " & MainModule.IndexProc)
|
||||
LeggiFileConfigurazione()
|
||||
'Camera.Connect(CameraID)
|
||||
Case "1"
|
||||
ModalitaNascosta = False
|
||||
Visible = True
|
||||
Case "2"
|
||||
CorrezioneAutomatica = True
|
||||
RichiestaBordi = False
|
||||
Console.WriteLine("PROCESSO: " & MainModule.IndexProc)
|
||||
Console.WriteLine("CAMERA BODY CFG: " & CameraID)
|
||||
Console.WriteLine("CAMERA BODY CONNECTED: " & Camera.CameraID)
|
||||
RichiestaClick()
|
||||
Case "3"
|
||||
RichiestaStatoCamera()
|
||||
Case "4"
|
||||
ScattoBackGround()
|
||||
Case "5"
|
||||
RichiestaBordi = True
|
||||
RichiestaClick()
|
||||
Case "6"
|
||||
RipetiThreshold()
|
||||
Case "7"
|
||||
Console.WriteLine("PROCESSO ATTIVO: " & MainModule.IndexProc)
|
||||
Case Else
|
||||
Console.WriteLine("COMANDO '" & sNewReadLine & "' NON DECODIFICATO: " & MainModule.IndexProc)
|
||||
End Select
|
||||
sNewReadLine = Console.ReadLine
|
||||
End While
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub BtnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
|
||||
'CancelFile(Camera.PhotoFileName)
|
||||
CancelDir(DirTmp)
|
||||
@@ -1134,26 +1211,7 @@ Public Class FrmMain
|
||||
End
|
||||
End Sub
|
||||
|
||||
Private Sub FrmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||
Dim strWinXP As String = ""
|
||||
|
||||
#If WinXp Then
|
||||
strWinXP = " (WinXP)"
|
||||
#End If
|
||||
|
||||
Me.Text = "EgalTech Camera Manager" & strWinXP & " v" & System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()
|
||||
BtnLoad.Visible = bExtended
|
||||
ImageControl1.PanMode = True
|
||||
Inizializza()
|
||||
TStatus.Text = "Initialized"
|
||||
If ModalitaNascosta Then Me.Visible = False
|
||||
|
||||
' Avvio su un nuvo processo la comunicazione con il programma OmagCUT
|
||||
Dim ThreadCmdProcess As New Thread(AddressOf StartThreadCmdProcess)
|
||||
ThreadCmdProcess.Start()
|
||||
End Sub
|
||||
|
||||
Private Sub ImageControl1_NewMousePosImage(pima As System.Drawing.PointF)
|
||||
Private Sub ImageControl1_NewMousePosImage(pima As System.Drawing.PointF) Handles ImageControl1.NewMousePosImage
|
||||
lbMousePosmm.Text = "px: X" & pima.X.ToString("0.00") & " Y" & pima.Y.ToString("0.00")
|
||||
|
||||
If ImageMng.Corrected Then
|
||||
@@ -1369,6 +1427,7 @@ Public Class FrmMain
|
||||
SetFormStatus()
|
||||
End Sub
|
||||
|
||||
' Scarico immagine e procedo all'elaborazione
|
||||
Private Sub Camera_DownloadedCompleted() Handles Camera.DownloadedCompleted
|
||||
ImageMng.DownloadCompletato()
|
||||
ImageMng.InputImage = Camera.CameraImage
|
||||
@@ -1663,6 +1722,10 @@ Public Class FrmMain
|
||||
Private Sub ComboBoxCameraCfg_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBoxCameraCfg.SelectedIndexChanged
|
||||
If Not ModalitaNascosta Then
|
||||
LeggiFileConfigurazione()
|
||||
ImageMng.m_fileCaliLensRead = False
|
||||
ImageMng.m_fileCaliProspRead = False
|
||||
ImageMng.m_bMatProspOk = False
|
||||
ImageMng.SetFileCalibrazione(FileLensCalib, FileCalibProsp)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ Public Class DrawingBoard
|
||||
Private m_centerpoint As Point
|
||||
|
||||
Private m_PanMode As Boolean = True
|
||||
Private m_StretchImageToFit As Boolean = False
|
||||
Private m_StretchImageToFit As Boolean = True
|
||||
|
||||
Private m_Select_Rect As Rectangle
|
||||
Private m_Select_Pen As New Pen(Color.Blue, 2) ' Pen used to indicate a selection on the image (zoom window)
|
||||
@@ -221,16 +221,18 @@ Public Class DrawingBoard
|
||||
End Sub
|
||||
Private Sub ZoomImage(ByVal ZoomIn As Boolean, origin As Point)
|
||||
|
||||
ZoomImage(ZoomIn)
|
||||
Return
|
||||
' ZoomImage(ZoomIn)
|
||||
' Return
|
||||
|
||||
|
||||
' tentativo di zoommare sul punto del mouse
|
||||
' Get center point
|
||||
m_centerpoint.X = m_Origin.X + SrcRect.Width / 2
|
||||
m_centerpoint.Y = m_Origin.Y + SrcRect.Height / 2
|
||||
origin.X = -m_centerpoint.X + origin.X / m_ZoomFactor
|
||||
origin.Y = -m_centerpoint.Y + origin.Y / m_ZoomFactor
|
||||
' Coordinate origine scalate
|
||||
Dim X_ As Integer = m_Origin.X * m_ZoomFactor
|
||||
Dim Y_ As Integer = m_Origin.Y * m_ZoomFactor
|
||||
' Coordinate cursore riferite all'origine immagine
|
||||
Dim W_ As Integer = X_ + origin.X
|
||||
Dim H_ As Integer = Y_ + origin.Y
|
||||
' Dimensione attuale immagine
|
||||
Dim pre_W As Integer = m_ApparentImageSize.Width
|
||||
Dim pre_H As Integer = m_ApparentImageSize.Height
|
||||
|
||||
'set new zoomfactor
|
||||
If ZoomIn Then
|
||||
@@ -239,11 +241,22 @@ Public Class DrawingBoard
|
||||
ZoomFactor = Math.Round(ZoomFactor * 0.9, 2)
|
||||
End If
|
||||
|
||||
'Reset the origin to maintain center point
|
||||
m_Origin.X = CDbl(m_centerpoint.X) - (CDbl(ClientSize.Width) / m_ZoomFactor) / 2.0 - origin.X
|
||||
m_Origin.Y = CDbl(m_centerpoint.Y) - (CDbl(ClientSize.Height) / m_ZoomFactor) / 2.0 - origin.Y
|
||||
' Nuove coordinate origine scalate
|
||||
Dim X_n As Integer = m_Origin.X * m_ZoomFactor
|
||||
Dim Y_n As Integer = m_Origin.Y * m_ZoomFactor
|
||||
' Nuova dimensione attuale immagine
|
||||
Dim post_W As Integer = m_ApparentImageSize.Width
|
||||
Dim post_H As Integer = m_ApparentImageSize.Height
|
||||
' Fattore di scalatura dell'immagine
|
||||
Dim W_fac As Double = pre_W / post_W
|
||||
Dim H_fac As Double = pre_H / post_H
|
||||
' Nuove coordinate cursore riferite all'origine immagine
|
||||
Dim W_n As Integer = W_ / W_fac
|
||||
Dim H_n As Integer = H_ / H_fac
|
||||
' Calcolo posizione origine per manatenre l'immagine fissa sulla posizione cursore
|
||||
m_Origin.X += (-W_ + W_n + X_ - X_n) / m_ZoomFactor
|
||||
m_Origin.Y += (-H_ + H_n + Y_ - Y_n) / m_ZoomFactor
|
||||
|
||||
CheckBounds()
|
||||
End Sub
|
||||
|
||||
Public Sub InvertColors()
|
||||
@@ -468,11 +481,6 @@ Public Class DrawingBoard
|
||||
Next
|
||||
End If
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
RaiseEvent SetScrollPositions()
|
||||
|
||||
End Sub
|
||||
@@ -657,23 +665,30 @@ Public Class DrawingBoard
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub CheckBounds()
|
||||
If m_OriginalImage Is Nothing Then Exit Sub
|
||||
'Make sure we don't go out of bounds
|
||||
If m_Origin.X < 0 Then m_Origin.X = 0
|
||||
If m_Origin.Y < 0 Then m_Origin.Y = 0
|
||||
' Metodo che dovrebbe verificare di che lo spostamento dell'immagine è dentro i contorni
|
||||
Private Sub CheckBounds()
|
||||
If m_OriginalImage Is Nothing Then Exit Sub
|
||||
|
||||
If m_Origin.X > m_OriginalImage.Width - (ClientSize.Width / m_ZoomFactor) Then
|
||||
m_Origin.X = m_OriginalImage.Width - (ClientSize.Width / m_ZoomFactor)
|
||||
End If
|
||||
If m_Origin.Y > m_OriginalImage.Height - (ClientSize.Height / m_ZoomFactor) Then
|
||||
m_Origin.Y = m_OriginalImage.Height - (ClientSize.Height / m_ZoomFactor)
|
||||
End If
|
||||
' Il controllo che segue non mi soddisfa...!!!! NASCONDE SEMPRE IL LATO BASSO DELL'IMMAGINE !!!!
|
||||
Return
|
||||
|
||||
If m_Origin.X < 0 Then m_Origin.X = 0
|
||||
If m_Origin.Y < 0 Then m_Origin.Y = 0
|
||||
End Sub
|
||||
Private Sub CheckPointBounds()
|
||||
'Make sure we don't go out of bounds
|
||||
If m_Origin.X < 0 Then m_Origin.X = 0
|
||||
If m_Origin.Y < 0 Then m_Origin.Y = 0
|
||||
|
||||
If m_Origin.X > m_OriginalImage.Width - (ClientSize.Width / m_ZoomFactor) Then
|
||||
m_Origin.X = m_OriginalImage.Width - (ClientSize.Width / m_ZoomFactor)
|
||||
End If
|
||||
If m_Origin.Y > m_OriginalImage.Height - (ClientSize.Height / m_ZoomFactor) Then
|
||||
m_Origin.Y = m_OriginalImage.Height - (ClientSize.Height / m_ZoomFactor)
|
||||
End If
|
||||
|
||||
If m_Origin.X < 0 Then m_Origin.X = 0
|
||||
If m_Origin.Y < 0 Then m_Origin.Y = 0
|
||||
End Sub
|
||||
|
||||
' Metodo NON utilizzato
|
||||
Private Sub CheckPointBounds()
|
||||
If m_OriginalImage Is Nothing Then Exit Sub
|
||||
|
||||
'Make sure we don't go out of bounds
|
||||
@@ -696,9 +711,7 @@ Public Class DrawingBoard
|
||||
m_pArea(m_isel).Y = m_OriginalImage.Height '- (ClientSize.Height / m_ZoomFactor)
|
||||
End If
|
||||
|
||||
|
||||
|
||||
End Sub
|
||||
End Sub
|
||||
|
||||
Private Sub DrawingBoard_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
|
||||
If m_OriginalImage Is Nothing Then Exit Sub
|
||||
|
||||
+187
-188
@@ -1,180 +1,181 @@
|
||||
<System.Runtime.InteropServices.ComVisible(False)> _
|
||||
<System.Runtime.InteropServices.ComVisible(False)>
|
||||
Public Class ImageControl
|
||||
|
||||
Public Event PointSelected(n As Integer)
|
||||
Public Event PointUnselected()
|
||||
Public Event NewMousePosImage(pima As PointF)
|
||||
|
||||
Private m_ScrollVisible As Boolean = True
|
||||
Private m_ScrollVisible As Boolean = True
|
||||
|
||||
Public Sub New()
|
||||
Public Sub New()
|
||||
|
||||
' This call is required by the Windows Form Designer.
|
||||
InitializeComponent()
|
||||
' This call is required by the Windows Form Designer.
|
||||
InitializeComponent()
|
||||
|
||||
' Add any initialization after the InitializeComponent() call.
|
||||
End Sub
|
||||
' Add any initialization after the InitializeComponent() call.
|
||||
End Sub
|
||||
|
||||
#Region "Public Properties"
|
||||
Public ReadOnly Property DBoard() As DrawingBoard
|
||||
Get
|
||||
Return DrawingBoard1
|
||||
End Get
|
||||
End Property
|
||||
Public ReadOnly Property DBoard() As DrawingBoard
|
||||
Get
|
||||
Return DrawingBoard1
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Property PanMode() As Boolean
|
||||
Get
|
||||
Return DrawingBoard1.PanMode
|
||||
End Get
|
||||
Set(ByVal value As Boolean)
|
||||
DrawingBoard1.PanMode = value
|
||||
End Set
|
||||
End Property
|
||||
Public Property PanMode() As Boolean
|
||||
Get
|
||||
Return DrawingBoard1.PanMode
|
||||
End Get
|
||||
Set(ByVal value As Boolean)
|
||||
DrawingBoard1.PanMode = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Public Property PanButton() As System.Windows.Forms.MouseButtons
|
||||
Get
|
||||
Return DrawingBoard1.PanButton
|
||||
End Get
|
||||
Set(ByVal value As System.Windows.Forms.MouseButtons)
|
||||
DrawingBoard1.PanButton = value
|
||||
End Set
|
||||
End Property
|
||||
Public Property PanButton() As System.Windows.Forms.MouseButtons
|
||||
Get
|
||||
Return DrawingBoard1.PanButton
|
||||
End Get
|
||||
Set(ByVal value As System.Windows.Forms.MouseButtons)
|
||||
DrawingBoard1.PanButton = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Public Property ZoomOnMouseWheel() As Boolean
|
||||
Get
|
||||
Return DrawingBoard1.ZoomOnMouseWheel
|
||||
End Get
|
||||
Set(ByVal value As Boolean)
|
||||
DrawingBoard1.ZoomOnMouseWheel = value
|
||||
End Set
|
||||
End Property
|
||||
Public Property ZoomOnMouseWheel() As Boolean
|
||||
Get
|
||||
Return DrawingBoard1.ZoomOnMouseWheel
|
||||
End Get
|
||||
Set(ByVal value As Boolean)
|
||||
DrawingBoard1.ZoomOnMouseWheel = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Public Property ZoomFactor() As Double
|
||||
Get
|
||||
Return DrawingBoard1.ZoomFactor
|
||||
End Get
|
||||
Set(ByVal value As Double)
|
||||
DrawingBoard1.ZoomFactor = value
|
||||
End Set
|
||||
End Property
|
||||
Public Property ZoomFactor() As Double
|
||||
Get
|
||||
Return DrawingBoard1.ZoomFactor
|
||||
End Get
|
||||
Set(ByVal value As Double)
|
||||
DrawingBoard1.ZoomFactor = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Public Property Origin() As System.Drawing.Point
|
||||
Get
|
||||
Return DrawingBoard1.Origin
|
||||
End Get
|
||||
Set(ByVal value As System.Drawing.Point)
|
||||
DrawingBoard1.Origin = value
|
||||
End Set
|
||||
End Property
|
||||
Public Property Origin() As System.Drawing.Point
|
||||
Get
|
||||
Return DrawingBoard1.Origin
|
||||
End Get
|
||||
Set(ByVal value As System.Drawing.Point)
|
||||
DrawingBoard1.Origin = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Public Property StretchImageToFit() As Boolean
|
||||
Get
|
||||
Return Me.DrawingBoard1.StretchImageToFit
|
||||
End Get
|
||||
Set(ByVal value As Boolean)
|
||||
Me.DrawingBoard1.StretchImageToFit = value
|
||||
End Set
|
||||
End Property
|
||||
Public Property MouseEnabled() As Boolean
|
||||
Get
|
||||
Return Me.DrawingBoard1.MouseEnaBled
|
||||
End Get
|
||||
Set(ByVal value As Boolean)
|
||||
Me.DrawingBoard1.MouseEnaBled = value
|
||||
End Set
|
||||
End Property
|
||||
Public Property StretchImageToFit() As Boolean
|
||||
Get
|
||||
Return Me.DrawingBoard1.StretchImageToFit
|
||||
End Get
|
||||
Set(ByVal value As Boolean)
|
||||
Me.DrawingBoard1.StretchImageToFit = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Public ReadOnly Property ApparentImageSize() As System.Drawing.Size
|
||||
Get
|
||||
Return DrawingBoard1.ApparentImageSize
|
||||
End Get
|
||||
End Property
|
||||
Public Property MouseEnabled() As Boolean
|
||||
Get
|
||||
Return Me.DrawingBoard1.MouseEnaBled
|
||||
End Get
|
||||
Set(ByVal value As Boolean)
|
||||
Me.DrawingBoard1.MouseEnaBled = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Public Sub fittoscreen()
|
||||
Me.DrawingBoard1.fittoscreen()
|
||||
End Sub
|
||||
Public ReadOnly Property ApparentImageSize() As System.Drawing.Size
|
||||
Get
|
||||
Return DrawingBoard1.ApparentImageSize
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Sub InvertColors()
|
||||
Me.DrawingBoard1.InvertColors()
|
||||
End Sub
|
||||
Public Sub fittoscreen()
|
||||
Me.DrawingBoard1.fittoscreen()
|
||||
End Sub
|
||||
|
||||
Public Sub ZoomIn()
|
||||
Me.DrawingBoard1.ZoomIn()
|
||||
End Sub
|
||||
Public Sub InvertColors()
|
||||
Me.DrawingBoard1.InvertColors()
|
||||
End Sub
|
||||
|
||||
Public Sub ZoomOut()
|
||||
Me.DrawingBoard1.ZoomOut()
|
||||
End Sub
|
||||
Public Sub ZoomIn()
|
||||
Me.DrawingBoard1.ZoomIn()
|
||||
End Sub
|
||||
|
||||
Public Property ScrollbarsVisible() As Boolean
|
||||
Get
|
||||
Return m_ScrollVisible
|
||||
End Get
|
||||
Set(ByVal value As Boolean)
|
||||
m_ScrollVisible = value
|
||||
Me.HScrollBar1.Visible = value
|
||||
Me.VScrollBar1.Visible = value
|
||||
If value = False Then
|
||||
Me.DrawingBoard1.Dock = DockStyle.Fill
|
||||
Else
|
||||
Me.DrawingBoard1.Dock = DockStyle.None
|
||||
Me.DrawingBoard1.Location = New Point(0, 0)
|
||||
Me.DrawingBoard1.Width = ClientSize.Width - VScrollBar1.Width
|
||||
Me.DrawingBoard1.Height = ClientSize.Height - HScrollBar1.Height
|
||||
Public Sub ZoomOut()
|
||||
Me.DrawingBoard1.ZoomOut()
|
||||
End Sub
|
||||
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
Public Property ScrollbarsVisible() As Boolean
|
||||
Get
|
||||
Return m_ScrollVisible
|
||||
End Get
|
||||
Set(ByVal value As Boolean)
|
||||
m_ScrollVisible = value
|
||||
Me.HScrollBar1.Visible = value
|
||||
Me.VScrollBar1.Visible = value
|
||||
If value = False Then
|
||||
Me.DrawingBoard1.Dock = DockStyle.Fill
|
||||
Else
|
||||
Me.DrawingBoard1.Dock = DockStyle.None
|
||||
Me.DrawingBoard1.Location = New Point(0, 0)
|
||||
Me.DrawingBoard1.Width = ClientSize.Width - VScrollBar1.Width
|
||||
Me.DrawingBoard1.Height = ClientSize.Height - HScrollBar1.Height
|
||||
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
|
||||
#End Region
|
||||
|
||||
#Region "Public/Private Shadows"
|
||||
Public Shadows Property Image() As System.Drawing.Image
|
||||
Get
|
||||
Return DrawingBoard1.Image
|
||||
End Get
|
||||
Set(ByVal Value As System.Drawing.Image)
|
||||
DrawingBoard1.Image = Value
|
||||
If Value Is Nothing Then
|
||||
HScrollBar1.Enabled = False
|
||||
VScrollBar1.Enabled = False
|
||||
Exit Property
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
Public Shadows Property Image() As System.Drawing.Image
|
||||
Get
|
||||
Return DrawingBoard1.Image
|
||||
End Get
|
||||
Set(ByVal Value As System.Drawing.Image)
|
||||
DrawingBoard1.Image = Value
|
||||
If Value Is Nothing Then
|
||||
HScrollBar1.Enabled = False
|
||||
VScrollBar1.Enabled = False
|
||||
Exit Property
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Public Shadows Property initialimage() As System.Drawing.Image
|
||||
Get
|
||||
Return DrawingBoard1.initialimage
|
||||
End Get
|
||||
Set(ByVal value As System.Drawing.Image)
|
||||
DrawingBoard1.initialimage = value
|
||||
If value Is Nothing Then
|
||||
HScrollBar1.Enabled = False
|
||||
VScrollBar1.Enabled = False
|
||||
Exit Property
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
Public Shadows Property initialimage() As System.Drawing.Image
|
||||
Get
|
||||
Return DrawingBoard1.initialimage
|
||||
End Get
|
||||
Set(ByVal value As System.Drawing.Image)
|
||||
DrawingBoard1.initialimage = value
|
||||
If value Is Nothing Then
|
||||
HScrollBar1.Enabled = False
|
||||
VScrollBar1.Enabled = False
|
||||
Exit Property
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Public Shadows Property BackgroundImage() As System.Drawing.Image
|
||||
Get
|
||||
Return DrawingBoard1.BackgroundImage
|
||||
End Get
|
||||
Set(ByVal Value As System.Drawing.Image)
|
||||
DrawingBoard1.BackgroundImage = Value
|
||||
If Value Is Nothing Then
|
||||
HScrollBar1.Enabled = False
|
||||
VScrollBar1.Enabled = False
|
||||
Exit Property
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
Public Shadows Property BackgroundImage() As System.Drawing.Image
|
||||
Get
|
||||
Return DrawingBoard1.BackgroundImage
|
||||
End Get
|
||||
Set(ByVal Value As System.Drawing.Image)
|
||||
DrawingBoard1.BackgroundImage = Value
|
||||
If Value Is Nothing Then
|
||||
HScrollBar1.Enabled = False
|
||||
VScrollBar1.Enabled = False
|
||||
Exit Property
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
|
||||
#End Region
|
||||
|
||||
Public Sub RotateFlip(ByVal RotateFlipType As System.Drawing.RotateFlipType)
|
||||
DrawingBoard1.RotateFlip(RotateFlipType)
|
||||
Public Sub RotateFlip(ByVal RotateFlipType As System.Drawing.RotateFlipType)
|
||||
DrawingBoard1.RotateFlip(RotateFlipType)
|
||||
End Sub
|
||||
|
||||
Private Sub DrawingBoard1_NewMousePosImage(pm As System.Drawing.PointF) Handles DrawingBoard1.NewMousePosImage
|
||||
@@ -185,51 +186,49 @@ Public Class ImageControl
|
||||
RaiseEvent PointSelected(n)
|
||||
End Sub
|
||||
|
||||
Private Sub DrawingBoard1_SetScrollPositions() Handles DrawingBoard1.SetScrollPositions
|
||||
|
||||
Dim DrawingWidth As Integer = DrawingBoard1.Image.Width
|
||||
Dim DrawingHeight As Integer = DrawingBoard1.Image.Height
|
||||
Dim OriginX As Integer = DrawingBoard1.Origin.X
|
||||
Dim OriginY As Integer = DrawingBoard1.Origin.Y
|
||||
Dim FactoredCtrlWidth As Integer = DrawingBoard1.Width / DrawingBoard1.ZoomFactor
|
||||
Dim FactoredCtrlHeight As Integer = DrawingBoard1.Height / DrawingBoard1.ZoomFactor
|
||||
HScrollBar1.Maximum = Me.DrawingBoard1.Image.Width
|
||||
VScrollBar1.Maximum = Me.DrawingBoard1.Image.Height
|
||||
|
||||
If FactoredCtrlWidth >= DrawingBoard1.Image.Width Or StretchImageToFit Then
|
||||
HScrollBar1.Enabled = False
|
||||
HScrollBar1.Value = 0
|
||||
Else
|
||||
HScrollBar1.LargeChange = FactoredCtrlWidth
|
||||
HScrollBar1.Enabled = True
|
||||
HScrollBar1.Value = OriginX
|
||||
End If
|
||||
|
||||
If FactoredCtrlHeight >= DrawingBoard1.Image.Height Or StretchImageToFit Then
|
||||
VScrollBar1.Enabled = False
|
||||
VScrollBar1.Value = 0
|
||||
Else
|
||||
VScrollBar1.Enabled = True
|
||||
VScrollBar1.LargeChange = FactoredCtrlHeight
|
||||
VScrollBar1.Value = OriginY
|
||||
End If
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub ScrollBar_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles HScrollBar1.ValueChanged, VScrollBar1.ValueChanged
|
||||
Me.DrawingBoard1.Origin = New Point(HScrollBar1.Value, VScrollBar1.Value)
|
||||
End Sub
|
||||
|
||||
Private Sub DrawingBoard1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DrawingBoard1.Load
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub DrawingBoard1_PointUnselected() Handles DrawingBoard1.PointUnselected
|
||||
RaiseEvent PointUnselected()
|
||||
End Sub
|
||||
|
||||
' DISATTIVO il richimao alla ScrollBar: Handles DrawingBoard1.SetScrollPositions
|
||||
Private Sub DrawingBoard1_SetScrollPositions()
|
||||
|
||||
Dim DrawingWidth As Integer = DrawingBoard1.Image.Width
|
||||
Dim DrawingHeight As Integer = DrawingBoard1.Image.Height
|
||||
Dim OriginX As Integer = DrawingBoard1.Origin.X
|
||||
Dim OriginY As Integer = DrawingBoard1.Origin.Y
|
||||
Dim FactoredCtrlWidth As Integer = DrawingBoard1.Width / DrawingBoard1.ZoomFactor
|
||||
Dim FactoredCtrlHeight As Integer = DrawingBoard1.Height / DrawingBoard1.ZoomFactor
|
||||
HScrollBar1.Maximum = Me.DrawingBoard1.Image.Width
|
||||
VScrollBar1.Maximum = Me.DrawingBoard1.Image.Height
|
||||
|
||||
If FactoredCtrlWidth >= DrawingBoard1.Image.Width Or StretchImageToFit Then
|
||||
HScrollBar1.Enabled = False
|
||||
HScrollBar1.Value = 0
|
||||
Else
|
||||
HScrollBar1.LargeChange = FactoredCtrlWidth
|
||||
HScrollBar1.Enabled = True
|
||||
HScrollBar1.Value = OriginX
|
||||
End If
|
||||
|
||||
If FactoredCtrlHeight >= DrawingBoard1.Image.Height Or StretchImageToFit Then
|
||||
VScrollBar1.Enabled = False
|
||||
VScrollBar1.Value = 0
|
||||
Else
|
||||
VScrollBar1.Enabled = True
|
||||
VScrollBar1.LargeChange = FactoredCtrlHeight
|
||||
VScrollBar1.Value = OriginY
|
||||
End If
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub ScrollBar_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles HScrollBar1.ValueChanged, VScrollBar1.ValueChanged
|
||||
Me.DrawingBoard1.Origin = New Point(HScrollBar1.Value, VScrollBar1.Value)
|
||||
End Sub
|
||||
|
||||
Private Sub DrawingBoard1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DrawingBoard1.Load
|
||||
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
@@ -28,7 +28,7 @@ Public Module MainModule
|
||||
Public ModalitaNascosta As Boolean = False
|
||||
Public StatoGenerale As statoGenEnum = statoGenEnum.StatoOk
|
||||
Public RichiestaBackGround As Boolean = False
|
||||
Public SogliaPercentuale As Double
|
||||
Public SogliaPercentuale As Double = 0.0
|
||||
Public RichiestaBordi As Boolean = False
|
||||
Public CameraID As String = ""
|
||||
Public bEnableBorder As Boolean = False
|
||||
|
||||
@@ -69,7 +69,6 @@ Public Class clsImageMng
|
||||
Private m_InputImage As Drawing.Bitmap = Nothing
|
||||
Private m_dim_XProspExt As Integer
|
||||
Private m_dim_YProspExt As Integer
|
||||
Private m_bMatProspOk As Boolean = False
|
||||
Private m_FileCalibLens As String = Nothing
|
||||
Private m_FileCalibProsp As String = Nothing
|
||||
Private m_widthImagePixMax As Integer = 6000
|
||||
@@ -83,8 +82,6 @@ Public Class clsImageMng
|
||||
' [ k1, k2, p1, p2, p3 ]
|
||||
Private _distCoeffs As Matrix(Of Double) = Nothing
|
||||
|
||||
Private m_fileCaliLensRead As Boolean = False
|
||||
Private m_fileCaliProspRead As Boolean = False
|
||||
Private Shared ReadOnly m_sync As New Object
|
||||
' vettore di correzione prospettica: convertita in matrice (m_MatDir)
|
||||
Private _perspMatDir As Emgu.CV.Mat
|
||||
@@ -96,6 +93,9 @@ Public Class clsImageMng
|
||||
#End Region
|
||||
|
||||
#Region "membri pubblici"
|
||||
Public m_fileCaliLensRead As Boolean = False
|
||||
Public m_fileCaliProspRead As Boolean = False
|
||||
Public m_bMatProspOk As Boolean = False
|
||||
' --- variabili per la correzione prospettica
|
||||
Public m_AltRif As Double
|
||||
Public m_ZCali As Double
|
||||
@@ -200,6 +200,7 @@ Public Class clsImageMng
|
||||
|
||||
|
||||
End Function
|
||||
|
||||
Public Sub Correggi()
|
||||
|
||||
' corregge solo la lente e carica il file di calibrazione prospettiva per dare la possibilità di calibrare dall'interfaccia
|
||||
@@ -242,6 +243,7 @@ Public Class clsImageMng
|
||||
End Try
|
||||
|
||||
End Sub
|
||||
|
||||
Public Sub DownloadCompletato()
|
||||
m_bCorrected = False
|
||||
End Sub
|
||||
@@ -267,6 +269,7 @@ Public Class clsImageMng
|
||||
End If
|
||||
|
||||
End Sub
|
||||
|
||||
Public Sub CalcolaDatiCorrezione()
|
||||
' forzo il ricalcolo
|
||||
m_ProspCalibrated = False
|
||||
@@ -277,7 +280,9 @@ Public Class clsImageMng
|
||||
If Not TrovaOffsetPosizione() Then m_bCorrAltezzaEnabled = False
|
||||
End Sub
|
||||
|
||||
' Salvo file di calibrazione
|
||||
Public Sub SalvaFileCorrezioneProsp()
|
||||
|
||||
Dim writer As StreamWriter
|
||||
Dim i As Integer
|
||||
Dim nfi As New CultureInfo("en-US", False)
|
||||
@@ -301,7 +306,9 @@ Public Class clsImageMng
|
||||
writer.WriteLine("ImageWidth= {0}", m_CalimageWidth.ToString("0"))
|
||||
writer.Close()
|
||||
CalcolaMatriceCorrezioneProspettiva()
|
||||
|
||||
' Avviso che la configurazione è stata salvata correttamente
|
||||
Dim sMsg = String.Format("Salvataggio file di calbrazione '{0}' " & vbCrLf & "avvenuto con succeso!", m_NomeFileCorrezProsp)
|
||||
MessageBox.Show(sMsg, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
|
||||
End Sub
|
||||
|
||||
Public Sub ProcessStop()
|
||||
@@ -314,6 +321,7 @@ Public Class clsImageMng
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
Public Sub CorrezioneCompletaAsync()
|
||||
|
||||
ProcessStop()
|
||||
@@ -664,11 +672,13 @@ Public Class clsImageMng
|
||||
Return m_bCorrAltezzaEnabled
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property ZCali() As Double
|
||||
Get
|
||||
Return m_ZCali
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Property XHpix(ByVal i As Integer) As Short
|
||||
Get
|
||||
Return (m_puntoH(i).XSrc)
|
||||
@@ -904,7 +914,7 @@ Public Class clsImageMng
|
||||
|
||||
' Crea file FinalImage.txt
|
||||
Private Sub SaveDataImage(NomeFile As String)
|
||||
|
||||
CalcolaCorrezioniAltezza()
|
||||
Dim writer As New StreamWriter(NomeFile)
|
||||
|
||||
writer.WriteLine("X = {0}", m_Pos_x_mm.ToString("F9", CultureInfo.InvariantCulture))
|
||||
@@ -920,7 +930,6 @@ Public Class clsImageMng
|
||||
writer.Close()
|
||||
End Sub
|
||||
|
||||
|
||||
Public Sub CorrezioneCompleta(Optional rEvents As Boolean = True)
|
||||
Try
|
||||
|
||||
@@ -945,8 +954,6 @@ Public Class clsImageMng
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
Private Sub CalcolaMatriceCorrezioneProspettiva()
|
||||
|
||||
Dim ix As Integer, iy As Integer
|
||||
@@ -1013,9 +1020,10 @@ Public Class clsImageMng
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub CorreggiProspettivaDaMatriceOCV(spessLastra As Double)
|
||||
|
||||
Console.WriteLine("INIZIO CREAZIONE IMMAGINE CON CORREZIONE OCV")
|
||||
Console.WriteLine("INIZIO CREAZIONE IMMAGINE CON CORREZIONE OCV: " & MainModule.IndexProc)
|
||||
|
||||
Dim flags As Integer = Emgu.CV.CvEnum.Inter.Linear
|
||||
Dim fillVal As New MCvScalar(0, 0, 0, 0)
|
||||
@@ -1026,7 +1034,7 @@ Public Class clsImageMng
|
||||
|
||||
SaveBitmap(m_FinalImage, SaveDir & "FinalImage.jpg")
|
||||
|
||||
Console.WriteLine("FINE CREAZIONE IMMAGINE CON CORREZIONE OCV")
|
||||
Console.WriteLine("FINE CREAZIONE IMMAGINE CON CORREZIONE OCV: " & MainModule.IndexProc)
|
||||
|
||||
SaveDataImage(SaveDir & "FinalImage.txt")
|
||||
End Sub
|
||||
@@ -1044,6 +1052,7 @@ Public Class clsImageMng
|
||||
|
||||
Return Nothing
|
||||
End Function
|
||||
|
||||
Private Sub CalcolaMatriceOCV()
|
||||
|
||||
Dim ix As Integer, iy As Integer
|
||||
@@ -1061,7 +1070,6 @@ Public Class clsImageMng
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub CalcolaCorrezioniAltezza()
|
||||
' fattore di scala data la nuova altezza
|
||||
Dim fattScala As Double
|
||||
@@ -1078,6 +1086,7 @@ Public Class clsImageMng
|
||||
m_Pos_y_mm = m_Pos_y_mm + m_scale_center.y
|
||||
|
||||
End Sub
|
||||
|
||||
Public Sub SaveClickMsg(numerr As Integer)
|
||||
Dim NomeFile As String
|
||||
|
||||
@@ -1089,6 +1098,7 @@ Public Class clsImageMng
|
||||
FileClose(nf)
|
||||
|
||||
End Sub
|
||||
|
||||
' questa è la correzione inversa a quello che mi serve...
|
||||
Public Function CorreggiPunto(p As Point) As Point
|
||||
Dim po As Point
|
||||
|
||||
@@ -279,9 +279,9 @@ Public Class clsVisione
|
||||
''' 'Trova i bordi sommando le differenze deri tre canali
|
||||
''' </summary>
|
||||
''' <remarks></remarks>
|
||||
Public Sub TrovaBordiMCh(ByRef trhVal As Integer)
|
||||
|
||||
Public Function TrovaBordiMCh(ByRef trhVal As Integer) As Boolean
|
||||
|
||||
Console.WriteLine("MODALITÀ RICONOSCIMENTO BORDI: " & MainModule.IndexProc & " -- " & _metodoDiff.ToString)
|
||||
Select Case _metodoDiff
|
||||
Case 1
|
||||
' somma delle differense sui tre canali
|
||||
@@ -307,10 +307,13 @@ Public Class clsVisione
|
||||
Case 8
|
||||
' in test
|
||||
TrovaBordiMCh8()
|
||||
Case Else
|
||||
Console.WriteLine("MODALITÀ RICONOSCIMENTO NON VALIDA BORDI: " & MainModule.IndexProc)
|
||||
Return False
|
||||
End Select
|
||||
|
||||
|
||||
End Sub
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Sub ApplicaTreshold(trhVal As Integer)
|
||||
|
||||
@@ -1060,30 +1063,32 @@ Public Class clsVisione
|
||||
End Sub
|
||||
|
||||
Private Sub TrovaBordiMCh7(trhVal As Integer, valutaBiancoNero As Boolean)
|
||||
|
||||
Try
|
||||
|
||||
' Ripolisco la memoria
|
||||
DisposePreviousImages()
|
||||
|
||||
' Se non c'è il back raddrizzato, lo raddrizzo
|
||||
Console.WriteLine("PREPARAZIONE BACK IMAGE: " & MainModule.IndexProc)
|
||||
If _convBackImage Is Nothing Then
|
||||
ConvertBackImage()
|
||||
End If
|
||||
|
||||
If _convBackImage Is Nothing Then
|
||||
Debug.Assert(False)
|
||||
Console.WriteLine("BACK IMAGE NON DISPONIBILE: " & MainModule.IndexProc)
|
||||
Return
|
||||
End If
|
||||
|
||||
Dim cvbackImage As New Image(Of Emgu.CV.Structure.Bgr, Byte)(_convBackImage)
|
||||
|
||||
Console.WriteLine("PREPARAZIONE SLAB IMAGE: " & MainModule.IndexProc)
|
||||
_imageMng.InputImage = _image1
|
||||
_imageMng.CorrezioneCompleta()
|
||||
|
||||
_outimage = New Image(Of Emgu.CV.Structure.Rgb, Byte)(_imageMng.FinalImage)
|
||||
' creo una copia dell'immagine ivertendo l'ordine dei primi 2 canali
|
||||
Dim cvimage1 As New Image(Of Emgu.CV.Structure.Bgr, Byte)(_imageMng.FinalImage)
|
||||
|
||||
|
||||
Dim add As Double = 0
|
||||
Dim factor As Double = 1
|
||||
CorreggiEsposizione(_outimage.Bitmap, _convBackImage, add, factor)
|
||||
@@ -1102,12 +1107,13 @@ Public Class clsVisione
|
||||
|
||||
End If
|
||||
|
||||
' Ridimensiono l'immaggine del 50% applicando un'iterpolazione di scala
|
||||
For j As Integer = 0 To _pdown - 1
|
||||
cvimage1 = cvimage1.Resize(0.5, _iterpType)
|
||||
cvbackImage = cvbackImage.Resize(0.5, _iterpType)
|
||||
Next
|
||||
|
||||
|
||||
' Calcola la differenza assoluta pixel per pixel tra due immagini per ogni canele (0:B, 1:G, 2:R)
|
||||
_corImgDiff0 = ScaleGrayTo(255, cvbackImage.Split(0).AbsDiff(cvimage1.Split(0)))
|
||||
_corImgDiff1 = ScaleGrayTo(255, cvbackImage.Split(1).AbsDiff(cvimage1.Split(1)))
|
||||
_corImgDiff2 = ScaleGrayTo(255, cvbackImage.Split(2).AbsDiff(cvimage1.Split(2)))
|
||||
@@ -1238,15 +1244,30 @@ Public Class clsVisione
|
||||
|
||||
Dim cvimageTh As Image(Of Emgu.CV.Structure.Gray, Byte)
|
||||
|
||||
|
||||
|
||||
|
||||
cvimageTh = _corImgDiff.ThresholdBinary(New Emgu.CV.Structure.Gray(trhVal), New Emgu.CV.Structure.Gray(255))
|
||||
Static fattR As Integer = 15
|
||||
|
||||
cvimageTh = cvimageTh.Dilate(fattR)
|
||||
cvimageTh = cvimageTh.Erode(fattR)
|
||||
|
||||
''------------------- PROVA PROVA
|
||||
'Dim cannyThreshold As Double = 25
|
||||
'Dim cannyThresholdLinking As Double = 12 ' Deve essere inferiore a cannyThreshold
|
||||
'Dim apertureSize As Integer = 3 ' Valori comuni: 3, 5, 7
|
||||
|
||||
'Dim cvimageTh_ As Image(Of Gray, Byte) = New Image(Of Gray, Byte)(_imageMng.FinalImage)
|
||||
'' Applica Dilate e Erode come hai già fatto
|
||||
'Dim fattR_ As Integer = 1 ' O il valore appropriato per fattR
|
||||
'cvimageTh_ = cvimageTh_.Dilate(fattR_)
|
||||
'cvimageTh_ = cvimageTh_.Erode(fattR_)
|
||||
|
||||
'Dim edges As Image(Of Gray, Byte) = New Image(Of Gray, Byte)(cvimageTh_.Size)
|
||||
'CvInvoke.Canny(cvimageTh_, edges, cannyThreshold, cannyThresholdLinking, apertureSize)
|
||||
|
||||
'cvimageTh_.Save(SaveDir & "EDGES_TEST0.png")
|
||||
'edges.Save(SaveDir & "EDGES_TEST.png")
|
||||
''------------------- PROVA PROVA
|
||||
|
||||
t1 = tm.ElapsedMilliseconds
|
||||
|
||||
' Faccio la canny per didattica, ma non la uso
|
||||
@@ -1255,7 +1276,9 @@ Public Class clsVisione
|
||||
'Dim frm4 As FrmImgShow = New FrmImgShow(cvimageCanny)
|
||||
'frm4.ShowDialog()
|
||||
|
||||
' Area massima
|
||||
Dim areaMax As Double = 0
|
||||
' Indice del contorno di area massima nella lista di contorni
|
||||
Dim iareaMax As Integer = 0
|
||||
|
||||
#If WinXp Then
|
||||
@@ -1279,6 +1302,7 @@ Public Class clsVisione
|
||||
|
||||
|
||||
#Else
|
||||
' Una lista di contorni, ogni contorno è una lista di punti
|
||||
Dim contours As New VectorOfVectorOfPoint
|
||||
Dim Hierarchy As IOutputArray
|
||||
CvInvoke.FindContours(cvimageTh, contours, Hierarchy, _searchMode, CvEnum.ChainApproxMethod.ChainApproxTc89Kcos)
|
||||
@@ -1361,7 +1385,10 @@ Public Class clsVisione
|
||||
|
||||
trhVal = trhVal * _thFactor
|
||||
|
||||
' cnale R
|
||||
If _corImgDiff1 Is Nothing Then Return
|
||||
|
||||
' pulisco la memoria
|
||||
Try
|
||||
If _thrImage IsNot Nothing Then
|
||||
_thrImage.Dispose()
|
||||
@@ -1387,6 +1414,7 @@ Public Class clsVisione
|
||||
|
||||
_corImgDiff = _thrImage
|
||||
|
||||
' raddoppio la dimensione dell'immagine (in precedenza dimezzata) '_pdown' volte
|
||||
For j As Integer = 0 To _pdown - 1
|
||||
_corImgDiff = _corImgDiff.PyrUp
|
||||
Next
|
||||
@@ -1409,11 +1437,12 @@ Public Class clsVisione
|
||||
End Sub
|
||||
|
||||
Private Sub ConvertBackImage()
|
||||
' Libero memoria
|
||||
If _convBackImage IsNot Nothing Then
|
||||
_convBackImage.Dispose()
|
||||
_convBackImage = Nothing
|
||||
End If
|
||||
|
||||
' verifico che esita l'immagine BackImg
|
||||
If _backImage Is Nothing Then Return
|
||||
|
||||
_imageMng.InputImage = _backImage
|
||||
@@ -1431,14 +1460,14 @@ Public Class clsVisione
|
||||
#If WinXp Then
|
||||
CvInvoke.cvMinMaxLoc(img, minv, maxv, minp, maxp, Nothing)
|
||||
#Else
|
||||
' Restituisce il valore minimo e massimo della matrice associato alla sua posizione
|
||||
CvInvoke.MinMaxLoc(img, minv, maxv, minp, maxp)
|
||||
#End If
|
||||
|
||||
' minv = 0 -> NERO, maxv = 255 -> BIANCO
|
||||
If (maxv - minv > 2) Then
|
||||
' imposto fondo scala immagine a zero '(img - minv)' e riscalo i colori per andare da 0 a 255
|
||||
img = (img - minv) * (maxg / (maxv - minv))
|
||||
End If
|
||||
|
||||
|
||||
Return img
|
||||
End Function
|
||||
|
||||
@@ -1451,22 +1480,34 @@ Public Class clsVisione
|
||||
|
||||
Dim cvimageTh As Image(Of Emgu.CV.Structure.Gray, Byte)
|
||||
|
||||
' Misuro il tempo impiegato per eseguire determinate operazioni
|
||||
Dim tm As New Stopwatch
|
||||
Dim t1, t2, t3 As Double
|
||||
tm.Start()
|
||||
|
||||
_corImgDiff.Save(SaveDir & "BlackAndWhite_00_" & nimg.ToString & ".png")
|
||||
|
||||
' creo un'immagine in bianco e nero (tutti i pixel con valore maggiore di soglia diventano 255, altrimenti 0)
|
||||
cvimageTh = _corImgDiff.ThresholdBinary(New Emgu.CV.Structure.Gray(trhVal), New Emgu.CV.Structure.Gray(255))
|
||||
|
||||
cvimageTh.Save(SaveDir & "BlackAndWhite_01_" & nimg.ToString & ".png")
|
||||
|
||||
t1 = tm.ElapsedMilliseconds
|
||||
|
||||
' Numero di iterazioni
|
||||
Static fattR As Integer = 7
|
||||
|
||||
' Closing = Dilate + Erode -> procedo a chiudere eventuali buchi
|
||||
cvimageTh = cvimageTh.Dilate(fattR)
|
||||
cvimageTh = cvimageTh.Erode(fattR)
|
||||
|
||||
cvimageTh.Save(SaveDir & "BlackAndWhite" & nimg.ToString & ".png")
|
||||
|
||||
t2 = tm.ElapsedMilliseconds
|
||||
|
||||
If _thrImage Is Nothing Then
|
||||
_thrImage = cvimageTh
|
||||
Else
|
||||
' sommo il risultato all'immagine precedente
|
||||
_thrImage = _thrImage.Add(cvimageTh)
|
||||
End If
|
||||
|
||||
@@ -1476,7 +1517,6 @@ Public Class clsVisione
|
||||
cvimageTh.Save("c:\temp\thImage" & nimg.ToString & ".png")
|
||||
#End If
|
||||
|
||||
|
||||
'GC.Collect()
|
||||
|
||||
Catch ex As Exception
|
||||
@@ -1489,21 +1529,16 @@ Public Class clsVisione
|
||||
Private Sub DisposePreviousImages()
|
||||
|
||||
Dim img As Image(Of Emgu.CV.Structure.Gray, Byte)
|
||||
|
||||
' Libera la memoria associata ai dati dell'immagine
|
||||
For Each img In {_corImgDiff0, _corImgDiff1, _corImgDiff2, _corImgDiff, _thrImage}
|
||||
|
||||
Try
|
||||
|
||||
If img IsNot Nothing Then
|
||||
img.Dispose()
|
||||
img = Nothing
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
|
||||
End Try
|
||||
Next
|
||||
|
||||
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user