Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long Private Declare Function GetPixel Lib "gdi32.dll" _ (ByVal hdc As LongPtr, ByVal nXPos As Long, ByVal nYPos As Long) As Long Sub hdc2() ' Dim color As Long Dim hwnd As Long Dim X As Long Dim Y As Long Dim hdc As Long hwnd = WindowFromPoint(0, 0) hdc = GetDC(hwnd) If hdc = 0 Then MsgBox "失敗しました。" Else Call GetWindowText(hwnd, Title, 20) MsgBox Title 'https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q1387601913 For X = 1 To 100 For Y = 1 To 100 color = GetPixel(hdc, X, Y) Cells(Y + 20, X).Value = color Next Next ' Call ReleaseDC(0, hdc) Call ReleaseDC(hTargetWin, hdc) End If End Sub
using System; using System.Drawing; using System.Runtime.InteropServices; using System.Net; namespace GetpxelFormAppCS { [Guid(Getp.ClassId)] public class Getp { // COM用のGUID値 public const string ClassId = "DC6E18DD-3731-4DC0-BC4F-4C64947E652A"; public string Getpxel(string fn, int x, int y) { //https://qiita.com/Tachibana446/items/31cdda5cac78cf571a04 //https://www.atmarkit.co.jp/fdotnet/dotnettips/961dpiresolution/dpiresolution.html // System.Drawing.Bitmap bitmap; // ローカルファイルの場合 bitmap = new Bitmap(fn); int w = bitmap.Width, h = bitmap.Height; Color pixel = bitmap.GetPixel(x-1, y-1); byte R = pixel.R; byte G = pixel.G; byte B = pixel.B; long color = R * 256 * 256 + G * 256 + B; double height = color * 0.01; bitmap.Dispose(); return R + ";" + G + ";" + B + ";" + color + ";" + w + ";" + h + ";" + height; } }