Membuat Image Transparan
Adobe Photoshop mempunyai fasilitas yang disebut dengan blending option. Ketika sebuah layer hendak diletakkan di atas layer yang lain, maka layer di atasnya bisa diset untuk
menumpuk layer dibawahnya dengan berbagai macam model, seperti hard light, soft light, difference, multiply, screen, dan sebagainya.
Tip kali ini adalah membuat efek blend dengan mode Lighten, Darken, Difference, dan Screen. Logika yang digunakan adalah mengambil nilai RGB pixel dari area yang hendak di-blend.
RGP Pixel tersebut akan diolah berdasar jenis blend yang diterapkan.
Langkah-langkahnya adalah:
1) Buat form yang terdiri dari sebuah dua buah picture box (dengan nama picture1 untuk citra yang asli, dan picture2 untuk citra yang hendak di-blend), serta 5 buah command button
dengan nama command1 (untuk Blend light), command2 (untuk Blend screen), command3 (untuk Blend Diff), command4 (untuk Blend Clear hasil blend).
2) Deklarasi awalnya mendefinisikan sebuah tipe bernama pixel untuk memudahkan pemrosesan setiap pixel-nya:
Option Explicit
Private Type Pixel 'warna 24 bit
blue As Integer
green As Integer
red As Integer
Trans As Integer
End Type
Dim a As Pixel, b As Pixel, c As Pixel
Fungsi-fungsi yang dibutuhkan adalah:
Private Function MaxB(ByVal inValA As Byte,
ByVal inValB As Byte) As Byte
MaxB = IIf(inValA > inValB, inValA,
inValB)
End Function
Private Function MinB(ByVal inValA As Byte,
ByVal inValB As Byte) As Byte
MinB = IIf(inValA < pixtolong =" RGB(.red," checkhighbyte =" IIf(inVal"> 255, 255,
nVal)
End Function
Private Function BlendLight(inPixA As Pixel,
inPixB As Pixel) As Pixel
With BlendLight ' Blend dengan mode
lighten
.red = MaxB(inPixA.red, inPixB.red)
.green = MaxB(inPixA.green, inPixB.
green)
.blue = MaxB(inPixA.blue, inPixB.blue)
End With
End Function
Private Function BlendDark(ByRef inPixA As
Pixel, ByRef inPixB As Pixel) As Pixel
With BlendDark ' Blend dengan mode darken
.red = MinB(inPixA.red, inPixB.red)
.green = MinB(inPixA.green, inPixB.
green)
.blue = MinB(inPixA.blue, inPixB.blue)
End With
End Function
Private Function BlendDiff(ByRef inPixA As
Pixel, ByRef inPixB As Pixel) As Pixel
With BlendDiff ' Blend dengan mode
difference
.red = Abs(inPixA.red - inPixB.red)
.green =
Abs(inPixA.green -
inPixB.
green)
.blue =
Abs(inPixA.blue -
inPixB.blue)
End With
End Function
Private Function
BlendScrn(inPixA As
Pixel,
inPixB As Pixel) As
Pixel
With BlendScrn
'Blend dengan mode
screen
.red =
CheckHighByte(inPixA.
red * (1 +
(inPixB.red / 255)))
.green =
CheckHighByte(inPixA.
green *
(1 + (inPixB.green /
255)))
.blue =
CheckHighByte(inPixA.
blue * (1
+ (inPixB.blue / 255)))
End With
End Function
Private Function LongToPix(inCol As Long) As
Pixel
With LongToPix 'Konversi dari long ke
piksel
.red = inCol And &HFF
.green = (inCol \ &H100) And &HFF
.blue =
(inCol \ &H10000)
And &HFF
End With
End Function
Private Sub
Blend(area As
PictureBox, x1 As
Integer, y1 As
Integer, X As
Integer, Y As
Integer, a As Pixel,
mode As Long)
Dim pix As Pixel
Dim bits_per_
pixel As Integer
Dim xc As
Integer, yc As
Integer
If y1 > Y Then
yc = Y
Y = y1
y1 = yc
End If
If x1 > X Then
xc = X
X = x1
Pemrograman
x1 = xc
End If
For yc = y1 To Y
For xc = x1 To X
pix = LongToPix(area.Point(xc, yc))
Select Case mode
Case 1: pix = BlendScrn(a, pix)
Case 2: pix = BlendLight(a, pix)
Case 3: pix = BlendDiff(a, pix)
Case 4: pix = BlendDark(a, pix)
End Select
area.PSet (xc, yc), PixToLong(pix)
Next xc
Next yc
End Sub
3) Event yang dicegat untuk masing-masing klik dari command button adalah:
Private Sub Command1_Click()
Blend Picture2, 10, 10, 100, 100, a, 1
Blend Picture2, 10, 110, 100, 210, b, 1
Blend Picture2, 110, 10, 200, 100, c, 1
End Sub
Private Sub Command2_Click()
Blend Picture2, 10, 10, 100, 100, a, 2
Blend Picture2, 10, 110, 100, 210, b, 2
Blend Picture2, 110, 10, 200, 100, c, 2
End Sub
Private Sub Command3_Click()
Blend Picture2, 10, 10, 100, 100, a, 3
Blend Picture2, 10, 110, 100, 210, b, 3
Blend Picture2, 110, 10, 200, 100, c, 3
End Sub
Private Sub Command4_Click()
Blend Picture2, 10, 10, 100, 100, a, 4
Blend Picture2, 10, 110, 100, 210, b, 4
Blend Picture2, 110, 10, 200, 100, c, 4
End Sub
Private Sub Command5_Click()
Set Picture2 = Picture1
End SubPrivate Sub Form_Load()
a.blue = 128
a.green = 0
a.red = 128
b.blue = 128
b.green = 128
b.red = 0
c.blue = 0
c.green = 128
c.red = 128
End SubOhya, baca juga artikel: Nissan X-trail Mobil SUV Tangguh dan Sporty Terbaik
4) Simpan dan jalankan program.
dengan nama command1 (untuk Blend light), command2 (untuk Blend screen), command3 (untuk Blend Diff), command4 (untuk Blend Clear hasil blend).
2) Deklarasi awalnya mendefinisikan sebuah tipe bernama pixel untuk memudahkan pemrosesan setiap pixel-nya:
Option Explicit
Private Type Pixel 'warna 24 bit
blue As Integer
green As Integer
red As Integer
Trans As Integer
End Type
Dim a As Pixel, b As Pixel, c As Pixel
Fungsi-fungsi yang dibutuhkan adalah:
Private Function MaxB(ByVal inValA As Byte,
ByVal inValB As Byte) As Byte
MaxB = IIf(inValA > inValB, inValA,
inValB)
End Function
Private Function MinB(ByVal inValA As Byte,
ByVal inValB As Byte) As Byte
MinB = IIf(inValA < pixtolong =" RGB(.red," checkhighbyte =" IIf(inVal"> 255, 255,
nVal)
End Function
Private Function BlendLight(inPixA As Pixel,
inPixB As Pixel) As Pixel
With BlendLight ' Blend dengan mode
lighten
.red = MaxB(inPixA.red, inPixB.red)
.green = MaxB(inPixA.green, inPixB.
green)
.blue = MaxB(inPixA.blue, inPixB.blue)
End With
End Function
Private Function BlendDark(ByRef inPixA As
Pixel, ByRef inPixB As Pixel) As Pixel
With BlendDark ' Blend dengan mode darken
.red = MinB(inPixA.red, inPixB.red)
.green = MinB(inPixA.green, inPixB.
green)
.blue = MinB(inPixA.blue, inPixB.blue)
End With
End Function
Private Function BlendDiff(ByRef inPixA As
Pixel, ByRef inPixB As Pixel) As Pixel
With BlendDiff ' Blend dengan mode
difference
.red = Abs(inPixA.red - inPixB.red)
.green =
Abs(inPixA.green -
inPixB.
green)
.blue =
Abs(inPixA.blue -
inPixB.blue)
End With
End Function
Private Function
BlendScrn(inPixA As
Pixel,
inPixB As Pixel) As
Pixel
With BlendScrn
'Blend dengan mode
screen
.red =
CheckHighByte(inPixA.
red * (1 +
(inPixB.red / 255)))
.green =
CheckHighByte(inPixA.
green *
(1 + (inPixB.green /
255)))
.blue =
CheckHighByte(inPixA.
blue * (1
+ (inPixB.blue / 255)))
End With
End Function
Private Function LongToPix(inCol As Long) As
Pixel
With LongToPix 'Konversi dari long ke
piksel
.red = inCol And &HFF
.green = (inCol \ &H100) And &HFF
.blue =
(inCol \ &H10000)
And &HFF
End With
End Function
Private Sub
Blend(area As
PictureBox, x1 As
Integer, y1 As
Integer, X As
Integer, Y As
Integer, a As Pixel,
mode As Long)
Dim pix As Pixel
Dim bits_per_
pixel As Integer
Dim xc As
Integer, yc As
Integer
If y1 > Y Then
yc = Y
Y = y1
y1 = yc
End If
If x1 > X Then
xc = X
X = x1
Pemrograman
x1 = xc
End If
For yc = y1 To Y
For xc = x1 To X
pix = LongToPix(area.Point(xc, yc))
Select Case mode
Case 1: pix = BlendScrn(a, pix)
Case 2: pix = BlendLight(a, pix)
Case 3: pix = BlendDiff(a, pix)
Case 4: pix = BlendDark(a, pix)
End Select
area.PSet (xc, yc), PixToLong(pix)
Next xc
Next yc
End Sub
3) Event yang dicegat untuk masing-masing klik dari command button adalah:
Private Sub Command1_Click()
Blend Picture2, 10, 10, 100, 100, a, 1
Blend Picture2, 10, 110, 100, 210, b, 1
Blend Picture2, 110, 10, 200, 100, c, 1
End Sub
Private Sub Command2_Click()
Blend Picture2, 10, 10, 100, 100, a, 2
Blend Picture2, 10, 110, 100, 210, b, 2
Blend Picture2, 110, 10, 200, 100, c, 2
End Sub
Private Sub Command3_Click()
Blend Picture2, 10, 10, 100, 100, a, 3
Blend Picture2, 10, 110, 100, 210, b, 3
Blend Picture2, 110, 10, 200, 100, c, 3
End Sub
Private Sub Command4_Click()
Blend Picture2, 10, 10, 100, 100, a, 4
Blend Picture2, 10, 110, 100, 210, b, 4
Blend Picture2, 110, 10, 200, 100, c, 4
End Sub
Private Sub Command5_Click()
Set Picture2 = Picture1
End SubPrivate Sub Form_Load()
a.blue = 128
a.green = 0
a.red = 128
b.blue = 128
b.green = 128
b.red = 0
c.blue = 0
c.green = 128
c.red = 128
End SubOhya, baca juga artikel: Nissan X-trail Mobil SUV Tangguh dan Sporty Terbaik
4) Simpan dan jalankan program.
8 komentar:
Mas, ada ga cara untuk mendapatkan penghasilan dari membuat program..? di internet misalnya ?
saya malah baru mau belajar nih
Bagus juga, bukannya vb yang baru sudah memberikannya secara lebih mudah ya.
all :
>>Tahnx yach dah mampir.
sniper blog :
>> da tuch, tapi kita musti kudu promosi dulu, misalnya pada situs2 pembuatan jasa skripsi dan program tugas akhir, mereka mengenakan biaya tersendiri.
atau situs2 pembuatan website spt webmedia.
mereka mengenakan biaya yang amat mahal.
eh gitu, yach.
Makasii yach informasinya....?!
:)
Keren sob. tutorial yang sangat bermanfaat buat orang yg minim tentang vb kayak saya :D
duh seru iahhh...jd mw lbh bnyak menelusuri ttg vb
tak save dulu mas ntar tak coba :D
Posting Komentar