VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



TV Lines Image Filter

by Jared Collums (3 Submissions)
Category: Graphics
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

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

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).
Assumes
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

Rate TV Lines Image Filter

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

Download this snippet    Add to My Saved Code

TV Lines Image Filter Comments

No comments have been posted about TV Lines Image Filter. Why not be the first to post a comment about TV Lines Image Filter.

Post your comment

Subject:
Message:
0/1000 characters