PDA

View Full Version : رنگ كردن محيط داخلي يك پليگون



vb study
یک شنبه 24 بهمن 1389, 13:21 عصر
با سلام
در برنامه من يك سري خط تشكيل دهنده تعدادي پليگون مي باشند
چطوري ميشه داخل پليگونهاي ايجاد شده را رنگ كرد

AmirHarirbafan
یک شنبه 24 بهمن 1389, 21:49 عصر
این متد رو برای درس گرافیکمون نوشتم، یک تصویر ازشما میگیره، یک نقطه در داخل یک محیط بسته، و یک رنگ، سپس محیط رو با رنگ مشخص شده رنگ آمیزی میکنه، مثل ابزار توی Photoshop


private void fill(Bitmap bitmap, Point pixel, Color defaultColor)
{
Stack<Point> pixels = new Stack<Point>();
pixels.Push(pixel);

while (pixels.Count > 0)
{
Point p = pixels.Pop();
if (bitmap.GetPixel(p.X, p.Y) == defaultColor)
{
bitmap.SetPixel(p.X, p.Y, this.BaseColor);
if (p.X < Definitions.ImageWidth - 1)
{
pixels.Push(new Point() { X = p.X + 1, Y = p.Y });
}
if (p.X > 0)
{
pixels.Push(new Point() { X = p.X - 1, Y = p.Y });
}
if (p.Y < Definitions.ImageHeight - 1)
{
pixels.Push(new Point() { X = p.X, Y = p.Y + 1 });
}
if (p.Y > 0)
{
pixels.Push(new Point() { X = p.X, Y = p.Y - 1 });
}
}
}
}

vb study
دوشنبه 25 بهمن 1389, 12:00 عصر
نمي تونم از اين كد تو vb6 استفاده كنم يعني متوجه نميشم

محسن واژدی
دوشنبه 25 بهمن 1389, 14:54 عصر
این متد رو برای درس گرافیکمون نوشتم، یک تصویر ازشما میگیره، یک نقطه در داخل یک محیط بسته، و یک رنگ، سپس محیط رو با رنگ مشخص شده رنگ آمیزی میکنه، مثل ابزار توی Photoshop


private void fill(Bitmap bitmap, Point pixel, Color defaultColor)
{
Stack<Point> pixels = new Stack<Point>();
pixels.Push(pixel);

while (pixels.Count > 0)
{
Point p = pixels.Pop();
if (bitmap.GetPixel(p.X, p.Y) == defaultColor)
{
bitmap.SetPixel(p.X, p.Y, this.BaseColor);
if (p.X < Definitions.ImageWidth - 1)
{
pixels.Push(new Point() { X = p.X + 1, Y = p.Y });
}
if (p.X > 0)
{
pixels.Push(new Point() { X = p.X - 1, Y = p.Y });
}
if (p.Y < Definitions.ImageHeight - 1)
{
pixels.Push(new Point() { X = p.X, Y = p.Y + 1 });
}
if (p.Y > 0)
{
pixels.Push(new Point() { X = p.X, Y = p.Y - 1 });
}
}
}
}

AmirHarirbafan خسته نباشید، اینا کجاش به کدای وی بی شباهت دارن :لبخندساده::متعجب::متفکر::قه هه:

این کدا رو ببینین البته یک Polygon رو با Gradiant پر میکنه که میتونین با کمی دستکاری درستشون کنین:

Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long

Public Sub gdiDrawGradient( _
ByVal hdc As Long, _
ByRef rct As RECT, _
ByVal lEndColor As Long, _
ByVal lStartColor As Long, _
ByVal bVertical As Boolean)

Dim lStep As Long
Dim lPos As Long, lSize As Long
Dim bRGB(1 To 3) As Integer
Dim bRGBStart(1 To 3) As Integer
Dim dR(1 To 3) As Double
Dim dPos As Double, d As Double
Dim hBr As Long
Dim tR As RECT

LSet tR = rct
If bVertical Then
lSize = (tR.Bottom - tR.Top)
Else
lSize = (tR.Right - tR.Left)
End If
lStep = lSize \ 255
If (lStep < 3) Then
lStep = 3
End If

bRGB(1) = lStartColor And &HFF&
bRGB(2) = (lStartColor And &HFF00&) \ &H100&
bRGB(3) = (lStartColor And &HFF0000) \ &H10000
bRGBStart(1) = bRGB(1): bRGBStart(2) = bRGB(2): bRGBStart(3) = bRGB(3)
dR(1) = (lEndColor And &HFF&) - bRGB(1)
dR(2) = ((lEndColor And &HFF00&) \ &H100&) - bRGB(2)
dR(3) = ((lEndColor And &HFF0000) \ &H10000) - bRGB(3)

For lPos = lSize To 0 Step -lStep '
' Draw bar
If bVertical Then
tR.Top = tR.Bottom - lStep
Else
tR.Left = tR.Right - lStep
End If
If tR.Top < rct.Top Then
tR.Top = rct.Top
End If
If tR.Left < rct.Left Then
tR.Left = rct.Left
End If

