-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfrmImportImage.frm
2280 lines (2162 loc) · 86.5 KB
/
frmImportImage.frm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "MSCOMCTL.OCX"
Begin VB.Form frmImpConv
Caption = "Vectoriser une image"
ClientHeight = 9345
ClientLeft = 225
ClientTop = 555
ClientWidth = 14325
KeyPreview = -1 'True
LinkTopic = "Form1"
ScaleHeight = 623
ScaleMode = 3 'Pixel
ScaleWidth = 955
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton cmdSauverVecto
Height = 435
Left = 135
Picture = "frmImportImage.frx":0000
Style = 1 'Graphical
TabIndex = 19
Top = 7305
Width = 690
End
Begin VB.PictureBox pctVisuVecto
Height = 6120
Left = 5010
ScaleHeight = 6060
ScaleWidth = 8580
TabIndex = 17
Top = 2955
Width = 8640
End
Begin VB.CommandButton cmdQuitterImpConv
Caption = "OK"
BeginProperty Font
Name = "Arial"
Size = 9
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 435
Left = 990
Style = 1 'Graphical
TabIndex = 14
Top = 7305
Width = 1035
End
Begin VB.PictureBox pctCouleurOriginaleRecadree
Appearance = 0 'Flat
AutoRedraw = -1 'True
BackColor = &H80000005&
ForeColor = &H80000008&
Height = 2130
Left = 7800
ScaleHeight = 140
ScaleMode = 3 'Pixel
ScaleWidth = 233
TabIndex = 13
Top = 135
Width = 3525
End
Begin VB.Frame frmLisserTransferer
Caption = "Vectoriser"
Height = 2520
Left = 90
TabIndex = 11
Top = 4665
Width = 1965
Begin VB.Frame frameInterieurExterieur
Height = 750
Left = 255
TabIndex = 24
Top = 220
Width = 1470
Begin VB.OptionButton optInterieur
Height = 450
Index = 0
Left = 135
Picture = "frmImportImage.frx":060A
Style = 1 'Graphical
TabIndex = 26
ToolTipText = "Seulement les contours extérieurs"
Top = 180
Value = -1 'True
Width = 585
End
Begin VB.OptionButton optInterieur
Height = 450
Index = 1
Left = 750
Picture = "frmImportImage.frx":0BEC
Style = 1 'Graphical
TabIndex = 25
ToolTipText = "Contours extérieurs et intérieurs"
Top = 180
Width = 585
End
End
Begin VB.HScrollBar hscLissageVecto
Height = 240
LargeChange = 5
Left = 180
Max = 20
Min = 3
TabIndex = 21
Top = 1470
Value = 10
Width = 1590
End
Begin VB.CheckBox chkVoirPointsVecto
Height = 480
Left = 1335
Picture = "frmImportImage.frx":11CE
Style = 1 'Graphical
TabIndex = 18
TabStop = 0 'False
ToolTipText = "Afficher les points"
Top = 1905
Value = 1 'Checked
Width = 495
End
Begin VB.CommandButton cmdContoursLissageTransfert
BackColor = &H00C0E0FF&
Height = 480
Left = 105
Picture = "frmImportImage.frx":1848
Style = 1 'Graphical
TabIndex = 12
ToolTipText = "Vectoriser"
Top = 1905
Width = 1080
End
Begin VB.Image imgVecto
Height = 270
Index = 1
Left = 1425
Picture = "frmImportImage.frx":2252
Top = 1095
Width = 360
End
Begin VB.Image imgVecto
Height = 285
Index = 0
Left = 120
Picture = "frmImportImage.frx":2894
Top = 1125
Width = 360
End
Begin VB.Label lblLissageVecto
AutoSize = -1 'True
BackColor = &H00FFFFFF&
Caption = "5"
BeginProperty Font
Name = "Arial"
Size = 9
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 225
Left = 915
TabIndex = 22
Top = 1170
Width = 105
End
End
Begin VB.Frame frmApercu
Caption = "Noir et Blanc"
Height = 1395
Left = 90
TabIndex = 8
Top = 2835
Width = 1965
Begin VB.OptionButton optApercu
Height = 510
Index = 1
Left = 1305
Picture = "frmImportImage.frx":2EF2
Style = 1 'Graphical
TabIndex = 16
ToolTipText = "Recommencer"
Top = 735
Value = -1 'True
Width = 525
End
Begin VB.OptionButton optApercu
BackColor = &H00C0E0FF&
Height = 510
Index = 0
Left = 105
Picture = "frmImportImage.frx":3534
Style = 1 'Graphical
TabIndex = 15
ToolTipText = "Convertir en noir et blanc"
Top = 735
Width = 1095
End
Begin VB.HScrollBar hscSensibilite
Height = 270
LargeChange = 10
Left = 105
Max = 200
Min = 1
TabIndex = 9
Top = 315
Value = 100
Width = 1080
End
Begin VB.Label lblSensibilite
Alignment = 2 'Center
Appearance = 0 'Flat
AutoSize = -1 'True
BackColor = &H80000005&
Caption = "seuil"
ForeColor = &H80000008&
Height = 195
Left = 1380
TabIndex = 10
ToolTipText = "Seuil noir/blanc"
Top = 330
Width = 345
End
End
Begin VB.Frame frmRecadrer
Caption = "Recadrer"
Height = 930
Left = 390
TabIndex = 6
Top = 1440
Width = 1665
Begin VB.CommandButton cmdRecadrerLaSelection
Height = 510
Left = 855
Picture = "frmImportImage.frx":3F3E
Style = 1 'Graphical
TabIndex = 7
ToolTipText = "Recadrer sur la sélection"
Top = 255
Width = 630
End
Begin VB.Image imgSelectionerUneZone
Height = 390
Left = 186
Picture = "frmImportImage.frx":4538
ToolTipText = "Sélectionner une zone puis cliquez"
Top = 360
Width = 540
End
End
Begin VB.Frame frmImporterImage
Caption = "Image"
Height = 915
Left = 90
TabIndex = 3
Top = 105
Width = 1965
Begin VB.CommandButton cmdImporterImage
Height = 510
Index = 1
Left = 1050
Picture = "frmImportImage.frx":4DFA
Style = 1 'Graphical
TabIndex = 5
ToolTipText = "Coller"
Top = 270
Width = 630
End
Begin VB.CommandButton cmdImporterImage
Height = 510
Index = 0
Left = 270
Picture = "frmImportImage.frx":53C0
Style = 1 'Graphical
TabIndex = 4
ToolTipText = "Importer"
Top = 270
Width = 630
End
End
Begin VB.PictureBox pctCouleurOriginale
Appearance = 0 'Flat
AutoRedraw = -1 'True
AutoSize = -1 'True
BackColor = &H80000005&
ForeColor = &H80000008&
Height = 1005
Left = 11760
ScaleHeight = 65
ScaleMode = 3 'Pixel
ScaleWidth = 107
TabIndex = 2
Top = 345
Visible = 0 'False
Width = 1635
End
Begin VB.PictureBox pctNoirBlancRedim
Appearance = 0 'Flat
AutoRedraw = -1 'True
BackColor = &H80000005&
ForeColor = &H80000008&
Height = 1245
Left = 10800
ScaleHeight = 81
ScaleMode = 3 'Pixel
ScaleWidth = 160
TabIndex = 1
Top = 1515
Width = 2430
End
Begin VB.PictureBox pctCouleurRedim
Appearance = 0 'Flat
AutoRedraw = -1 'True
BackColor = &H80000005&
ForeColor = &H80000008&
Height = 5700
Left = 2160
ScaleHeight = 378
ScaleMode = 3 'Pixel
ScaleWidth = 363
TabIndex = 0
Top = 300
Width = 5475
Begin VB.Shape Shape1
BorderColor = &H000000FF&
BorderStyle = 3 'Dot
FillColor = &H000000FF&
Height = 15
Left = 0
Top = 0
Width = 15
End
End
Begin MSComDlg.CommonDialog COMDLG
Left = 2595
Top = 6270
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin MSComctlLib.ProgressBar pbConvertir
Height = 270
Left = 2835
TabIndex = 20
Top = 150
Width = 5340
_ExtentX = 9419
_ExtentY = 476
_Version = 393216
Appearance = 0
End
Begin VB.Label lblCouleur
AutoSize = -1 'True
Caption = "Couleur"
BeginProperty Font
Name = "Arial"
Size = 9
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 225
Left = 2235
TabIndex = 23
Top = 60
Width = 660
End
Begin VB.Line Line12
BorderWidth = 2
X1 = 71
X2 = 64
Y1 = 296
Y2 = 308
End
Begin VB.Line Line11
BorderWidth = 2
X1 = 59
X2 = 65
Y1 = 296
Y2 = 308
End
Begin VB.Line Line10
BorderWidth = 2
X1 = 65
X2 = 65
Y1 = 288
Y2 = 308
End
Begin VB.Line Line9
BorderWidth = 2
X1 = 82
X2 = 77
Y1 = 80
Y2 = 90
End
Begin VB.Line Line8
BorderWidth = 2
X1 = 71
X2 = 76
Y1 = 80
Y2 = 89
End
Begin VB.Line Line7
BorderWidth = 2
X1 = 82
X2 = 77
Y1 = 175
Y2 = 185
End
Begin VB.Line Line6
BorderWidth = 2
X1 = 71
X2 = 76
Y1 = 174
Y2 = 184
End
Begin VB.Line Line5
BorderWidth = 2
X1 = 9
X2 = 16
Y1 = 169
Y2 = 181
End
Begin VB.Line Line4
BorderWidth = 2
X1 = 22
X2 = 16
Y1 = 169
Y2 = 181
End
Begin VB.Line Line3
BorderWidth = 2
X1 = 77
X2 = 77
Y1 = 165
Y2 = 184
End
Begin VB.Line Line2
BorderWidth = 2
X1 = 16
X2 = 16
Y1 = 74
Y2 = 181
End
Begin VB.Line Line1
BorderWidth = 2
X1 = 77
X2 = 77
Y1 = 74
Y2 = 90
End
Begin VB.Menu menuImage
Caption = "Image"
Visible = 0 'False
Begin VB.Menu menuImporter
Caption = "&Importer image"
End
Begin VB.Menu menuColler
Caption = "&Coller image"
End
End
End
Attribute VB_Name = "frmImpConv"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Copyright Renaud ILTIS, 2014
'
'renaudiltis@ yahoo.fr
'
'Ce logiciel est un programme informatique servant à piloter une machine de découpe par fil chaud.
'Ce logiciel est régi par la licence CeCILL soumise au droit français et respectant les principes de diffusion des logiciels libres. Vous pouvez
'utiliser, modifier et/ou redistribuer ce programme sous les conditionsde la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
'sur le site "http://www.cecill.info".
'En contrepartie de l'accessibilité au code source et des droits de copie, de modification et de redistribution accordés par cette licence, il n'est
'offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons, seule une responsabilité restreinte pèse sur l'auteur du programme, le
'titulaire des droits patrimoniaux et les concédants successifs.
'A cet égard l'attention de l'utilisateur est attirée sur les risques associés au chargement, à l'utilisation, à la modification et/ou au
'développement et à la reproduction du logiciel par l'utilisateur étant donné sa spécificité de logiciel libre, qui peut le rendre complexe à
'manipuler et qui le réserve donc à des développeurs et des professionnels avertis possédant des connaissances informatiques approfondies. Les
'utilisateurs sont donc invités à charger et tester l'adéquation du logiciel à leurs besoins dans des conditions permettant d'assurer la
'sécurité de leurs systèmes et ou de leurs données et, plus généralement, à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
'Le fait que vous puissiez accéder à cet en-tête signifie que vous avez pris connaissance de la licence CeCILL, et que vous en avez accepté les
'termes.
'
'------
'
'This software is a computer program whose purpose is to control a hot wire foam cutter.
'This software is governed by the CeCILL license under French law and abiding by the rules of distribution of free software. You can use,
'modify and/ or redistribute the software under the terms of the CeCILL license as circulated by CEA, CNRS and INRIA at the following URL
'"http://www.cecill.info".
'As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only
'with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited
'liability.
'In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the
'software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also
'therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore
'encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or
'data to be ensured and, more generally, to use and operate it in the same conditions as regards security.
'The fact that you are presently reading this means that you have had knowledge of the CeCILL license and that you accept its terms.
Option Explicit
Private Sub Form_Load()
Me.KeyPreview = True 'pour intercepter Ctrl+v
With frmImpConv
.Top = frmMiniCut2d.Top + frmMiniCut2d.Height * 0.2
.Left = frmMiniCut2d.Left + 600
.Height = frmMiniCut2d.Height - frmMiniCut2d.Height * 0.2 - 110
.Width = frmMiniCut2d.Width - 700
End With
With pctCouleurOriginale
.ScaleMode = vbPixels
.AutoRedraw = True
.Appearance = 0
.AutoSize = True
.Visible = False
.ZOrder
End With
With pctCouleurRedim
.ScaleMode = vbPixels
.AutoRedraw = True
.Appearance = 0
.ZOrder
End With
With pctNoirBlancRedim
.ScaleMode = vbPixels
.AutoRedraw = True
.Appearance = 0
.Top = pctCouleurRedim.Top
.Left = pctCouleurRedim.Left
.Visible = False
End With
With pctCouleurOriginaleRecadree
.ScaleMode = vbPixels
.AutoRedraw = True
.Appearance = 0
.Visible = False
End With
With pctVisuVecto
.ScaleMode = vbPixels
.AutoRedraw = True
.Appearance = 0
.Top = pctCouleurRedim.Top
.Left = pctCouleurRedim.Left
.Visible = False
.ZOrder
.ScaleTop = .ScaleHeight 'inversion de l'axe Y
.ScaleHeight = -.ScaleHeight
End With
With pbConvertir
.Visible = False
.Left = pctCouleurRedim.Left + 5
.Top = pctCouleurRedim.Top + 5
.Value = 0
.ZOrder
End With
lblCouleur.Caption = ""
pbConvertir.ZOrder
pctCouleurRedim.Visible = False
LargeurMaxiPct = frmImpConv.ScaleWidth - pctCouleurRedim.Left - 5 'mémorisation des dimensions relatives de pctCouleurRedim
HauteurMaxiPct = frmImpConv.ScaleHeight - 26
COMDLG.Filter = "Images(*.bmp; *.jpg)|*.bmp; *.jpg"
lblSensibilite.Caption = hscSensibilite.Value
lblLissageVecto.Caption = hscLissageVecto.Value
ToleranceNoir = hscSensibilite.Value
blnImageTracee = True
blnRecadree = False
blnSelected = False
cmdRecadrerLaSelection.Enabled = False
cmdContoursLissageTransfert.Enabled = False
chkVoirPointsVecto.Enabled = False
hscLissageVecto.Enabled = False
optInterieur(0).Enabled = False
optInterieur(1).Enabled = False
optApercu(0).Enabled = False
optApercu(1).Enabled = False
cmdSauverVecto.Enabled = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
If frmImpConv.Visible = True Then
If NbSequVecto <> 0 Then
Call MiseEchelleMachine
Sequ = SequVecto
NbSequ = NbSequVecto
NumSequSel = 0 'initialisation pour mouse_move
NbSequSel = 0
CoeffBloc = 1 'reset car nouveau fichier
Call frmMiniCut2d.CalculAffichageInitial
Call frmMiniCut2d.TraceSequ
End If
Erase BitsPict
Erase MatricePict
Erase MatriceBinaire
Erase CopieMatriceBinaire
Erase Contours
Erase NumeroMarqueurs
Erase profil
Erase SequVecto
Erase SequVectoTrace
NbSequVecto = 0
pctCouleurOriginale.Cls
pctCouleurRedim.Cls
pctNoirBlancRedim.Cls
pctCouleurOriginaleRecadree.Cls
pctVisuVecto.Cls
End If
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim CtrlDown As Integer
'Définition des constantes
Const vbCtrlMask As Integer = 2
CtrlDown = (Shift And vbCtrlMask) > 0
If KeyCode = vbKeyV Then ' interception de Ctrl+v
If CtrlDown Then
cmdImporterImage(1).Value = True 'on clique sur le bouton "coller"
End If
End If
End Sub
Private Sub Form_Resize()
LargeurMaxiPct = frmImpConv.ScaleWidth - pctCouleurRedim.Left - 5 'mémorisation des dimensions relatives de pctCouleurRedim
HauteurMaxiPct = frmImpConv.ScaleHeight - 26
If pctVisuVecto.Visible = True Then
Call RepresenterVecto
End If
End Sub
Private Sub cmdImporterImage_Click(Index As Integer)
Dim ImagePressePapier As Boolean
'importation de l'image originale par ouverture fichier ou collage presse-papier
flagVectoRedimCourses = False
pctCouleurOriginale.Cls 'premier truc à faire pour vider la mémoire
pctCouleurRedim.Cls
pctNoirBlancRedim.Cls
pctCouleurOriginaleRecadree.Cls
pctVisuVecto.Cls
Erase SequVecto
Erase BitsPict
Erase MatricePict
Erase MatriceBinaire
Erase CopieMatriceBinaire
Erase Contours
NbSequVecto = 0
Shape1.Move 1, 1, 1, 1 'fait disparaître le cadre de sélection
On Error GoTo Erreur
Select Case Index
Case 0 'ouvrir un fichier
blnImageTracee = False
COMDLG.ShowOpen
If COMDLG.FileName = "" Then
Exit Sub
End If
pctCouleurOriginale.Picture = LoadPicture(COMDLG.FileName) 'pctCouleurOriginale contient l'image initiale
Case 1 'coller le contenu du presse-papier
ImagePressePapier = False
If Clipboard.GetFormat(vbCFBitmap) Or Clipboard.GetFormat(vbCFDIB) Then
ImagePressePapier = True
Else
MsgBox "Le presse-papier ne contient pas d'image compatible."
Exit Sub
End If
blnImageTracee = False
pctCouleurOriginale.Picture = Clipboard.GetData
End Select
pctCouleurRedim.Visible = True
pctNoirBlancRedim.Visible = False
lblCouleur.Visible = True
Call TransferOriginaleDansRedim 'redimensionnement pour affichage à l'écran en taille maxi
'initialisation des contrôles
cmdRecadrerLaSelection.Enabled = True
If optApercu(1).Value = False Then optApercu(1).Value = True
If optApercu(0).Enabled = False Then optApercu(0).Enabled = True
blnSelected = False
Exit Sub
Erreur:
MsgBox "Impossible d'afficher l'image"
End Sub
Private Sub TransferOriginaleDansRedim()
'redimensionnement pour affichage à l'écran en taille maxi
pctCouleurRedim.AutoRedraw = True
pctCouleurRedim.Cls
If pctCouleurOriginale.Height > HauteurMaxiPct Or pctCouleurOriginale.Width > LargeurMaxiPct Then
'si l'image est trop grande, on la redimensionne pour l'affichage
If pctCouleurOriginale.Width / pctCouleurOriginale.Height >= LargeurMaxiPct / HauteurMaxiPct Then
pctCouleurRedim.Width = LargeurMaxiPct
pctCouleurRedim.Height = pctCouleurRedim.Width * pctCouleurOriginale.Height / pctCouleurOriginale.Width
Else
pctCouleurRedim.Height = HauteurMaxiPct
pctCouleurRedim.Width = pctCouleurRedim.Height * pctCouleurOriginale.Width / pctCouleurOriginale.Height
End If
pctCouleurRedim.PaintPicture pctCouleurOriginale.Image, 2, 2, pctCouleurRedim.Width - 6, pctCouleurRedim.Height - 6 'pctCouleurRedim affiche l'image redimensionnée
Else 'sinon affichage à la taille d'origine
pctCouleurRedim.Height = pctCouleurOriginale.ScaleHeight
pctCouleurRedim.Width = pctCouleurOriginale.ScaleWidth
pctCouleurRedim.AutoRedraw = True
pctCouleurRedim.AutoSize = True
pctCouleurRedim.Picture = pctCouleurOriginale.Picture
End If
pbConvertir.Width = pctCouleurRedim.Width - 10
pctNoirBlancRedim.Width = pctCouleurRedim.Width
pctNoirBlancRedim.Height = pctCouleurRedim.Height
pctCouleurRedim.ZOrder
pctCouleurRedim.Visible = True
lblCouleur.Caption = Label(36) 'image couleur ou niveaux de gris
DoEvents 'pour déclencher éventuellement le mousedown/up sur la picturebox en-dessous
blnImageTracee = True
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'effacer la croix sur le plan temporaire quand on n'est plus sur le pctbox de l'image
pctCouleurRedim.AutoRedraw = False
pctCouleurRedim.Cls
pctCouleurRedim.AutoRedraw = True
End Sub
Private Sub hscLissageVecto_Change()
lblLissageVecto.Caption = hscLissageVecto.Value
End Sub
Private Sub hscLissageVecto_Scroll()
lblLissageVecto.Caption = hscLissageVecto.Value
End Sub
Private Sub pctCouleurRedim_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
'tracé du rectangle de sélection ou menu clic-droit
Select Case Button
Case vbLeftButton
If blnImageTracee = True Then
With RectangleSelection
blnSelected = False
OrigX = CInt(x)
OrigY = CInt(y)
.Left = OrigX
.Top = OrigY
.Right = OrigX
.Bottom = OrigY
Shape1.Move .Left, .Top, (.Right - .Left), (.Bottom - .Top)
End With
End If
Case vbRightButton
PopupMenu menuImage
End Select
End Sub
Private Sub pctCouleurRedim_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'rectangle et croix de sélection sur pctCouleurRedim
'les valeurs du rectangle de sélection sont mémorisées dans une entité "RectangleSelection"
If Button = vbKeyLButton Then
If blnImageTracee = True Then
pctCouleurRedim.AutoRedraw = False
pctCouleurRedim.Cls
With RectangleSelection
If x < OrigX Then
.Left = x
ElseIf x > OrigX Then
.Right = x
Else
.Left = x
.Right = x
End If
If y < OrigY Then
.Top = y
ElseIf y > OrigY Then
.Bottom = y
Else
.Top = y
.Bottom = y
End If
Shape1.Move .Left, .Top, .Right - .Left, .Bottom - .Top
End With
pctCouleurRedim.AutoRedraw = True
End If
Else
With pctCouleurRedim
.AutoRedraw = False
.Cls
pctCouleurRedim.Line (0, y)-(.Width, y), vbRed
pctCouleurRedim.Line (x, 0)-(x, .Height), vbRed
.AutoRedraw = True
End With
End If
End Sub
Private Sub pctCouleurRedim_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
'fin sélection
With RectangleSelection
If Abs(.Right - .Left) > 2 And Abs(.Top - .Bottom) > 2 Then
blnSelected = True
cmdRecadrerLaSelection.Enabled = True
End If
End With
End Sub
Private Sub cmdRecadrerLaSelection_Click()
'recadrer en fonction du rectangle de sélection
If blnSelected Then
CoeffRedim = pctCouleurOriginale.Width / pctCouleurRedim.Width 'coeff de proportionnalité entre les deux picturebox (l'originale et celle affichée)
'on va redimensionner les pctbox de visu pour qu'elles aient le même rapport H/L que la sélection
With RectangleSelection
If Abs(.Right - .Left) / Abs(.Bottom - .Top) > LargeurMaxiPct / HauteurMaxiPct Then
pctCouleurRedim.Width = LargeurMaxiPct
pctCouleurRedim.Height = LargeurMaxiPct * Abs(.Bottom - .Top) / Abs(.Right - .Left)
pctCouleurRedim.Cls
Else
pctCouleurRedim.Height = HauteurMaxiPct
pctCouleurRedim.Width = HauteurMaxiPct * Abs(.Right - .Left) / Abs(.Bottom - .Top)
pctCouleurRedim.Cls
End If
pctNoirBlancRedim.Height = pctCouleurRedim.Height
pctNoirBlancRedim.Width = pctCouleurRedim.Height
pctCouleurRedim.Cls
pctNoirBlancRedim.Cls
pctCouleurOriginaleRecadree.Cls
pctCouleurOriginaleRecadree.Width = Abs(.Right - .Left) * CoeffRedim
pctCouleurOriginaleRecadree.Height = Abs(.Bottom - .Top) * CoeffRedim
pctCouleurRedim.AutoRedraw = True
pctCouleurRedim.PaintPicture pctCouleurOriginale.Image, 0, 0, pctCouleurRedim.Width, pctCouleurRedim.Height, _
.Left * CoeffRedim, .Top * CoeffRedim, Abs(.Right - .Left) * CoeffRedim, Abs(.Bottom - .Top) * CoeffRedim
pctCouleurOriginaleRecadree.PaintPicture pctCouleurOriginale.Image, 0, 0, pctCouleurOriginaleRecadree.Width, pctCouleurOriginaleRecadree.Height, _
.Left * CoeffRedim, .Top * CoeffRedim, Abs(.Right - .Left) * CoeffRedim, Abs(.Bottom - .Top) * CoeffRedim
Shape1.Move 1, 1, 1, 1
.Left = 0
.Right = 0
.Top = 0
.Bottom = 0
End With
blnRecadree = True
cmdRecadrerLaSelection.Enabled = False 'on ne peut recadrer qu'une fois
End If
blnSelected = False
End Sub
Private Sub optApercu_Click(Index As Integer)
flagVectoRedimCourses = False
Select Case Index
Case 0 'passage en noir et blanc
If blnSelected = True Then 'si un cadre est tracé, on applique la sélection
cmdRecadrerLaSelection.Value = True
End If
Call ImageVersMatrice(pctCouleurRedim) 'on travaille pour l'instant uniquement sur l'image réduite pour ne pas avoir
pctNoirBlancRedim.Width = LargeurPictDestination ' à calculer le noir et blanc sur l'image totale
pctNoirBlancRedim.Height = HauteurPictDestination
Call MatriceVersNoirBlanc(True, pctNoirBlancRedim) 'true = pas de matrice binaire, uniquement de la visu
lblCouleur.Caption = Label(37) 'image en noir et blanc
pctNoirBlancRedim.Visible = True
pctCouleurRedim.Visible = False
optApercu(0).Enabled = False
optApercu(1).Enabled = True
cmdContoursLissageTransfert.Enabled = True
cmdSauverVecto.Enabled = False
chkVoirPointsVecto.Enabled = True
hscLissageVecto.Enabled = True
optInterieur(0).Enabled = True
optInterieur(1).Enabled = True
Case 1 'annulation
pctVisuVecto.Visible = False
pctCouleurRedim.Visible = True
pctNoirBlancRedim.Visible = False
cmdContoursLissageTransfert.Enabled = False
cmdSauverVecto.Enabled = False
chkVoirPointsVecto.Enabled = False
hscLissageVecto.Enabled = False
optInterieur(0).Enabled = False
optInterieur(1).Enabled = False
optApercu(0).Enabled = True
optApercu(1).Enabled = False
End Select
cmdRecadrerLaSelection.Enabled = False 'on ne peut plus recadrer
End Sub
Private Sub hscSensibilite_Change()
If optApercu(1).Value = False Then optApercu(1).Value = True
lblSensibilite.Caption = hscSensibilite.Value
ToleranceNoir = hscSensibilite.Value
End Sub
Private Sub ImageVersMatrice(Picture As PictureBox) '
'Copie de l'image vers une matrice
Dim i As Long, j As Long
Dim Z As Long
Dim k As Long, D As Long
Dim InfoPict As BITMAP
Dim NL As Integer 'numéro de ligne
GetObject Picture.Image, Len(InfoPict), InfoPict
Size = InfoPict.bmWidth * InfoPict.bmBitsPixel * InfoPict.bmHeight / 8
ReDim BitsPict(Size) As Byte
ReDim MatricePict(InfoPict.bmHeight, InfoPict.bmWidth) ' As Pixel
pbConvertir.Min = 0
pbConvertir.Max = 2 * InfoPict.bmHeight * (InfoPict.bmWidth + 1) / 1000
pbConvertir.Visible = True
pbConvertir.ZOrder
GetBitmapBits Picture.Image, Size, BitsPict(1)
k = InfoPict.bmWidth * 4
For i = 1 To InfoPict.bmHeight
D = ((i - 1) * k) + 1
For j = 1 To InfoPict.bmWidth
Z = D + ((j - 1) * 4)
MatricePict(i, j).Blue = BitsPict(Z)
MatricePict(i, j).Green = BitsPict(Z + 1)
MatricePict(i, j).Red = BitsPict(Z + 2)
Next j
pbConvertir.Value = Int(i * j / 1000)
Next i
pbConvertir.Visible = False
Erase BitsPict 'on libère la mémoire
HauteurPictDestination = InfoPict.bmHeight + 2
LargeurPictDestination = InfoPict.bmWidth + 2
End Sub
Private Sub MatriceVersNoirBlanc(PourVisu As Boolean, Optional Picture As PictureBox)
'si PourVisu=true on fait uniquement l'image
'si PouVisu=false, on fait uniquement la matrice binaire pour détection des contours
Dim i As Long, j As Long
Dim UBy As Integer
Dim Z As Long
Dim Mx As Long, My As Long
' On Error GoTo Erreur
'Copie de la matrice vers picture contours noir
If PourVisu = True Then 'on va représenter l'image noir et blanc
ReDim BitsPict(UBound(MatricePict(), 1) * UBound(MatricePict(), 2) * 4)
Else
'Copie vers une matrice binaire pour détection des contours
'******** ATTENTION : on va ajouter une
'******** bordure "blanche" (=0) tout autour de l'image
'******** dans la matrice binaire => on commence à 0 et on termine à ubound+1
'ATTENTION : inversion des X et Y...
ReDim MatriceBinaire(0 To UBound(MatricePict(), 2) + 1, 0 To UBound(MatricePict(), 1) + 1)
'le tableau est créé "vide", donc il n'y a rien besoin de faire, il faut juste mettre les
'valeurs à l'intérieur du rectangle
'00000000000000000000000000
'0vvvvvvvvvvvvvvvvvvvvvvvv0
'0vvvvvvvvvvvvvvvvvvvvvvvv0
'0vvvvvvvvvvvvvvvvvvvvvvvv0
'00000000000000000000000000
End If
Z = 0
UBy = UBound(MatricePict(), 1) + 1 'pour remettre les Y de bas en haut dans la matrice de 0 et de 1
'on paramètre la progressbar
pbConvertir.Min = 0
pbConvertir.Max = 2 * UBound(MatricePict(), 1) * (UBound(MatricePict(), 2) + 1) / 1000