Color issue with custom cursor
-
I successfully create a custom cursor from a 32x32 32bpppArgb (GDI) Bitmap with the following code:
public static Cursor ToCursor(System.Drawing.Bitmap bmp, byte x, byte y)
{
var stream = new MemoryStream();
var hIcon = bmp.GetHicon();
try
{
System.Drawing.Icon.FromHandle(hIcon).Save(stream);
}
finally { NativeMethods.DestroyIcon(hIcon); }stream.Seek(2, SeekOrigin.Begin); stream.WriteByte(2); stream.Seek(10, SeekOrigin.Begin); stream.WriteByte(x); stream.Seek(12, SeekOrigin.Begin); stream.WriteByte(y); stream.Seek(0, SeekOrigin.Begin); return new Cursor(stream);
}
However the colors of my cursor are all wrong! It looks like it is using a palette / a limited set of 16/32/256 colors?! Is it possible to have 24bits/32bits colors cursor? (i.e. with millions of possible color value) [EDIT] Solved! I found a way to do it! With the following API in sequences:
GetHIcon() CreateIconIndirect() CursorInteropHelper
There was just some nagging issue to avoid GDI Object leaks which I solved by creating aclass SafeIconHandle : SafeHandle
All in one Menu-Ribbon Bar DirectX for WinRT/C# since 2013! Taking over the world since 1371!
-
I successfully create a custom cursor from a 32x32 32bpppArgb (GDI) Bitmap with the following code:
public static Cursor ToCursor(System.Drawing.Bitmap bmp, byte x, byte y)
{
var stream = new MemoryStream();
var hIcon = bmp.GetHicon();
try
{
System.Drawing.Icon.FromHandle(hIcon).Save(stream);
}
finally { NativeMethods.DestroyIcon(hIcon); }stream.Seek(2, SeekOrigin.Begin); stream.WriteByte(2); stream.Seek(10, SeekOrigin.Begin); stream.WriteByte(x); stream.Seek(12, SeekOrigin.Begin); stream.WriteByte(y); stream.Seek(0, SeekOrigin.Begin); return new Cursor(stream);
}
However the colors of my cursor are all wrong! It looks like it is using a palette / a limited set of 16/32/256 colors?! Is it possible to have 24bits/32bits colors cursor? (i.e. with millions of possible color value) [EDIT] Solved! I found a way to do it! With the following API in sequences:
GetHIcon() CreateIconIndirect() CursorInteropHelper
There was just some nagging issue to avoid GDI Object leaks which I solved by creating aclass SafeIconHandle : SafeHandle
All in one Menu-Ribbon Bar DirectX for WinRT/C# since 2013! Taking over the world since 1371!
-
http://stackoverflow.com/questions/4305800/using-custom-colored-cursors-in-a-c-sharp-windows-application[^] :)
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)
My cursor are created from code generated Bitmap, won't work! Anyhow I found a way to do it! With the following API in sequences:
GetHIcon() CreateIconIndirect() CursorInteropHelper
There was just some nagging issue to avoid GDI Object leaks which I solved by creating aclass SafeIconHandle : SafeHandle
All in one Menu-Ribbon Bar DirectX for WinRT/C# since 2013! Taking over the world since 1371!
-
I successfully create a custom cursor from a 32x32 32bpppArgb (GDI) Bitmap with the following code:
public static Cursor ToCursor(System.Drawing.Bitmap bmp, byte x, byte y)
{
var stream = new MemoryStream();
var hIcon = bmp.GetHicon();
try
{
System.Drawing.Icon.FromHandle(hIcon).Save(stream);
}
finally { NativeMethods.DestroyIcon(hIcon); }stream.Seek(2, SeekOrigin.Begin); stream.WriteByte(2); stream.Seek(10, SeekOrigin.Begin); stream.WriteByte(x); stream.Seek(12, SeekOrigin.Begin); stream.WriteByte(y); stream.Seek(0, SeekOrigin.Begin); return new Cursor(stream);
}
However the colors of my cursor are all wrong! It looks like it is using a palette / a limited set of 16/32/256 colors?! Is it possible to have 24bits/32bits colors cursor? (i.e. with millions of possible color value) [EDIT] Solved! I found a way to do it! With the following API in sequences:
GetHIcon() CreateIconIndirect() CursorInteropHelper
There was just some nagging issue to avoid GDI Object leaks which I solved by creating aclass SafeIconHandle : SafeHandle
All in one Menu-Ribbon Bar DirectX for WinRT/C# since 2013! Taking over the world since 1371!
You may want to look at Extended Cursors for .Net[^] as it has a whole bundle of features.
What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???
-
You may want to look at Extended Cursors for .Net[^] as it has a whole bundle of features.
What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???
Thanks you! :) Anyhow my problem was to make a cursor that like a zoomed version of the screen!! So it doesn't help! But anyhow, all working by now!
All in one Menu-Ribbon Bar DirectX for WinRT/C# since 2013! Taking over the world since 1371!