Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem with DllImport

Problem with DllImport

Scheduled Pinned Locked Moved C#
jsonhelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jtmtv18
    wrote on last edited by
    #1

    Iam trying to get the pixel of a area in a screen of my program (for collison detection) the API call (GetPixel) seems to work..and it returns a int that i use with Color.FromArgb(int) (i think thats it) anyways when i try to convert the int i get back the color but...it doesnt convert correctly.....the A(alpha) of the color is always 0. Is there something i need to do before i try to convert the int ? Here is the code i use. [DllImport("Gdi32.dll")] private static extern int GetPixel(IntPtr Handler,int x,int y); [DllImport("user32.dll")] private static extern IntPtr GetDesktopWindow(); // [DllImport("user32.dll")] private static extern IntPtr GetWindowDC(int Pointer); [DllImport("user32.dll")] private static extern IntPtr ReleaseDC(IntPtr hWnd,IntPtr hdc); //Use a method Called check pixel (overloads Int X, Int Y) int j = CheckPixel(100,100); int jm =Convert.ToInt32(j); Color c = Color.FromArgb(jm); MessageBox.Show(c.ToString()); //method CheckPixel private int CheckPixel(int x,int y) { IntPtr DC = GetWindowDC(GetDesktopWindow().ToInt32()); int jm = GetPixel(DC,x,y); // // ReleaseDC(GetDesktopWindow(),DC); // return jm; } Thanks for your time. Jesse M The Code Project Is Your Friend...

    N 1 Reply Last reply
    0
    • J jtmtv18

      Iam trying to get the pixel of a area in a screen of my program (for collison detection) the API call (GetPixel) seems to work..and it returns a int that i use with Color.FromArgb(int) (i think thats it) anyways when i try to convert the int i get back the color but...it doesnt convert correctly.....the A(alpha) of the color is always 0. Is there something i need to do before i try to convert the int ? Here is the code i use. [DllImport("Gdi32.dll")] private static extern int GetPixel(IntPtr Handler,int x,int y); [DllImport("user32.dll")] private static extern IntPtr GetDesktopWindow(); // [DllImport("user32.dll")] private static extern IntPtr GetWindowDC(int Pointer); [DllImport("user32.dll")] private static extern IntPtr ReleaseDC(IntPtr hWnd,IntPtr hdc); //Use a method Called check pixel (overloads Int X, Int Y) int j = CheckPixel(100,100); int jm =Convert.ToInt32(j); Color c = Color.FromArgb(jm); MessageBox.Show(c.ToString()); //method CheckPixel private int CheckPixel(int x,int y) { IntPtr DC = GetWindowDC(GetDesktopWindow().ToInt32()); int jm = GetPixel(DC,x,y); // // ReleaseDC(GetDesktopWindow(),DC); // return jm; } Thanks for your time. Jesse M The Code Project Is Your Friend...

      N Offline
      N Offline
      Nathan Blomquist
      wrote on last edited by
      #2

      Quote from MSDN: "GetPixel: The GetPixel function retrieves the red, green, blue (RGB) color value of the pixel at the specified coordinates. " This seems to imply that the Alpha value is undefined when returned from GetPixel. It seems as though the Alpha is always zero, but then the docs don't say that so you can't trust it. I haven't been able to locate how to get the alpha value though :( -Nathan --------------------------- Hmmm... what's a signature?

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups