当前位置: 首页>>代码示例>>C#>>正文


C# ImageAttributes.SetWrapMode方法代码示例

本文整理汇总了C#中System.Drawing.Imaging.ImageAttributes.SetWrapMode方法的典型用法代码示例。如果您正苦于以下问题:C# ImageAttributes.SetWrapMode方法的具体用法?C# ImageAttributes.SetWrapMode怎么用?C# ImageAttributes.SetWrapMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Imaging.ImageAttributes的用法示例。


在下文中一共展示了ImageAttributes.SetWrapMode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ResizeImage

        //Метод для высококачественного изменения размера изображения
        public static Image ResizeImage(Image image, int width, int height)
        {
            //Если изменять нечего, возвращаем исходное изображение без изменений
            if ((image.Width == width && image.Height == height) || (width == 0 && height == 0))
                return new Bitmap(image);

            var destRect = new Rectangle(0, 0, width, height);
            var destImage = new Bitmap(width, height);

            destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

            using (var graphics = Graphics.FromImage(destImage))
            {
                graphics.CompositingMode = CompositingMode.SourceCopy;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                graphics.SmoothingMode = SmoothingMode.HighQuality;
                graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

                using (var wrapMode = new ImageAttributes())
                {
                    wrapMode.SetWrapMode(WrapMode.TileFlipXY);
                    graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
                }
            }

            return destImage;
        }
开发者ID:Maxx53,项目名称:MiloSnake,代码行数:29,代码来源:Utils.cs

示例2: ResizeImage

        public static Image ResizeImage(Image img, int width, int height)
        {
            if (width < 1 || height < 1 || (img.Width == width && img.Height == height))
            {
                return img;
            }

            Bitmap bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb);
            bmp.SetResolution(img.HorizontalResolution, img.VerticalResolution);

            using (img)
            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                g.SmoothingMode = SmoothingMode.HighQuality;
                g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                g.CompositingQuality = CompositingQuality.HighQuality;
                g.CompositingMode = CompositingMode.SourceOver;

                using (ImageAttributes ia = new ImageAttributes())
                {
                    ia.SetWrapMode(WrapMode.TileFlipXY);
                    g.DrawImage(img, new Rectangle(0, 0, width, height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
                }
            }

            return bmp;
        }
开发者ID:L1Q,项目名称:ShareX,代码行数:28,代码来源:ImageHelpers.cs

示例3: ResizeImage

        public static Bitmap ResizeImage(Image image, System.Drawing.Size newSize)
        {
            // Make a rectangle that is the new size
            Rectangle destRect = new Rectangle(0, 0, newSize.Width, newSize.Height);

            // Make a bitmap that is the new size
            Bitmap destImage = new Bitmap(newSize.Width, newSize.Height);

            // Set new image to the resolution of the original
            destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

            // Create a GDI holder and use it
            using (Graphics graphics = Graphics.FromImage(destImage))
            {

                // Set our quality options
                graphics.CompositingMode = CompositingMode.SourceCopy;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                graphics.SmoothingMode = SmoothingMode.HighQuality;
                graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

                // Resize original image into new one
                using (var wrapMode = new ImageAttributes())
                {
                    wrapMode.SetWrapMode(WrapMode.TileFlipXY);
                    graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
                }
            }
            return destImage;
        }
开发者ID:egoebelbecker,项目名称:ComicViewer-2,代码行数:31,代码来源:MainWindow.xaml.cs

示例4: ProcessImage

        /// <summary>
        /// Resizes the image using a high quality.  
        /// From http://stackoverflow.com/questions/1922040/resize-an-image-c-sharp
        /// </summary>
        /// <param name="imageStream"></param>
        /// <returns></returns>
        internal static MemoryStream ProcessImage(MemoryStream imageStream)
        {
            var height = 100;
            var width = 100;

            Image original = Image.FromStream(imageStream);

            var destRect = new Rectangle(0, 0, width, height);
            var destImage = new Bitmap(width, height);

            destImage.SetResolution(original.HorizontalResolution, original.VerticalResolution);

            using (var graphics = Graphics.FromImage(destImage))
            {
                graphics.CompositingMode = CompositingMode.SourceCopy;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                graphics.SmoothingMode = SmoothingMode.HighQuality;
                graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

                using (var wrapMode = new ImageAttributes())
                {
                    wrapMode.SetWrapMode(WrapMode.TileFlipXY);
                    graphics.DrawImage(original, destRect, 0, 0, original.Width, original.Height, GraphicsUnit.Pixel, wrapMode);
                }
            }

            MemoryStream ret = new MemoryStream();
            destImage.Save(ret, original.RawFormat);
            ret.FlushAsync().Wait();
            ret.Position = 0;
            return ret;
        }
