internal RECT(PSIZE size) { Left = 0; Top = 0; Right = size.x - 1; Bottom = size.y - 1; }
private static void CenterAndScaleRectangle(ref Rect rectangle, PSIZE size) { var height = rectangle.Height; var width = rectangle.Width; if (size.x < size.y) { double ScaleFactor = width / (double)size.y; int scaledX = (int)(size.x * ScaleFactor); int xOffset = (width - scaledX) / 2; rectangle.Left += xOffset; rectangle.Right -= xOffset; } if (size.y < size.x) { double ScaleFactor = height / (double)size.x; int scaledY = (int)(size.y * ScaleFactor); int yOffset = (height - scaledY) / 2; rectangle.Top += yOffset; rectangle.Bottom -= yOffset; } }
internal static extern int DwmQueryThumbnailSourceSize(IntPtr thumb, out PSIZE size);
public static extern void DwmQueryThumbnailSourceSize( IntPtr hThumbnail, out PSIZE size);
public static extern int DwmQueryThumbnailSourceSize(IntPtr thumb, out PSIZE size);
private PSIZE GetThumbSize(PSIZE sourceSize, Rectangle destination) { if (sourceSize.x < destination.Width && sourceSize.y < destination.Height) { return sourceSize; } else { PSIZE size = new PSIZE(); float whq = sourceSize.x / (float)sourceSize.y; // width-height quotient int respectiveHeight = (int)(destination.Width / whq); int respectiveWidth = (int)(destination.Height * whq); if ((whq < 1 && respectiveHeight <= destination.Height) || respectiveWidth > destination.Width) { size.x = destination.Width; size.y = respectiveHeight; } else { size.x = respectiveWidth; size.y = destination.Height; } return size; } }
static extern int DwmQueryThumbnailSourceSize(ThumbnailSafeHandle hThumbnail, ref PSIZE pSize);