Search Tools Links Login

TV Lines Image Filter


Visual Basic 6, or VB Classic

This code puts lines over a picture box's picture. You can set it's opacity, and it's direction.

Original Author: Jared Collums

Inputs

PictBox, the picture box to manipulate. optional Opacity. This controls how transparent/solid the lines are. The value works best with a value 1-100. And direction...wich sets the lines horizontal(1) or vertical(2).

Assumptions

For this to work, the picturebox must have AutoRedraw set, and it's scalemode must be pixels.

Side Effects

if it's a very big image, it might be a tiny bit slow.

API Declarations

Public Declare Function SetPixel Lib "GDI32" (ByVal HDC As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long
Public Declare Function GetPixel Lib "GDI32" (ByVal HDC As Long, ByVal X As Long, ByVal Y As Long) As Long

Code

Public Sub TVLines(PictBox As PictureBox, Optional Direction As Integer, Optional Opacity As Long)
Dim i As Long, k As Long, r As Long, g As Long, b As Long, pixel As Long, pix As Long
If IsMissing(Opacity) Then Opacity = 25
If IsMissing(Direction) Then Direction = 1
Opacity = Opacity * 2.55
Opacity = Round(Opacity)
For k = 0 To PictBox.ScaleHeight - 1
For i = 0 To PictBox.ScaleWidth - 1
'get current pixel
pixel = GetPixel(PictBox.HDC, i, k)

'get rgb values of the pixel
r = TakeRGB(pixel, 0)
g = TakeRGB(pixel, 1)
b = TakeRGB(pixel, 2)

'the code alternates lightness/darkness each line
If Direction = 1 Then
pix = k
Else
pix = i
End If

If pix / 2 = Int(pix / 2) Then
r = IIf(r - Opacity < 0, 0, r - Opacity)
g = IIf(g - Opacity < 0, 0, g - Opacity)
b = IIf(b - Opacity < 0, 0, b - Opacity)
Else
r = IIf(r + Opacity > 255, 255, r + Opacity)
g = IIf(g + Opacity > 255, 255, g + Opacity)
b = IIf(b + Opacity > 255, 255, b + Opacity)
End If

'set new pixel
SetPixel PictBox.HDC, i, k, RGB(r, g, b)
Next i
PictBox.Refresh
Next k
PictBox.Refresh
End Sub
'just a function to get rgb values of a pixel
'I borrowed it from Jongmin Baek's Drawer (an exellect program, btw)
Function TakeRGB(Colors As Long, Index As Long) As Long
IndexColor = Colors
Red = IndexColor - Int(IndexColor / 256) * 256: IndexColor = (IndexColor - Red) / 256
Green = IndexColor - Int(IndexColor / 256) * 256: IndexColor = (IndexColor - Green) / 256
Blue = IndexColor
If Index = 0 Then TakeRGB = Red
If Index = 1 Then TakeRGB = Green
If Index = 2 Then TakeRGB = Blue
End Function

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 92 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.