private static void ResizeCursor(System.Windows.Forms.Cursor cursor, int newSize, CursorShift cursorShift) { Bitmap cursorImage = GetSystemCursorBitmap(cursor); cursorImage = ResizeCursorBitmap(cursorImage, new Size(newSize, newSize), cursorShift); SetCursor(cursorImage, getResourceId(cursor)); }
private static Bitmap ResizeCursorBitmap(Bitmap bitmap, Size size, CursorShift cursorShift) { if (size.Width > 32) { //shifting must occur Bitmap intermediateBitmap = new Bitmap(64, 64); Graphics intermediateGraphics = Graphics.FromImage(intermediateBitmap); if (cursorShift == CursorShift.LowerRight) { //place the mouse cursor in the lower right hand quadrant of the bitmap intermediateGraphics.DrawImage(bitmap, intermediateBitmap.Width / 2, intermediateBitmap.Height / 2); } else if (cursorShift == CursorShift.Centered) { intermediateGraphics.DrawImage(bitmap, intermediateBitmap.Width / 2 - bitmap.Width / 2, intermediateBitmap.Height / 2 - bitmap.Height / 2); } //now we have a shifted bitmap; use it to draw the resized cursor //Bitmap finalBitmap = new Bitmap(intermediateBitmap, size); //normal quality Bitmap finalBitmap = new Bitmap(size.Width, size.Height); Graphics finalGraphics = Graphics.FromImage(finalBitmap); finalGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; finalGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; finalGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; finalGraphics.DrawImage(intermediateBitmap, 0, 0, finalBitmap.Width, finalBitmap.Height); return(finalBitmap); } else { Bitmap newBitmap = new Bitmap(bitmap, size); return(newBitmap); } }