hBr = CreateSolidBrush((bRGB(3) * &H10000 + bRGB(2) * &H100& + bRGB(1)))
FillRect hdc, tR, hBr
DeleteObject hBr

' Adjust colour '
dPos = ((lSize - lPos) / lSize)
If bVertical Then
tR.Bottom = tR.Top
bRGB(1) = bRGBStart(1) + dR(1) * dPos
bRGB(2) = bRGBStart(2) + dR(2) * dPos
bRGB(3) = bRGBStart(3) + dR(3) * dPos
Else
tR.Right = tR.Left
bRGB(1) = bRGBStart(1) + dR(1) * dPos
bRGB(2) = bRGBStart(2) + dR(2) * dPos
bRGB(3) = bRGBStart(3) + dR(3) * dPos
End If

Next lPos

End Sub
اینم نمونه کدش:

Private Sub Command1_Click()
Dim r As RECT

r.Left = 10
r.Top = 10
r.Right = 100
r.Bottom = 150
Call gdiDrawGradient(Me.hdc, r, vbRed, vbBlue, True)
End Sub
موفق باشید
یاعلی

vb study
سه شنبه 10 خرداد 1390, 23:22 عصر
سلام

کد ها خطا میده
ممنون میشم اگه فرمشو ایجاد کنید و برام بزارین

www.pc3enter.tk
چهارشنبه 11 خرداد 1390, 02:01 صبح
بیت همه اینها را کپی کن و بعد پیییست کن



Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Sub gdiDrawGradient(ByVal hdc As Long, ByRef rct As RECT, ByVal lEndColor As Long, ByVal lStartColor As Long, ByVal bVertical As Boolean)

Dim lStep As Long
Dim lPos As Long, lSize As Long
Dim bRGB(1 To 3) As Integer
Dim bRGBStart(1 To 3) As Integer
Dim dR(1 To 3) As Double
Dim dPos As Double, d As Double
Dim hBr As Long
Dim tR As RECT

LSet tR = rct
If bVertical Then
lSize = (tR.Bottom - tR.Top)
Else
lSize = (tR.Right - tR.Left)
End If
lStep = lSize \ 255
? "www.pc3enter.40s.ir"
If (lStep < 3) Then
lStep = 3
End If

bRGB(1) = lStartColor And &HFF&
bRGB(2) = (lStartColor And &HFF00&) \ &H100&
bRGB(3) = (lStartColor And &HFF0000) \ &H10000
bRGBStart(1) = bRGB(1): bRGBStart(2) = bRGB(2): bRGBStart(3) = bRGB(3)
dR(1) = (lEndColor And &HFF&) - bRGB(1)
dR(2) = ((lEndColor And &HFF00&) \ &H100&) - bRGB(2)
dR(3) = ((lEndColor And &HFF0000) \ &H10000) - bRGB(3)

For lPos = lSize To 0 Step -lStep '
' Draw bar
If bVertical Then
tR.Top = tR.Bottom - lStep
Else
tR.Left = tR.Right - lStep
End If
If tR.Top < rct.Top Then
tR.Top = rct.Top
End If
If tR.Left < rct.Left Then
tR.Left = rct.Left
End If

hBr = CreateSolidBrush((bRGB(3) * &H10000 + bRGB(2) * &H100& + bRGB(1)))
FillRect hdc, tR, hBr
DeleteObject hBr

' Adjust colour '
dPos = ((lSize - lPos) / lSize)
If bVertical Then
tR.Bottom = tR.Top
bRGB(1) = bRGBStart(1) + dR(1) * dPos
bRGB(2) = bRGBStart(2) + dR(2) * dPos
bRGB(3) = bRGBStart(3) + dR(3) * dPos
Else
tR.Right = tR.Left
bRGB(1) = bRGBStart(1) + dR(1) * dPos
bRGB(2) = bRGBStart(2) + dR(2) * dPos
bRGB(3) = bRGBStart(3) + dR(3) * dPos
End If

Next lPos

End Sub

Private Sub Command1_Click()
Dim r As RECT

r.Left = 10
r.Top = 10
r.Right = 100
r.Bottom = 150
Call gdiDrawGradient(Me.hdc, r, vbRed, vbBlue, True)
End Sub

vb study
چهارشنبه 11 خرداد 1390, 11:20 صبح
اين كدها يك مستطيل رو رنگ ميزنه اما من با چند خط يك پليگون ايجاد كردم كه شكل نامتقارن داره و بايد توي اون رو رنگ بزنم
البته اگه دوستان براي ايجاد يك شكل نامتقارن كه توش رنگ شده راهي دارند ممنون ميشم كمك كنند

vb study
چهارشنبه 18 خرداد 1390, 15:08 عصر
با تشكر از همه دوستان جواب رو پيدا كردم

اين هم فايل پيوست :لبخندساده:

70893