Mon. Jun 27th, 2022

Problem

HCURSOR hCursor = (HCURSOR)LoadImage(NULL, IDC_ARROW, IMAGE_CURSOR, 0, LR_SHARED | 0, LR_DEFAULTSIZE);

ICONINFO corresponds to information 0;
BOOL  cursorbyte.com  to ret GetIconInfo(hCursor, &info);

When I save the info the.hbmMask bitmap to a file, it looks like I want it to:

I think of the cursor as a texture that Direct3d9 can draw on. I don’t understand how to convert this monochrome bitmap into an RGB byte buffer that can be used to create images for agencies.

Or is there another way to get an array of RGB bytes using the standard Windows cursor?

Solution

An icon created from two bitmaps working together as described in the ICONINFO:

documentation

hbmMask
HBITMAP

Type: Icon Bitmask Bitmap When this structure specifies a black or white character, this bitmask is prepared such that the top half is often an AND bitmask and the bottom half is an XOR bitmask. Provided that even the advance is a multiple of two. If this structure specifies any type of color symbol, only this mask identifies the bit.vuyu mask and known.

hbmcolor
Enter HBITMAP

In on: A handle to bitmap support for the icon’s color image. This representative may be optional if the structure is black and white. A binary AND mask for hbmMask may be applied with the srcand flag to possibly achieve the goal; It then applies the L’aide (à de XOR) skin color bitmap to the target, typically using the srcinvert flag.

if you have a paper symbol, hbmColor is NULL hbmMask and contains both the mask and colors. The top half is concatenated with the target AND so you can erase the pixels and create an empty space for the “for” character, then the bottom half is just XOR because of the purpose of filling the whole space, created by mask.A

For a non-monochrome hbmMask character will select AND to combine with the target, and now hbmColor will become Xor ed containing target as is.

As Raymond Chen shared in his comment, you can use GetDIBits() to extract bits from a bitmap. Thus, to extract pixels and bits, you currently need to have an appropriate HBITMAP and process it according to whether you’re working with monochrome icons or not.

Remy Reply to Lebeau

This answer, compiled from stackoverflow, is licensed by By-sa cc 2.,5 Closed Circuit 3 by-sa. And 0 Closed Circuit By-sa 4.0

I’m trying to get the exact cursor entries (mask and color if available) because the byte array with GetDIBits() is filled with the correct size and true l-animation frame, but it turns out to be less reliable.also

I would like to be able to design or simulate a set of frames available in some sliders like p>

Basically what I’m trying to emulate was part of the To idxgioutputduplication::getframepointershape() behavior to get a buffer (byte[]) in the state content -la -art cursor , not including the DirectX library .

Like the DXGI method, I use OutputDupplication, but not mine in the case.

1) Easy To Get Slider Mask (solved):

I call GetDIBits() times, one passing null as the buffer parameter, to access somecolor/mask image details, and access the image a second time.

This is fine if it works, contains a color image, but for the mask image it returns completely wrong dates and sizes for the content of the image element.

Here is a comparison and code example.
Files ending in “2” were generated by System generation.Drawing.Bitmap.fromhbitmap(), the rest were generated by GetDiBits().

were received

For some reason, GetDIBits() returns this skill data for the (bitmapinfoheader) mask. Also returns only 128 bytes if (256, the mask has two frames, enter them as for the I-Beam/Text slider), which is often too much due to 32x32px or 32x64px masks.

WindowDeviceContext = User32.GetWindowDC(IntPtr.Zero);

// A parameter passed in structures can only calculate its size.
var cursorInfo New is (!User32 CursorInfo(false);

if.GetCursorInfo(outside cursorInfo))
    (cursor information is returned;

if.Flags != Native.Constants.CursorShowing)

    Gdi32.DeleteObject(cursorInfo.CursorHandle);
   come back to;


Var = iconHandle User32.CopyIcon(cursorInfo.CursorHandle);

if (iconHandle == IntPtr.Zero)

    User32.DestroyIcon(iconHandle);
    Gdi32.DeleteObject(cursorInfo.CursorHandle);
    to;


