Dim As Integer As Integer Private Sub CmdOpen_Click funzione che caric

 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
Dim r As Integer, c As Integer
Private Sub CmdOpen_Click() 'funzione che carica immagine nella PictureBox1
CommonDialog1.ShowOpen 'componente chiamato Common File dialog
Picture1.Picture = LoadPicture(CommonDialog1.FileName)
Picture2.Height = Picture1.Height
Picture2.Width = Picture1.Width
End Sub
Private Sub CmdGrayscale_Click() 'scala di griggio
Dim pix As Long
Dim media As Long
Dim red As Integer, blu As Integer, green As Integer
For r = 0 To Picture1.ScaleHeight + 100
For c = 0 To Picture1.ScaleWidth
pix = Picture1.Point(r, c)
green = pix Mod 256
pix = Int(pix / 256)
red = pix Mod 256
pix = Int(pix / 256)
pix = Int(pix / 256)
blu = pix
media = (red + green + blu) / 3
media = Abs(media)
pix = RGB(media, media, media) 'si imposta il colore giusto per un pixel
Picture2.PSet (r, c), pix 'si copiano i pixel
Next c
Next r
End Sub
Private Sub CmdRedscale_Click() 'scala di rosso
Dim pix As Long
Dim media As Long
Dim red As Integer, blu As Integer, green As Integer
For r = 0 To Picture1.ScaleHeight + 100
For c = 0 To Picture1.ScaleWidth
pix = Picture1.Point(r, c)
green = pix Mod 256
pix = Int(pix / 256)
red = pix Mod 256
pix = Int(pix / 256)
blu = pix
pix = RGB(Abs(red), 0, 0)
Picture2.PSet (r, c), pix
Next c
Next r
End Sub
Private Sub CmdGreenscale_Click() 'la scala di verde
Dim pix As Long
Dim media As Long
Dim red As Integer, blu As Integer, green As Integer
For r = 0 To Picture1.ScaleHeight + 100
For c = 0 To Picture1.ScaleWidth
pix = Picture1.Point(r, c)
green = pix Mod 256
pix = Int(pix / 256)
red = pix Mod 256
pix = Int(pix / 256)
pix = Int(pix / 256)
blu = pix
pix = RGB(0, Abs(green), 0)
Picture2.PSet (r, c), pix
Next c
Next r
End Sub
Private Sub CmdResize_Click() 'funzione per rimpicciolire immagine
Dim pix As Long
Dim media As Long
For r = 0 To Picture1.ScaleHeight + 100
For c = 0 To Picture1.ScaleWidth
pix = Picture1.Point(r, c)
Picture2.PSet (r / 2, c / 2), pix
Next c
Next r
End Sub
Private Sub CmdRestore_Click() 'funzione per ingrandire immagine
Dim x, y, r, c As Integer
Dim px As Long
For y = 1 To Picture2.ScaleWidth - 1
For x = 1 To Picture2.ScaleHeight - 1
px = Picture2.Point(x, y)
For r = 0 To 1
For c = 0 To 1
Picture1.PSet (x * 2 + r, y * 2 + c), px
Next c
Next r
Next x
Next y
End Sub