|
-
Jun 25th, 2002, 11:11 PM
#1
Thread Starter
Hyperactive Member
How to get the pixel and chek them for a pirticular color
i m making a digital image processing assigment.
what i want is that i have to draw a closed selection on
a picture in a picture box..
this i have done ..but i need that all color inside
the selction then would be black and out side the selection would be white..
but i am puzzeled how to do it .. can n e one willing
to help me i m writing my code .
I m drawing the line in a perticular color and cheking it in a function mask that if this perticualr combination of color exist then till another this type of color exist make the color black i.e 0 else every other thing is black.. but its not working.. 
VB Code:
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
If Button = 1 Then Picture1.Line (A, B)-(x, Y), RGB(100, 195, 155)
A = x: B = Y
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, x As Single, Y As Single)
If Button = 1 Then Picture1.Line (x, Y)-(x + 15, Y + 15)
End Sub
Private Sub mask(ByVal picColor As PictureBox)
Picture2 = Picture1
Dim x, Y, countz As Integer
Dim red, green, blue, gray As Byte
GetObject picColor.Image, Len(bm), bm
wid = bm.BMPWidth
hgt = bm.BMPHeight
ReDim bytes(0 To bm.BMPWidthBytes - 1, 0 To hgt - 1)
GetBitmapBits picColor.Image, bm.BMPWidthBytes * bm.BMPHeight, bytes(0, 0)
ProgressBar1.Min = 0
ProgressBar1.Max = hgt - 1
' Convert the data to gray scale.
For Y = 0 To hgt - 1
For x = 0 To wid - 1 Step 3
' Get the current pixel value.
red = bytes(x * 3, Y)
green = bytes(x * 3 + 1, Y)
blue = bytes(x * 3 + 2, Y)
While (red = 100) And (green = 195) And (blue = 155)
bytes(x * 3, Y) = 0
bytes(x * 3 + 1, Y) = 0
bytes(x * 3 + 2, Y) = 0
Wend
bytes(x * 3, Y) = 255
bytes(x * 3 + 1, Y) = 255
bytes(x * 3 + 2, Y) = 255
Next x
ProgressBar1.Value = Y
Next Y
' Set the new pixel values.
SetBitmapBits picColor.Image, _
bm.BMPWidthBytes * bm.BMPHeight, bytes(0, 0)
picColor.Picture = picColor.Image
End Sub
Last edited by Kirun; Jun 26th, 2002 at 02:59 AM.
-
Jun 26th, 2002, 03:02 AM
#2
Thread Starter
Hyperactive Member
hey...
not any buddu willing 2 help me
-
Jun 26th, 2002, 03:57 AM
#3
Frenzied Member
Well, since your request is that the outside be entirely white
while the inside be entirely black, you should just get the
x1,x2,,y1,y2 coordinates of the selection then just make a black
square over the white sqaure. I didn't read your code yet, but i
will now.
-
Jun 26th, 2002, 03:59 AM
#4
Frenzied Member
I'm no graphics developer, but i say your code sucks. Just kidding.
To be honest, i have no idea what your code means. It seems
immensely complicated.
-
Jun 29th, 2002, 12:44 PM
#5
Lively Member
uh, you could create an array of booleans which then stated which ones are selected and which ones arnt
VB Code:
for i = 1 to picture1.width
for j= 1 to picture1.height
if selected(i,j) = true then
picture1.pset (i,j),vbwhite
else
picture1.pset (i,j),vbblack
end if
next j
doevents
next i
it woudl be a pain to set up the selected array, but it obviously can be done...
sry if thats nto what you want, that was just my interpetation of your problem after reading the post several times.
-
Jun 30th, 2002, 03:51 PM
#6
Fanatic Member
Off Subject: How did u get the archon image as ur avatar
-
Jun 30th, 2002, 04:18 PM
#7
Lively Member
uploading is always a method
-
Jun 30th, 2002, 06:29 PM
#8
Frenzied Member
Originally posted by Mushroom Realm
Off Subject: How did u get the archon image as ur avatar
I ripped the GIF file from the StarCraft.MPQ.
-
Jul 6th, 2002, 03:18 PM
#9
Fanatic Member
Some of the units also have their animated portrats on blizzard's starcraft strat guide. Its located at: http://www.battle.net/scc/
-
Jul 11th, 2002, 09:40 AM
#10
New Member
I had a quick mess about and the following code checks for when a shape has been closed and then does as you requested.
The code isn't perfect but hopefully it will be useful to you. 
Option Explicit
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private lXPos As Long, lYPos As Long
Private Sub picDisplay_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lXCount As Integer, lYcount As Integer
Dim lLineStart As Long, lLineEnd As Long
Dim bBorderFound As Boolean
If Button = vbLeftButton Then
picDisplay.Line (lXPos, lYPos)-(X, Y), RGB(100, 195, 155)
If GetPixel(picDisplay.hdc, X / 15, Y / 15) = 10208100 Then
For lYcount = 1 To picDisplay.Height Step 15
bBorderFound = False
lLineStart = 0
lLineEnd = 0
For lXCount = 1 To picDisplay.Width Step 15
If GetPixel(picDisplay.hdc, lXCount / 15, lYcount / 15) = 10208100 Then bBorderFound = True
If bBorderFound = True Then
lLineStart = lXCount + 1
Exit For
Else
picDisplay.PSet (lXCount, lYcount), RGB(255, 255, 255)
End If
Next 'lXCount
bBorderFound = False
For lXCount = picDisplay.Width To 1 Step -15
If GetPixel(picDisplay.hdc, lXCount / 15, lYcount / 15) = 10208100 Then bBorderFound = True
If bBorderFound = True Then
lLineEnd = lXCount - 1
Exit For
Else
picDisplay.PSet (lXCount, lYcount), RGB(255, 255, 255)
End If
Next 'lXCount
If lLineEnd > lLineStart Then
picDisplay.Line (lLineStart, lYcount)-(lLineEnd, lYcount), RGB(0, 0, 0)
End If
picDisplay.Refresh
Next 'lYCount
End If
End If
lXPos = X
lYPos = Y
End Sub
Private Sub picDisplay_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then picDisplay.Line (X, Y)-(X + 15, Y + 15)
End Sub
Help this helps.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|