开发者ID:kaevans,项目名称:globalscaledemo,代码行数:39,代码来源:PhotoEditor.cs

示例5: LoadImage

        /// <summary>
        ///     Loads an image from path into a byte array.
        /// </summary>
        public static byte[] LoadImage(string path)
        {
            var image = Image.FromFile(path);

            var destinationRectangle = new Rectangle(0, 0, TargetWidth, TargetHeight);
            var destinationImage = new Bitmap(TargetWidth, TargetHeight);

            destinationImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

            using (var graphics = Graphics.FromImage(image))
            {
                graphics.CompositingMode = CompositingMode.SourceCopy;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                graphics.SmoothingMode = SmoothingMode.HighQuality;
                graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

                using (var wrapMode = new ImageAttributes())
                {
                    wrapMode.SetWrapMode(WrapMode.TileFlipXY);
                    graphics.DrawImage(image, destinationRectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
                }
            }

            byte[] buffer;
            using (var stream = new MemoryStream())
            {
                image.Save(stream, ImageFormat.Png);
                buffer = stream.ToArray();
            }
            return buffer;
        }
开发者ID:andreassjoberg,项目名称:Tfs2015SetPicture,代码行数:35,代码来源:ImageLoader.cs

示例6: MakeGrayscale

        /// <summary>
        /// Converts a bitmap to grayscale.  Based on:
        /// http://tech.pro/tutorial/660/csharp-tutorial-convert-a-color-image-to-grayscale
        /// </summary>
        public static Bitmap MakeGrayscale(this Bitmap original, int newWidth, int newHeight)
        {
            // Create a blank bitmap the desired size
            Bitmap newBitmap = new Bitmap(newWidth, newHeight);

            using (Graphics g = Graphics.FromImage(newBitmap))
            {
                // Create the grayscale ColorMatrix
                ColorMatrix colorMatrix = new ColorMatrix(new float[][] 
                {
                    new float[] { .3f, .3f, .3f, 0, 0 },
                    new float[] { .59f, .59f, .59f, 0, 0 },
                    new float[] { .11f, .11f, .11f, 0, 0 },
                    new float[] { 0, 0, 0, 1, 0 },
                    new float[] { 0, 0, 0, 0, 1 }
                });

                ImageAttributes attributes = new ImageAttributes();

                // Set the color matrix attribute
                attributes.SetColorMatrix(colorMatrix);

                // Fixes "ringing" around the borders...
                attributes.SetWrapMode(WrapMode.TileFlipXY);

                // Draw the original image on the new image using the grayscale color matrix
                g.CompositingMode = CompositingMode.SourceCopy;
                g.SmoothingMode = SmoothingMode.HighQuality;
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                g.DrawImage(original, new Rectangle(0, 0, newWidth, newHeight), 0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);
            }

            return newBitmap;
        }
开发者ID:nazrazam,项目名称:Sacknet.KinectFacialRecognition,代码行数:39,代码来源:BitmapExtensions.cs

示例7: DrawBackgroundImage

 public static void DrawBackgroundImage(Graphics g, Image backgroundImage, Color backColor, ImageLayout backgroundImageLayout, Rectangle bounds, Rectangle clipRect, Point scrollOffset, RightToLeft rightToLeft)
 {
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     if (backgroundImageLayout == ImageLayout.Tile)
     {
         using (TextureBrush brush = new TextureBrush(backgroundImage, WrapMode.Tile))
         {
             if (scrollOffset != Point.Empty)
             {
                 Matrix transform = brush.Transform;
                 transform.Translate((float) scrollOffset.X, (float) scrollOffset.Y);
                 brush.Transform = transform;
             }
             g.FillRectangle(brush, clipRect);
             return;
         }
     }
     Rectangle rect = CalculateBackgroundImageRectangle(bounds, backgroundImage, backgroundImageLayout);
     if ((rightToLeft == RightToLeft.Yes) && (backgroundImageLayout == ImageLayout.None))
     {
         rect.X += clipRect.Width - rect.Width;
     }
     using (SolidBrush brush2 = new SolidBrush(backColor))
     {
         g.FillRectangle(brush2, clipRect);
     }
     if (!clipRect.Contains(rect))
     {
         if ((backgroundImageLayout == ImageLayout.Stretch) || (backgroundImageLayout == ImageLayout.Zoom))
         {
             rect.Intersect(clipRect);
             g.DrawImage(backgroundImage, rect);
         }
         else if (backgroundImageLayout == ImageLayout.None)
         {
             rect.Offset(clipRect.Location);
             Rectangle destRect = rect;
             destRect.Intersect(clipRect);
             Rectangle rectangle3 = new Rectangle(Point.Empty, destRect.Size);
             g.DrawImage(backgroundImage, destRect, rectangle3.X, rectangle3.Y, rectangle3.Width, rectangle3.Height, GraphicsUnit.Pixel);
         }
         else
         {
             Rectangle rectangle4 = rect;
             rectangle4.Intersect(clipRect);
             Rectangle rectangle5 = new Rectangle(new Point(rectangle4.X - rect.X, rectangle4.Y - rect.Y), rectangle4.Size);
             g.DrawImage(backgroundImage, rectangle4, rectangle5.X, rectangle5.Y, rectangle5.Width, rectangle5.Height, GraphicsUnit.Pixel);
         }
     }
     else
     {
         ImageAttributes imageAttr = new ImageAttributes();
         imageAttr.SetWrapMode(WrapMode.TileFlipXY);
         g.DrawImage(backgroundImage, rect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAttr);
         imageAttr.Dispose();
     }
 }
开发者ID:zhushengwen,项目名称:example-zhushengwen,代码行数:60,代码来源:CmbControlPaintEx.cs

示例8: ResizeImage

		private static Bitmap ResizeImage(Image image, int width, int height) {
			if ((image == null) || (width <= 0) || (height <= 0)) {
				Logging.LogNullError(nameof(image) + " || " + nameof(width) + " || " + nameof(height));
				return null;
			}

			Rectangle destRect = new Rectangle(0, 0, width, height);
			Bitmap destImage = new Bitmap(width, height);

			destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

			using (Graphics graphics = Graphics.FromImage(destImage)) {
				graphics.CompositingMode = CompositingMode.SourceCopy;
				graphics.CompositingQuality = CompositingQuality.HighQuality;
				graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
				graphics.SmoothingMode = SmoothingMode.HighQuality;
				graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

				using (ImageAttributes wrapMode = new ImageAttributes()) {
					wrapMode.SetWrapMode(WrapMode.TileFlipXY);
					graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
				}
			}

			return destImage;
		}
开发者ID:Kasp42,项目名称:ArchiSteamFarm,代码行数:26,代码来源:MainForm.cs

示例9: ResizeImage

        public static Bitmap ResizeImage(Image image, int width, int height)
        {
            var destRect = new Rectangle(0, 0, width, height);
            var destImage = new Bitmap(width, height);

            destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

            using (var graphics = Graphics.FromImage(destImage))
            {
                graphics.CompositingMode = CompositingMode.SourceCopy;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                graphics.SmoothingMode = SmoothingMode.HighQuality;
                graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

                using (var wrapMode = new ImageAttributes())
                {
                    wrapMode.SetWrapMode(WrapMode.TileFlipXY);
                    graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
                    graphics.Dispose();
                }
            }

            return destImage;
        }
开发者ID:anhnnp,项目名称:Nhakhoaso,代码行数:25,代码来源:UtilImage.cs

示例10: ResizeImage

        /// <summary>
        /// Resizes the specified image to the specifed size.
        /// </summary>
        /// <param name="image">The image to resize.</param>
        /// <param name="width">The width in pixels of the resized image.</param>
        /// <param name="height">The height in pixels of the resized image.</param>
        /// <param name="dispose">The value indicating whether to dispose the specified image after returning the new resized bitmap.</param>
        /// <returns>The specifed image, resized to the specified size.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when 'image' is null.
        /// </exception>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// Thrown when 'width' is less than 0.
        ///  - OR -
        /// Thrown when 'height' is less than 0.
        /// </exception>
        public static Bitmap ResizeImage(Image image, int width, int height, bool dispose = true)
        {
            // http://stackoverflow.com/questions/1922040/resize-an-image-c-sharp

            if (image == null)
                throw new ArgumentNullException(nameof(image));
            if (width < 0)
                throw new ArgumentOutOfRangeException(nameof(width), width, "'" + nameof(width) + "' cannot be less than 0.");
            if (height < 0)
                throw new ArgumentOutOfRangeException(nameof(height), height, "'" + nameof(height) + "' cannot be less than 0.");

            Bitmap bitmap = new Bitmap(width, height);
            Graphics graphics = Graphics.FromImage(bitmap);
            ImageAttributes attributes = new ImageAttributes();

            #region >> Sets settings for high quality resizing

            bitmap.SetResolution(image.HorizontalResolution, image.VerticalResolution);
            graphics.CompositingMode = CompositingMode.SourceCopy;
            graphics.CompositingQuality = CompositingQuality.HighQuality;
            graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            graphics.SmoothingMode = SmoothingMode.HighQuality;
            graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
            attributes.SetWrapMode(WrapMode.TileFlipXY);

            #endregion
            graphics.DrawImage(image, new Rectangle(0, 0, width, height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);

            if (dispose) image.Dispose();
            graphics.Dispose();
            attributes.Dispose();

            return bitmap;
        }
开发者ID:mrGyzzz,项目名称:Certus,代码行数:50,代码来源:BitmapUtility.cs

示例11: Resize

        /// <summary>
        /// Resizes an image
        /// </summary>
        /// <param name="image">The image to resize</param>
        /// <param name="width">New width in pixels</param>
        /// <param name="height">New height in pixesl</param>
        /// <param name="useHighQuality">Resize quality</param>
        /// <returns>The resized image</returns>
        public static Bitmap Resize(this Bitmap image, int width, int height, bool useHighQuality)
        {
            var newImg = new Bitmap(width, height);

            newImg.SetResolution(image.HorizontalResolution, image.VerticalResolution);

            using (var g = Graphics.FromImage(newImg))
            {
                g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                if (useHighQuality)
                {
                    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                    g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                }
                else
                {
                    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Default;
                    g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.Default;
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
                    g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Default;
                }

                var attributes = new ImageAttributes();
                attributes.SetWrapMode(System.Drawing.Drawing2D.WrapMode.TileFlipXY);
                g.DrawImage(image, new Rectangle(0, 0, width, height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
            }

            return newImg;
        }
开发者ID:CaffeineForCode,项目名称:CNTK,代码行数:39,代码来源:CntkBitmapExtensions.cs

示例12: Resize

        /// <summary>
        /// Resizes and rotates an image, keeping the original aspect ratio. Does not dispose the original
        /// Image instance.
        /// </summary>
        /// <param name="image">Image instance</param>
        /// <param name="width">desired width</param>
        /// <param name="height">desired height</param>
        /// <param name="rotateFlipType">desired RotateFlipType</param>
        /// <returns>new resized/rotated Image instance</returns>
        public static System.Drawing.Image Resize(System.Drawing.Image image, int width, 
            int height, RotateFlipType rotateFlipType)
        {
            // clone the Image instance, since we don't want to resize the original Image instance
            var rotatedImage = image.Clone() as System.Drawing.Image;
            //rotatedImage.RotateFlip(rotateFlipType);
            var newSize = CalculateResizedDimensions(rotatedImage, width, height);

            var resizedImage = new Bitmap(newSize.Width, newSize.Height, PixelFormat.Format32bppArgb);
            resizedImage.SetResolution(72, 72);

            using (var graphics = Graphics.FromImage(resizedImage))
            {
                // set parameters to create a high-quality thumbnail
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                graphics.SmoothingMode = SmoothingMode.AntiAlias;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

                // use an image attribute in order to remove the black/gray border around image after resize
                // (most obvious on white images), see this post for more information:
                // http://www.codeproject.com/KB/GDI-plus/imgresizoutperfgdiplus.aspx
                using (var attribute = new ImageAttributes())
                {
                    attribute.SetWrapMode(WrapMode.TileFlipXY);

                    // draws the resized image to the bitmap
                    graphics.DrawImage(rotatedImage, new Rectangle(new Point(0, 0), newSize), 0, 0, rotatedImage.Width, rotatedImage.Height, GraphicsUnit.Pixel, attribute);
                }
            }

            return resizedImage;
        }
开发者ID:tonousa,项目名称:HtmlEmails,代码行数:42,代码来源:WebForm.aspx.cs

示例13: Get

        public static Bitmap Get(Image image, int maxWidth, int maxHeight)
        {
            if (image.Width < maxWidth && image.Height < maxHeight)
            {
                maxWidth = image.Width;
                maxHeight = image.Height;
            }

            var widthScaleFactor = (float)maxWidth / image.Width;
            var heightScaleFactor = (float)maxHeight / image.Height;
            var scaleFactor = widthScaleFactor > heightScaleFactor ? heightScaleFactor : widthScaleFactor;
            var width = Convert.ToInt32(scaleFactor * image.Width);
            var height = Convert.ToInt32(scaleFactor * image.Height);

            var bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb);

            bitmap.SetResolution(image.HorizontalResolution, image.VerticalResolution);

            using (var graphics = Graphics.FromImage(bitmap))
            {
                graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                graphics.CompositingMode = CompositingMode.SourceCopy;

                var imageAttributes = new ImageAttributes();
                imageAttributes.SetWrapMode(WrapMode.TileFlipXY);

                var destRectangle = new Rectangle(0, 0, width, height);

                graphics.DrawImage(image, destRectangle, 0, 0, width, height, GraphicsUnit.Pixel, imageAttributes);
            }
            return bitmap;
        }
开发者ID:cimex,项目名称:ImageManager,代码行数:34,代码来源:ResizeUtility.cs

示例14: ResizeImage

        private static Bitmap ResizeImage(Image image, int width, int height)
        {
            // Borrowed from http://stackoverflow.com/questions/1922040/resize-an-image-c-sharp
            // Ensures a high quality resizing.
            var destRect = new Rectangle(0, 0, width, height);
            var destImage = new Bitmap(width, height);

            destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

            using (var graphics = Graphics.FromImage(destImage))
            {
                graphics.CompositingMode = CompositingMode.SourceCopy;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                graphics.SmoothingMode = SmoothingMode.HighQuality;
                graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

                using (var wrapMode = new ImageAttributes())
                {
                    wrapMode.SetWrapMode(WrapMode.TileFlipXY);
                    graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
                }
            }
            return destImage;
        }
开发者ID:pprintz,项目名称:p2,代码行数:25,代码来源:ImageScanningTools.cs

示例15: FindMaxPixel

        /// <summary>
        /// Looks for the brightest pixel after applying a redness filter. Narrows search first using a resampled copy of the image to eliminate edge dots. 
        /// Expects an image that is already cropped to the interested area for faster processing.
        /// </summary>
        /// <param name="img"></param>
        /// <param name="mouse"></param>
        /// <param name="maxDistanceFromMouse"></param>
        /// <returns></returns>
        public unsafe Point FindMaxPixel(UnmanagedImage img, PointF mouse, float maxDistanceFromMouse)
        {
            int width = 15;
            int height = (int)Math.Ceiling((double)img.Height / (double)img.Width * width);

            if (width <= img.Width && height <= img.Height + 1) {
                width = img.Width;
                height = img.Height;
            }

            double scale = (double)img.Width / (double)width;

            UnmanagedImage lowRed = null;
            try {
                if (width != img.Width && height != img.Height) {
                    using (Bitmap reduced = new Bitmap(width, height, PixelFormat.Format24bppRgb))
                    using (Graphics g = Graphics.FromImage(reduced))
                    using (ImageAttributes ia = new ImageAttributes()) {
                        g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                        g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                        g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                        ia.SetWrapMode(System.Drawing.Drawing2D.WrapMode.TileFlipXY);
                        g.DrawImage(img.ToManagedImage(false), new Rectangle(0, 0, width, height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
                        //TODO: Not sure if ToManagedImage will stick around after the underying image is disposed. I know that the bitmap data will be gone, guess that's most of it.
                        using (UnmanagedImage rui = UnmanagedImage.FromManagedImage(reduced)) {
                            lowRed = new RedEyeFilter(2).Apply(rui); // Make an copy using the red eye filter
                        }
                    }
                } else {
                    //Don't resample unless needed
                    lowRed = new RedEyeFilter(2).Apply(img);
                }

                Point max = GetMax(lowRed, new PointF(mouse.X / (float)scale, mouse.Y / (float)scale), maxDistanceFromMouse / scale);

                //We weren't scaling things? OK, cool...
                if (scale == 0) return max;

                //Otherwise, let's get the unscaled pixel.
                //Calculate the rectangle surrounding the selected pixel, but in source coordinates.
                int tinySize = (int)Math.Ceiling(scale) + 1;
                Rectangle tinyArea = new Rectangle((int)Math.Floor(scale * (double)max.X), (int)Math.Floor(scale * (double)max.Y), tinySize, tinySize);
                if (tinyArea.Right >= img.Width) tinyArea.Width -= img.Width - tinyArea.Right + 1;
                if (tinyArea.Bottom >= img.Height) tinyArea.Height -= img.Height - tinyArea.Bottom + 1;
                //Filter it and look
                using (UnmanagedImage tiny = new Crop(tinyArea).Apply(img)) {
                    using (UnmanagedImage tinyRed = new RedEyeFilter(2).Apply(tiny)) {
                        max = GetMax(tinyRed);
                        max.X += tinyArea.X;
                        max.Y += tinyArea.Y;
                    }
                }
                return max;
            } finally {
                if (lowRed != null) lowRed.Dispose();
            }
        }
开发者ID:stukalin,项目名称:ImageResizer,代码行数:67,代码来源:ManualSearcher.cs


注:本文中的System.Drawing.Imaging.ImageAttributes.SetWrapMode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。