public Image CreateDeviceFromLogicalImage(Image logicalImage, System.Drawing.Color backgroundColor, ImageScalingMode scalingMode = ImageScalingMode.Default) { Validate.IsNotNull(logicalImage, "logicalImage"); ImageScalingMode scalingMode1 = GetActualScalingMode(scalingMode); System.Drawing.Size size = logicalImage.Size; System.Drawing.Size deviceUnits = LogicalToDeviceUnits(size); if (scalingMode1 == ImageScalingMode.MixedNearestNeighborHighQualityBicubic) { System.Drawing.Size prescaledImageSize = GetPrescaledImageSize(size); if (prescaledImageSize == size) { scalingMode1 = ImageScalingMode.HighQualityBicubic; } else if (prescaledImageSize == deviceUnits) { scalingMode1 = ImageScalingMode.NearestNeighbor; } else if (prescaledImageSize == System.Drawing.Size.Empty) { scalingMode1 = ImageScalingMode.HighQualityBilinear; } else { Image image = ScaleLogicalImageForDeviceSize(logicalImage, prescaledImageSize, backgroundColor, ImageScalingMode.NearestNeighbor); scalingMode1 = ImageScalingMode.HighQualityBicubic; logicalImage = image; } } return(ScaleLogicalImageForDeviceSize(logicalImage, deviceUnits, backgroundColor, scalingMode1)); }
private ImageScalingMode GetActualScalingMode(ImageScalingMode scalingMode) { if (scalingMode != ImageScalingMode.Default) { return(scalingMode); } return(ImageScalingMode); }
public void LogicalToDeviceUnits(ref Icon icon, ImageScalingMode scalingMode = ImageScalingMode.Default) { Validate.IsNotNull(icon, "icon"); if (!IsScalingRequired) { return; } Icon fromLogicalImage = CreateDeviceFromLogicalImage(icon, scalingMode); icon.Dispose(); icon = fromLogicalImage; }
public Icon CreateDeviceFromLogicalImage(Icon logicalIcon, ImageScalingMode scalingMode = ImageScalingMode.Default) { Validate.IsNotNull(logicalIcon, "logicalIcon"); System.Drawing.Size deviceUnits = LogicalToDeviceUnits(logicalIcon.Size); Icon icon = new Icon(logicalIcon, deviceUnits); if (icon.Size.Width != deviceUnits.Width && icon.Size.Width != 0) { IntPtr hicon = ((Bitmap)CreateDeviceFromLogicalImage(icon.ToBitmap(), System.Drawing.Color.Transparent, scalingMode)).GetHicon(); icon = Icon.FromHandle(hicon).Clone() as Icon; NativeMethods.User32.DestroyIcon(hicon); } return(icon); }
public static BitmapScalingMode ToBitmapScalingMode(this ImageScalingMode imageScalingMode) { switch (imageScalingMode) { case ImageScalingMode.HighQuality: return(BitmapScalingMode.HighQuality); default: case ImageScalingMode.LowQuality: return(BitmapScalingMode.LowQuality); case ImageScalingMode.NearestNeighbor: return(BitmapScalingMode.NearestNeighbor); } }
private InterpolationMode GetInterpolationMode(ImageScalingMode scalingMode) { switch (scalingMode) { case ImageScalingMode.BorderOnly: case ImageScalingMode.NearestNeighbor: return(InterpolationMode.NearestNeighbor); case ImageScalingMode.Bilinear: return(InterpolationMode.Bilinear); case ImageScalingMode.Bicubic: return(InterpolationMode.Bicubic); case ImageScalingMode.HighQualityBilinear: return(InterpolationMode.HighQualityBilinear); case ImageScalingMode.HighQualityBicubic: return(InterpolationMode.HighQualityBicubic); default: return(GetInterpolationMode(ImageScalingMode)); } }
public static void LogicalToDeviceUnits(ref Bitmap imageStrip, System.Drawing.Size logicalImageSize, System.Drawing.Color backgroundColor, ImageScalingMode scalingMode = ImageScalingMode.Default) { Instance.LogicalToDeviceUnits(ref imageStrip, logicalImageSize, backgroundColor, scalingMode); }
public static void LogicalToDeviceUnits(ref Bitmap bitmapImage, System.Drawing.Color backgroundColor, ImageScalingMode scalingMode = ImageScalingMode.Default) { Instance.LogicalToDeviceUnits(ref bitmapImage, backgroundColor, scalingMode); }
public static void LogicalToDeviceUnits(ref Bitmap bitmapImage, ImageScalingMode scalingMode = ImageScalingMode.Default) { Instance.LogicalToDeviceUnits(ref bitmapImage, scalingMode); }
public ImageList CreateDeviceFromLogicalImage(ImageList logicalImageList, System.Drawing.Color backgroundColor, ImageScalingMode scalingMode = ImageScalingMode.Default) { Validate.IsNotNull(logicalImageList, "logicalImageList"); ImageList imageList = new ImageList { Site = logicalImageList.Site, Tag = logicalImageList.Tag, ColorDepth = logicalImageList.ColorDepth, TransparentColor = logicalImageList.TransparentColor, ImageSize = LogicalToDeviceUnits(logicalImageList.ImageSize) }; for (int index = 0; index < logicalImageList.Images.Count; ++index) { Image fromLogicalImage = CreateDeviceFromLogicalImage(logicalImageList.Images[index], backgroundColor, scalingMode); imageList.Images.Add(fromLogicalImage); } foreach (string key in logicalImageList.Images.Keys) { int index = logicalImageList.Images.IndexOfKey(key); if (index != -1) { imageList.Images.SetKeyName(index, key); } } return(imageList); }
public void LogicalToDeviceUnits(ref Bitmap bitmapImage, ImageScalingMode scalingMode = ImageScalingMode.Default) { LogicalToDeviceUnits(ref bitmapImage, System.Drawing.Color.Transparent, scalingMode); }
public static void LogicalToDeviceUnits(ref ImageList imageList, System.Drawing.Color backgroundColor, ImageScalingMode scalingMode = ImageScalingMode.Default) { Instance.LogicalToDeviceUnits(ref imageList, backgroundColor, scalingMode); }
public static Icon CreateDeviceFromLogicalImage(this Icon logicalIcon, ImageScalingMode scalingMode = ImageScalingMode.Default) { return(Instance.CreateDeviceFromLogicalImage(logicalIcon, scalingMode)); }
public static ImageList CreateDeviceFromLogicalImage(this ImageList logicalImageList, System.Drawing.Color backgroundColor, ImageScalingMode scalingMode = ImageScalingMode.Default) { return(Instance.CreateDeviceFromLogicalImage(logicalImageList, backgroundColor, scalingMode)); }
public Bitmap CreateDeviceFromLogicalImage(Bitmap logicalBitmapStrip, System.Drawing.Size logicalImageSize, ImageScalingMode scalingMode = ImageScalingMode.Default) { return(CreateDeviceFromLogicalImage(logicalBitmapStrip, logicalImageSize, System.Drawing.Color.Transparent, scalingMode)); }
public Bitmap CreateDeviceFromLogicalImage(Bitmap logicalBitmapStrip, System.Drawing.Size logicalImageSize, System.Drawing.Color backgroundColor, ImageScalingMode scalingMode = ImageScalingMode.Default) { Validate.IsNotNull(logicalBitmapStrip, "logicalBitmapStrip"); Validate.IsNotNull(logicalImageSize, "logicalImageSize"); if (logicalImageSize.Width == 0 || logicalBitmapStrip.Height % logicalImageSize.Width != 0 || logicalImageSize.Height != logicalBitmapStrip.Height) { throw new ArgumentException("logicalImageSize not matching the logicalBitmap size"); } int num = logicalBitmapStrip.Width / logicalImageSize.Width; int deviceUnitsX = LogicalToDeviceUnitsX(logicalImageSize.Width); int deviceUnitsY = LogicalToDeviceUnitsY(logicalImageSize.Height); Bitmap bitmap = new Bitmap(num * deviceUnitsX, deviceUnitsY, logicalBitmapStrip.PixelFormat); using (Graphics graphics1 = Graphics.FromImage(bitmap)) { graphics1.InterpolationMode = InterpolationMode.NearestNeighbor; for (int index = 0; index < num; ++index) { RectangleF srcRect = new RectangleF(index * logicalImageSize.Width, 0.0f, logicalImageSize.Width, logicalImageSize.Height); srcRect.Offset(-0.5f, -0.5f); RectangleF destRect = new RectangleF(0.0f, 0.0f, logicalImageSize.Width, logicalImageSize.Height); Bitmap bitmapImage = new Bitmap(logicalImageSize.Width, logicalImageSize.Height, logicalBitmapStrip.PixelFormat); using (Graphics graphics2 = Graphics.FromImage(bitmapImage)) { graphics2.InterpolationMode = InterpolationMode.NearestNeighbor; graphics2.DrawImage(logicalBitmapStrip, destRect, srcRect, GraphicsUnit.Pixel); } LogicalToDeviceUnits(ref bitmapImage, backgroundColor, scalingMode); srcRect = new RectangleF(0.0f, 0.0f, deviceUnitsX, deviceUnitsY); srcRect.Offset(-0.5f, -0.5f); destRect = new RectangleF(index * deviceUnitsX, 0.0f, deviceUnitsX, deviceUnitsY); graphics1.DrawImage(bitmapImage, destRect, srcRect, GraphicsUnit.Pixel); } } return(bitmap); }
public void LogicalToDeviceUnits(ref Bitmap imageStrip, System.Drawing.Size logicalImageSize, System.Drawing.Color backgroundColor, ImageScalingMode scalingMode = ImageScalingMode.Default) { Validate.IsNotNull(imageStrip, "imageStrip"); if (!IsScalingRequired) { return; } Bitmap fromLogicalImage = CreateDeviceFromLogicalImage(imageStrip, logicalImageSize, backgroundColor, scalingMode); imageStrip.Dispose(); imageStrip = fromLogicalImage; }
public void LogicalToDeviceUnits(ref Bitmap imageStrip, System.Drawing.Size logicalImageSize, ImageScalingMode scalingMode = ImageScalingMode.Default) { LogicalToDeviceUnits(ref imageStrip, logicalImageSize, System.Drawing.Color.Transparent, scalingMode); }
private Image ScaleLogicalImageForDeviceSize(Image logicalImage, System.Drawing.Size deviceImageSize, System.Drawing.Color backgroundColor, ImageScalingMode scalingMode) { Validate.IsNotNull(logicalImage, "logicalImage"); InterpolationMode interpolationMode = GetInterpolationMode(scalingMode); System.Drawing.Imaging.PixelFormat pixelFormat = logicalImage.PixelFormat; System.Drawing.Color clrMagenta = System.Drawing.Color.FromArgb(byte.MaxValue, 0, byte.MaxValue); System.Drawing.Color clrNearGreen = System.Drawing.Color.FromArgb(0, 254, 0); System.Drawing.Color clrTransparentHalo = System.Drawing.Color.FromArgb(0, 246, 246, 246); System.Drawing.Color clrActualBackground = backgroundColor; Bitmap image1 = logicalImage as Bitmap; if (scalingMode != ImageScalingMode.NearestNeighbor && image1 != null) { if (pixelFormat != System.Drawing.Imaging.PixelFormat.Format32bppArgb) { Rectangle rect = new Rectangle(0, 0, logicalImage.Width, logicalImage.Height); logicalImage = image1.Clone(rect, System.Drawing.Imaging.PixelFormat.Format32bppArgb); image1 = (Bitmap)logicalImage; if (backgroundColor != System.Drawing.Color.Transparent && backgroundColor.A != byte.MaxValue) { backgroundColor = System.Drawing.Color.FromArgb(byte.MaxValue, backgroundColor); } } ProcessBitmapPixels(image1, (ref byte alpha, ref byte red, ref byte green, ref byte blue) => { if (backgroundColor != System.Drawing.Color.Transparent) { if (alpha != backgroundColor.A || red != backgroundColor.R || (green != backgroundColor.G || blue != backgroundColor.B)) { return; } alpha = clrTransparentHalo.A; red = clrTransparentHalo.R; green = clrTransparentHalo.G; blue = clrTransparentHalo.B; clrActualBackground = backgroundColor; } else if (alpha == clrMagenta.A && red == clrMagenta.R && (green == clrMagenta.G && blue == clrMagenta.B)) { alpha = clrTransparentHalo.A; red = clrTransparentHalo.R; green = clrTransparentHalo.G; blue = clrTransparentHalo.B; clrActualBackground = clrMagenta; } else { if (alpha != clrNearGreen.A || red != clrNearGreen.R || (green != clrNearGreen.G || blue != clrNearGreen.B)) { return; } alpha = clrTransparentHalo.A; red = clrTransparentHalo.R; green = clrTransparentHalo.G; blue = clrTransparentHalo.B; clrActualBackground = clrNearGreen; } }); if (clrActualBackground == System.Drawing.Color.Transparent && pixelFormat != System.Drawing.Imaging.PixelFormat.Format32bppArgb) { clrActualBackground = !(backgroundColor != System.Drawing.Color.Transparent) ? clrMagenta : backgroundColor; } } Image image2; if (logicalImage is Bitmap) { image2 = new Bitmap(deviceImageSize.Width, deviceImageSize.Height, logicalImage.PixelFormat); } else { if (!(logicalImage is Metafile)) { throw new ArgumentException("Unsupported image type for High DPI conversion", nameof(logicalImage)); } IntPtr dc = NativeMethods.User32.GetDC(IntPtr.Zero); try { image2 = new Metafile(dc, EmfType.EmfPlusDual); } finally { NativeMethods.User32.ReleaseDC(IntPtr.Zero, dc); } } using (Graphics graphics = Graphics.FromImage(image2)) { graphics.InterpolationMode = interpolationMode; graphics.Clear(backgroundColor); RectangleF srcRect = new RectangleF(0.0f, 0.0f, logicalImage.Size.Width, logicalImage.Size.Height); srcRect.Offset(-0.5f, -0.5f); RectangleF destRect = new RectangleF(0.0f, 0.0f, deviceImageSize.Width, deviceImageSize.Height); if (scalingMode == ImageScalingMode.BorderOnly) { destRect = new RectangleF(0.0f, 0.0f, srcRect.Width, srcRect.Height); destRect.Offset((float)((deviceImageSize.Width - (double)srcRect.Width) / 2.0), (float)((deviceImageSize.Height - (double)srcRect.Height) / 2.0)); } graphics.DrawImage(logicalImage, destRect, srcRect, GraphicsUnit.Pixel); } Bitmap image3 = image2 as Bitmap; if (scalingMode != ImageScalingMode.NearestNeighbor && image3 != null) { ProcessBitmapPixels(image3, (ref byte alpha, ref byte red, ref byte green, ref byte blue) => { if (alpha == byte.MaxValue) { return; } alpha = clrActualBackground.A; red = clrActualBackground.R; green = clrActualBackground.G; blue = clrActualBackground.B; }); if (pixelFormat != System.Drawing.Imaging.PixelFormat.Format32bppArgb) { Rectangle rect = new Rectangle(0, 0, image2.Width, image2.Height); image2 = image3.Clone(rect, pixelFormat); } } return(image2); }
public static Bitmap CreateDeviceFromLogicalImage(this Bitmap logicalBitmapStrip, System.Drawing.Size logicalImageSize, System.Drawing.Color backgroundColor, ImageScalingMode scalingMode = ImageScalingMode.Default) { return(Instance.CreateDeviceFromLogicalImage(logicalBitmapStrip, logicalImageSize, backgroundColor, scalingMode)); }
protected virtual ImageScalingMode GetImageScalingModeOverride(int dpiScalePercent, ImageScalingMode defaultImageScalingMode) { return(defaultImageScalingMode); }
public static void LogicalToDeviceUnits(ref Icon icon, ImageScalingMode scalingMode = ImageScalingMode.Default) { Instance.LogicalToDeviceUnits(ref icon, scalingMode); }
public void LogicalToDeviceUnits(ref ImageList imageList, System.Drawing.Color backgroundColor, ImageScalingMode scalingMode = ImageScalingMode.Default) { Validate.IsNotNull(imageList, "imageList"); if (!IsScalingRequired) { return; } ImageList fromLogicalImage = CreateDeviceFromLogicalImage(imageList, backgroundColor, scalingMode); imageList.Dispose(); imageList = fromLogicalImage; }
public static void LogicalToDeviceUnits(ref ImageList imageList, ImageScalingMode scalingMode = ImageScalingMode.Default) { Instance.LogicalToDeviceUnits(ref imageList, scalingMode); }
public ImageList CreateDeviceFromLogicalImage(ImageList logicalImageList, ImageScalingMode scalingMode = ImageScalingMode.Default) { return(CreateDeviceFromLogicalImage(logicalImageList, System.Drawing.Color.Transparent, scalingMode)); }
public static ImageList CreateDeviceFromLogicalImage(this ImageList logicalImageList, ImageScalingMode scalingMode = ImageScalingMode.Default) { return(Instance.CreateDeviceFromLogicalImage(logicalImageList, scalingMode)); }
public void LogicalToDeviceUnits(ref Bitmap bitmapImage, System.Drawing.Color backgroundColor, ImageScalingMode scalingMode = ImageScalingMode.Default) { Image image = bitmapImage; LogicalToDeviceUnits(ref image, backgroundColor, scalingMode); bitmapImage = (Bitmap)image; }
public ImageInputRenderer(ImageScalingMode scalingMode, GraphicsOptions graphicsOptions) { ScalingMode = scalingMode; GraphicsOptions = graphicsOptions; }
public void LogicalToDeviceUnits(ref ImageList imageList, ImageScalingMode scalingMode = ImageScalingMode.Default) { LogicalToDeviceUnits(ref imageList, System.Drawing.Color.Transparent, scalingMode); }