指定座標のRGB値取得(T) <TOP>
GradientFill 矩形、または三角形の内部をグラデーションで塗りつぶす
GetPixel 指定された座標のピクセルのRGB(赤、緑、青)値を取得
マウスでクリックした座標のRGB値を取得します。F-BasicでのGetPixel(x, y)と同じです。
'================================================================
'= 指定座標のRGB値取得
'= (GetPixel.bas)
'================================================================
#include "Windows.bi"
Type GRADIENT_TRIANGLE
Vertex1 As Long
Vertex2 As Long
Vertex3 As Long
End Type
Type TRIVERTEX
X As Long
Y As Long
Red As Integer
Green As Integer
Blue As Integer
Alpha As Integer
End Type
Type GRADIENT_RECT
UpperLeft As Long
LowerRight As Long
End Type
' 矩形、または三角形の内部をグラデーションで塗りつぶす
Declare Function Api_GradientFill& Lib "msimg32" Alias "GradientFill" (ByVal hDC&, pVertex As TRIVERTEX, ByVal dwNumVertex&, pMesh As GRADIENT_TRIANGLE, ByVal dwNumMesh&, ByVal dwMode&)
' 指定された座標のピクセルのRGB値を取得
Declare Function Api_GetPixel& Lib "gdi32" Alias "GetPixel" (ByVal hDC&, ByVal X&, ByVal Y&)
' 指定されたウィンドウのクライアント領域または画面全体を表すディスプレイデバイスコンテキストのハンドルを取得
Declare Function Api_GetDC& Lib "user32" Alias "GetDC" (ByVal hWnd&)
' デバイスコンテキストを解放
Declare Function Api_ReleaseDC& Lib "user32" Alias "ReleaseDC" (ByVal hWnd&, ByVal hDC&)
#define GRADIENT_FILL_RECT_H &H0 '
#define GRADIENT_FILL_RECT_V &H1 '
#define GRADIENT_FILL_TRIANGLE &H2 '
Var Shared hDC As Long
'================================================================
'=
'================================================================
Declare Sub MainForm_Start edecl ()
Sub MainForm_Start()
Var vert(4) As TRIVERTEX
Var gTRi(1) As GRADIENT_TRIANGLE
Var Ret As Long
hDC = Api_GetDC(GethWnd)
vert(0).X = 0
vert(0).Y = 0
vert(0).Red = -256
vert(0).Green = 0
vert(0).Blue = 0
vert(0).Alpha = 0
vert(1).X = 255
vert(1).Y = 0
vert(1).Red = 0
vert(1).Green = -256
vert(1).Blue = 0
vert(1).Alpha = 0
vert(2).X = 256
vert(2).Y = 256
vert(2).Red = 0
vert(2).Green = 0
vert(2).Blue = -256
vert(2).Alpha = 0
vert(3).X = 0
vert(3).Y = 256
vert(3).Red = -256
vert(3).Green = -256
vert(3).Blue = -256
vert(3).Alpha = 0
gTRi(0).Vertex1 = 0
gTRi(0).Vertex2 = 1
gTRi(0).Vertex3 = 2
gTRi(1).Vertex1 = 0
gTRi(1).Vertex2 = 2
gTRi(1).Vertex3 = 3
Ret = Api_GradientFill(hDC, vert(0), 4, gTRi(0), 2, GRADIENT_FILL_TRIANGLE)
End Sub
'================================================================
'=
'================================================================
Declare Sub MainForm_MouseMove edecl (ByVal Button%, ByVal Shift%, ByVal X!, ByVal Y!)
Sub MainForm_MouseMove(ByVal Button%, ByVal Shift%, ByVal X!, ByVal Y!)
Var DotColor As String
Var ColorMe As Long
Var rgbRed As Integer
Var rgbGreen As Integer
Var rgbBlue As Integer
ColorMe = Api_GetPixel(hDC, X, Y)
' ColorMe = GetPixel(X, Y)
rgbRed = Abs(ColorMe Mod &H100)
ColorMe = Abs(ColorMe \ &H100)
rgbGreen = Abs(ColorMe Mod &H100)
ColorMe = Abs(ColorMe \ &H100)
rgbBlue = Abs(ColorMe Mod &H100)
ColorMe = RGB(rgbRed, rgbGreen, rgbBlue)
DotColor = "GetPixel:RGB(" & Format$(rgbRed, "###") & ", " & Format$(rgbGreen, "###") & ", " & Format$(rgbBlue, "###") & ")"
SetWindowText DotColor
End Sub
'================================================================
'=
'================================================================
While 1
WaitEvent
Wend
Stop
End