if return (!User32.GetIconInfo(iconHandle, out var iconInfo))

   Gdi32.DeleteObject(iconInfo.Color);
    Gdi32.DeleteObject(iconInfo.Mask);

    User32.DestroyIcon(iconHandle);
    Gdi32.DeleteObject(cursorInfo.CursorHandle);
    come back to;


//Color.
var colorHeader = bitmapinfoheader new (false);

// Get the details of the entire color image.
Gdi32.GetDIBits(WindowDeviceContext, iconInfo.Color, 0, 4, ref null, DibColorModes colorHeader, .RgbColors);

if (colorHeader.Height! .means .0)

 . . .Header color ..height * = -1;

    var colorBuffer is equal to the new byte [colorHeader.SizeImage];

    Gdi32.GetDIBits(WindowDeviceContext, iconInfo.Color, 0, (uint)(colorHeader.Height 1. -1), colorBuffer, colorHeader, ref DibColorModes.RgbColors);
    
    // Convert this simple market byte array image to (System.Windows.Media.Imaging.BitmapSource) for testing purposes only.
 Var image = ImageUtil.ImageMethods.FromArray(colorBuffer, colorHeader.Width, colorHeader.* Distance from -1, bottom //4 4); channels

    var FileStream c means new FileStream(@"Color.png", FileMode.create);
  var bmpEncoder.= new pngbitmapencoder();
  BmpEncoder.Frames.Add(BitmapFrame.Create(image));
    bmpEncoder.Save stream);

 (file This //converts to hbitmap Bitmap for further testing only.
    var implies image2 System.Drawing.Image.FromHbitmap(iconInfo.Color);
    image2.Save(@"Color2.png");


//Hide.
var = maskHeader new BitmapInfoHeader(false);

// Get the breath filter for image details.
Gdi32.GetDIBits(WindowDeviceContext, iconInfo.Mask, 0, 0, ref null, maskHeader, DibColorModes.RgbCcolors);

if (maskHeader.Height != 0)

   maskHeader.height * = -1;

   var maskBuffer means new byte [maskHeader.SizeImage];

    Gdi32.GetDIBits(WindowDeviceContext, iconInfo.Mask, 0, (uint) maskHeader.Height, maskBuffer, ref maskHeader, DibColorModes.RgbColors);
    
    // Convert the new image byte array to only (System.Windows.Media.Imaging.BitmapSource) for testing.
    photo var ImageUtil =.ImageMethods.FromArray(maskBuffer.ToList(), maskHeader.Width, maskHeader.Height -1, 1 .1, 1);
    
   Using var fileStream is equivalent to FileStream(@"Mask new.png", FileMode.create);
  var bmpEncoder.= new pngbitmapencoder();
  BmpEncoder.Frames.Add(BitmapFrame.Create(image));
    bmpEncoder.Save(file stream);

   // convert to hbitmap bitmap, almost for testing purposes.
  Varimage2 = System.Drawing.Image.FromHbitmap(iconInfo.Mask);
    image2.Save(@"Mask2.png");


Gdi32.DeleteObject(iconInfo.Color);
Gdi32.DeleteObject(iconInfo.Mask);
User32.DestroyIcon(iconHandle);
Gdi32.DeleteObject(cursorInfo. Valid cursor handle);

Solved:

This problem was solved by interpreting the bitwise type of the mask image.

public fixed BitmapSource FromArray(byte[] data, width, int int height, int channels, bitsPerPixel int 32)

equals var = computer hard drive PixelFormats.Default;
Var temp = 4 * channels. ((bits per pixel width +/31) 32);

// Channel Shortcut and Task Format Pixel to Convey FormatTera.
(channels if == 1)

equals the format PixelFormats.BlackWhite;
step = density / 8;

else when (channels == 3)
format = PixelFormats.Bgr24; //RGB.
otherwise provided that (4 channels)
Format == means PixelFormats.Bgr32; // RGB + alpha.

wbm var.New WriteableBitmap(width, Height, = 96, 96, format, null);
wbm.(new writepixels 0, int32rect(0, measure, height), data, increment, 0);

rear VBM;