code_junkie

Create a semi-transparent cursor from an image

Nov 14th, 2011
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. Image cursorImage = customImage.GetThumbnailImage(300, 100, null, IntPtr.Zero);
  2. cursorImage.SetResolution(96.0F, 96.0F);
  3. int midPointX = cursorImage.Width / 2;
  4. int midPointY = cursorImage.Height / 2;
  5. Bitmap cursorMouse = GetCursorImage(cursorOverlay);
  6. Graphics cursorGfx = Graphics.FromImage(cursorImageCopy);
  7. cursorGfx.DrawImageUnscaled(cursorMouse, midPointX, midPointY);
  8.  
  9. Cursor tmp = new Cursor(cursorImage.GetHicon());
  10.  
  11. public struct IconInfo
  12. {
  13. public bool fIcon;
  14. public int xHotspot;
  15. public int yHotspot;
  16. public IntPtr hbmMask;
  17. public IntPtr hbmColor;
  18. }
  19.  
  20. public static Cursor CreateCursor(Bitmap bmp, int xHotSpot, int yHotSpot)
  21. {
  22. IntPtr ptr = bmp.GetHicon();
  23. IconInfo tmp = new IconInfo();
  24. GetIconInfo(ptr, ref tmp);
  25. tmp.xHotspot = xHotSpot;
  26. tmp.yHotspot = yHotSpot;
  27. tmp.fIcon = false;
  28. ptr = CreateIconIndirect(ref tmp);
  29. return new Cursor(ptr);
  30. }
Add Comment
Please, Sign In to add comment