Пиксели

Программирование на Visual Basic, главный форум. Обсуждение тем программирования на VB 1—6.
Даже если вы плохо разбираетесь в VB и программировании вообще — тут вам помогут. В разумных пределах, конечно.
Правила форума
Темы, в которых будет сначала написано «что нужно сделать», а затем просьба «помогите», будут закрыты.
Читайте требования к создаваемым темам.
Мика
Обычный пользователь
Обычный пользователь
 
Сообщения: 58
Зарегистрирован: 08.06.2003 (Вс) 10:27

Пиксели

Сообщение Мика » 02.10.2003 (Чт) 15:24

В PictureBox у меня загружена картинка.
Как отыскать пиксели одного цвета предположем RGB(255, 0, 0)
и заменить их на предположем RGB(0, 255, 0)

Mikle
Изобретатель велосипедов
Изобретатель велосипедов
Аватара пользователя
 
Сообщения: 4158
Зарегистрирован: 25.03.2003 (Вт) 14:02
Откуда: Туапсе

Сообщение Mikle » 02.10.2003 (Чт) 15:46

Код: Выделить всё
dim FirstColor as long, SecondColor as long

FirstColor= RGB(255, 0, 0)
SecondColor= RGB(0, 255, 0)

For y=0 to picture1.height-1
  For x=0 to picture1.width-1
    If point(x,y)=FirstColor then Pset (x,y),SecondColor
  next x
next y


Я не проверял, но смысл понятен.

Black_Star
Начинающий
Начинающий
 
Сообщения: 14
Зарегистрирован: 01.10.2003 (Ср) 20:30
Откуда: Minsk

Сообщение Black_Star » 02.10.2003 (Чт) 19:16

Советую вместо Point использовать GetPixel. Результат будет раз в 5 быстрее :D

Мика
Обычный пользователь
Обычный пользователь
 
Сообщения: 58
Зарегистрирован: 08.06.2003 (Вс) 10:27

Сообщение Мика » 02.10.2003 (Чт) 20:05

Спасиб :D

Amed
Алфизик
Алфизик
 
Сообщения: 5346
Зарегистрирован: 09.03.2003 (Вс) 9:26

Сообщение Amed » 02.10.2003 (Чт) 20:13

Советую вместо PSet использовать SetPixel. Результат будет раз в 5 быстрее :D

Black_Star
Начинающий
Начинающий
 
Сообщения: 14
Зарегистрирован: 01.10.2003 (Ср) 20:30
Откуда: Minsk

Сообщение Black_Star » 02.10.2003 (Чт) 20:15

Ето точно :) !

v-adix
Постоялец
Постоялец
 
Сообщения: 490
Зарегистрирован: 14.11.2002 (Чт) 15:11

Сообщение v-adix » 03.10.2003 (Пт) 12:55

что за GetPixel и SetPixel?

Vovik
Постоялец
Постоялец
Аватара пользователя
 
Сообщения: 643
Зарегистрирован: 02.08.2003 (Сб) 15:14
Откуда: Belarus, Minsk

Сообщение Vovik » 03.10.2003 (Пт) 13:00

v-adix писал(а):что за GetPixel и SetPixel?

Get - полуить(дословно)
Set - соответственно, установить..
Pixel - я думаю ясно...ПИКСЕЛЬ(точка)
:arrow: Делай вывод... :wink:

v-adix
Постоялец
Постоялец
 
Сообщения: 490
Зарегистрирован: 14.11.2002 (Чт) 15:11

Сообщение v-adix » 03.10.2003 (Пт) 15:39

с англ. яз. у меня в порядке, я только не понял как применять эти ф-ции. не работает!

A.A.Z.
Член-корреспондент академии VBStreets
Член-корреспондент академии VBStreets
 
Сообщения: 3035
Зарегистрирован: 30.06.2003 (Пн) 13:38

Сообщение A.A.Z. » 03.10.2003 (Пт) 15:48

Ну раз

v-adix писал(а):с англ. яз. у меня в порядке


тогда

API-Guide писал(а):
Declaration:
Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long

Description:
The GetPixel function retrieves the red, green, blue (RGB) color value of the pixel at the specified coordinates.

Parameters:
· hdc
Identifies the device context.

· nXPos
Specifies the logical x-coordinate of the pixel to be examined.

· nYPos
Specifies the logical y-coordinate of the pixel to be examined.

Return values:
If the function succeeds, the return value is an RGB value. If the pixel is outside of the current clipping region, the return value is CLR_INVALID.




Declaration:
Declare Function SetPixel Lib "gdi32" Alias "SetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long

Description:
The SetPixel function sets the pixel at the specified coordinates to the specified color.

Parameters:
· hdc
Identifies the device context.

· X
Specifies the x-coordinate, in logical units, of the point to be set.

· Y
Specifies the y-coordinate, in logical units, of the point to be set.

· crColor
Specifies the color to be used to paint the point.

Return values:
If the function succeeds, the return value is the RGB value that the function sets the pixel to. This value may differ from the color specified by crColor; that happens when an exact match for the specified color cannot be found.

If the function fails, the return value is -1. To get extended error information, call GetLastError.



Sample (Один и тот же для обеих функций):
Код: Выделить всё
'This project needs:
'- two picture boxes
'- a button
Private Type POINTAPI
    X As Long
    Y As Long
End Type

Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long
Private Declare Function PaintDesktop Lib "user32" (ByVal hdc As Long) As Long
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Private Declare Function GetBkColor Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, lpPoint As POINTAPI) As Long
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long

Const ScrCopy = &HCC0020
Const Yellow = &HFFFF&
Private Sub Form_Load()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim Cnt1 As Byte, Cnt2 As Byte, Point As POINTAPI
    'Set the graphic mode to persistent
    Me.AutoRedraw = True
    'API uses pixels
    Me.ScaleMode = vbPixels
    Picture1.ScaleMode = vbPixels
    Picture2.ScaleMode = vbPixels
    'No borders
    Picture1.BorderStyle = 0: Picture2.BorderStyle = 0
    'Set the button's caption
    Command1.Caption = "Paint && Stretch"
    'Set the graphic mode to 'non persistent'
    Picture1.AutoRedraw = False: Picture2.AutoRedraw = False
    For Cnt1 = 0 To 100 Step 3
        For Cnt2 = 0 To 100 Step 3
            'Set the start-point's coördinates
            Point.X = Cnt1: Point.Y = Cnt2
            'Move the active point
            MoveToEx Me.hdc, Cnt1, Cnt2, Point
            'Draw a line from the active point to the given point
            LineTo Me.hdc, 200, 200
        Next Cnt2
    Next Cnt1
    For Cnt1 = 0 To 100 Step 5
        For Cnt2 = 0 To 100 Step 5
            'Draw a pixel
            SetPixel Me.hdc, Cnt1, Cnt2, Yellow
        Next Cnt2
    Next Cnt1
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim XX As Long, YY As Long, A As Long
    XX = X: YY = Y
    'Set the picturebox' backcolor
    Picture2.BackColor = GetPixel(Picture1.hdc, XX, YY)
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
        Dim XX As Long, YY As Long, A As Long
        XX = X: YY = Y
        'Set the picturebox' backcolor
        Picture2.BackColor = GetPixel(Picture1.hdc, XX, YY)
    End If
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim XX As Long, YY As Long, A As Long
    XX = X: YY = Y
    'Set the picturebox' backcolor
    Picture2.BackColor = GetPixel(Picture1.hdc, XX, YY)
End Sub
Private Sub Command1_Click()
    'Set the width and height
    Picture2.Width = 100: Picture2.Height = 100
    Picture1.Width = 50: Picture1.Height = 50
    'No pictures
    Picture1.Picture = LoadPicture("")
    DoEvents
    Copy the desktop to our picturebox
    PaintDesktop Picture1.hdc
    'Stretch the picture
    StretchBlt Picture2.hdc, 0, 0, 100, 100, Picture1.hdc, 0, 0, 50, 50, ScrCopy
End Sub




Во. :) :idea:
Нет меня больше

v-adix
Постоялец
Постоялец
 
Сообщения: 490
Зарегистрирован: 14.11.2002 (Чт) 15:11

Сообщение v-adix » 03.10.2003 (Пт) 16:03

Грэйт thanx!
Ещё кое что: как получить цвет пикселя? в RGB?
напр, в picturebox пиксель 3x67 чтобы в три переменных (Red, Green, Blue) были соотв. цвет

Mikle
Изобретатель велосипедов
Изобретатель велосипедов
Аватара пользователя
 
Сообщения: 4158
Зарегистрирован: 25.03.2003 (Вт) 14:02
Откуда: Туапсе

Сообщение Mikle » 03.10.2003 (Пт) 16:14

Color=GetPixel...
R=Color\65536
G=(Color and 65535)\256
B=Color and 255

Black_Star
Начинающий
Начинающий
 
Сообщения: 14
Зарегистрирован: 01.10.2003 (Ср) 20:30
Откуда: Minsk

Сообщение Black_Star » 03.10.2003 (Пт) 17:13

А шуму-то, шуму!!! :D

Мика
Обычный пользователь
Обычный пользователь
 
Сообщения: 58
Зарегистрирован: 08.06.2003 (Вс) 10:27

Сообщение Мика » 03.10.2003 (Пт) 19:48

Дааа конечно первый тормозит по страшному делает секунд 30
А второй по быстрей
короче всем спасибо!!


Вернуться в Visual Basic 1–6

Кто сейчас на конференции

Сейчас этот форум просматривают: Yandex-бот и гости: 5

    TopList