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


C# Image.CreateEmptyBitmap方法代码示例

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


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

示例1: AddCanvas

        public static Image AddCanvas(Image img, Padding margin)
        {
            Bitmap bmp = img.CreateEmptyBitmap(margin.Horizontal, margin.Vertical);

            using (Graphics g = Graphics.FromImage(bmp))
            using (img)
            {
                g.SetHighQuality();
                g.DrawImage(img, margin.Left, margin.Top, img.Width, img.Height);
            }

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

示例2: AddCanvas

        public static Image AddCanvas(Image img, int width, int height)
        {
            Bitmap bmp = img.CreateEmptyBitmap(width * 2, height * 2);

            using (Graphics g = Graphics.FromImage(bmp))
            using (img)
            {
                g.SetHighQuality();
                g.DrawImage(img, width, height, img.Width, img.Height);
            }

            return bmp;
        }
开发者ID:modulexcite,项目名称:ShareX_Google_Code,代码行数:13,代码来源:ImageHelpers.cs

示例3: ChangeGamma

        /// <param name="img"></param>
        /// <param name="value">1 = No change (Min 0.1, Max 5.0)</param>
        public static Image ChangeGamma(Image img, float value)
        {
            value = value.Between(0.1f, 5.0f);

            Bitmap bmp = img.CreateEmptyBitmap();

            using (Graphics g = Graphics.FromImage(bmp))
            using (ImageAttributes ia = new ImageAttributes())
            {
                ia.ClearColorMatrix();
                ia.SetGamma(value, ColorAdjustType.Bitmap);
                g.SetHighQuality();
                g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
            }

            return bmp;
        }
开发者ID:barsv,项目名称:ShareX,代码行数:19,代码来源:ColorMatrixManager.cs

示例4: DrawBorder

        public static Image DrawBorder(Image img, Pen borderPen, BorderType borderType)
        {
            Bitmap bmp;

            if (borderType == BorderType.Inside)
            {
                bmp = (Bitmap)img;

                using (Graphics g = Graphics.FromImage(bmp))
                {
                    g.DrawRectangleProper(borderPen, 0, 0, img.Width, img.Height);
                }
            }
            else
            {
                int borderSize = (int)borderPen.Width;
                bmp = img.CreateEmptyBitmap(borderSize * 2, borderSize * 2);

                using (Graphics g = Graphics.FromImage(bmp))
                using (img)
                {
                    g.DrawRectangleProper(borderPen, 0, 0, bmp.Width, bmp.Height);
                    g.SetHighQuality();
                    g.DrawImage(img, borderSize, borderSize, img.Width, img.Height);
                }
            }

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

示例5: Outline

        public static Image Outline(Image img, int borderSize, Color borderColor)
        {
            Bitmap result = img.CreateEmptyBitmap(borderSize * 2, borderSize * 2);

            ColorMatrix maskMatrix = new ColorMatrix();
            maskMatrix.Matrix00 = 0;
            maskMatrix.Matrix11 = 0;
            maskMatrix.Matrix22 = 0;
            maskMatrix.Matrix33 = 1;
            maskMatrix.Matrix40 = ((float)borderColor.R).Remap(0, 255, 0, 1);
            maskMatrix.Matrix41 = ((float)borderColor.G).Remap(0, 255, 0, 1);
            maskMatrix.Matrix42 = ((float)borderColor.B).Remap(0, 255, 0, 1);

            using (img)
            using (Image shadow = maskMatrix.Apply(img))
            using (Graphics g = Graphics.FromImage(result))
            {
                for (int i = 0; i <= borderSize * 2; i++)
                {
                    g.DrawImage(shadow, new Rectangle(i, 0, shadow.Width, shadow.Height));
                    g.DrawImage(shadow, new Rectangle(i, borderSize * 2, shadow.Width, shadow.Height));
                    g.DrawImage(shadow, new Rectangle(0, i, shadow.Width, shadow.Height));
                    g.DrawImage(shadow, new Rectangle(borderSize * 2, i, shadow.Width, shadow.Height));
                }

                g.DrawImage(img, new Rectangle(borderSize, borderSize, img.Width, img.Height));
            }

            return result;
        }
开发者ID:ElectronicWar,项目名称:ShareX,代码行数:30,代码来源:ImageHelpers.cs

示例6: RoundedCorners

        public static Image RoundedCorners(Image img, int cornerRadius)
        {
            Bitmap bmp = img.CreateEmptyBitmap();

            using (Graphics g = Graphics.FromImage(bmp))
            using (img)
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.PixelOffsetMode = PixelOffsetMode.HighQuality;

                using (GraphicsPath gp = new GraphicsPath())
                {
                    gp.AddRoundedRectangleProper(new RectangleF(0, 0, img.Width, img.Height), cornerRadius);

                    using (TextureBrush brush = new TextureBrush(img))
                    {
                        g.FillPath(brush, gp);
                    }
                }
            }

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

示例7: AddSkew

        public static Bitmap AddSkew(Image img, int x, int y)
        {
            Bitmap result = img.CreateEmptyBitmap(Math.Abs(x), Math.Abs(y));

            using (Graphics g = Graphics.FromImage(result))
            using (img)
            {
                g.SetHighQuality();
                int startX = -Math.Min(0, x);
                int startY = -Math.Min(0, y);
                int endX = Math.Max(0, x);
                int endY = Math.Max(0, y);
                Point[] destinationPoints = { new Point(startX, startY), new Point(startX + img.Width - 1, endY), new Point(endX, startY + img.Height - 1) };
                g.DrawImage(img, destinationPoints);
            }

            return result;
        }
开发者ID:ElectronicWar,项目名称:ShareX,代码行数:18,代码来源:ImageHelpers.cs

示例8: FillImageBackground

        public static Bitmap FillImageBackground(Image img, Color color)
        {
            Bitmap result = img.CreateEmptyBitmap();

            using (Graphics g = Graphics.FromImage(result))
            using (img)
            {
                g.Clear(color);
                g.SetHighQuality();
                g.DrawImage(img, 0, 0, result.Width, result.Height);
            }

            return result;
        }
开发者ID:modulexcite,项目名称:ShareX_Google_Code,代码行数:14,代码来源:ImageHelpers.cs

示例9: AddShadow

        public static Bitmap AddShadow(Image sourceImage, float opacity, int size, float darkness, Color color, Point offset)
        {
            Image shadowImage = null;

            try
            {
                shadowImage = sourceImage.CreateEmptyBitmap(size * 2, size * 2);

                ColorMatrix maskMatrix = new ColorMatrix();
                maskMatrix.Matrix00 = 0;
                maskMatrix.Matrix11 = 0;
                maskMatrix.Matrix22 = 0;
                maskMatrix.Matrix33 = opacity;
                maskMatrix.Matrix40 = ((float)color.R).Remap(0, 255, 0, 1);
                maskMatrix.Matrix41 = ((float)color.G).Remap(0, 255, 0, 1);
                maskMatrix.Matrix42 = ((float)color.B).Remap(0, 255, 0, 1);

                Rectangle shadowRectangle = new Rectangle(size, size, sourceImage.Width, sourceImage.Height);
                maskMatrix.Apply(sourceImage, shadowImage, shadowRectangle);

                if (size > 0)
                {
                    Blur((Bitmap)shadowImage, size);
                }

                if (darkness > 1)
                {
                    ColorMatrix alphaMatrix = new ColorMatrix();
                    alphaMatrix.Matrix33 = darkness;

                    Image shadowImage2 = alphaMatrix.Apply(shadowImage);
                    shadowImage.Dispose();
                    shadowImage = shadowImage2;
                }

                Bitmap result = shadowImage.CreateEmptyBitmap(Math.Abs(offset.X), Math.Abs(offset.Y));

                using (Graphics g = Graphics.FromImage(result))
                {
                    g.SetHighQuality();
                    g.DrawImage(shadowImage, Math.Max(0, offset.X), Math.Max(0, offset.Y), shadowImage.Width, shadowImage.Height);
                    g.DrawImage(sourceImage, Math.Max(size, -offset.X + size), Math.Max(size, -offset.Y + size), sourceImage.Width, sourceImage.Height);
                }

                return result;
            }
            finally
            {
                if (sourceImage != null) sourceImage.Dispose();
                if (shadowImage != null) shadowImage.Dispose();
            }
        }
开发者ID:ElectronicWar,项目名称:ShareX,代码行数:52,代码来源:ImageHelpers.cs

示例10: ApplyRegionPathToImage

        public static Image ApplyRegionPathToImage(Image img, GraphicsPath gp)
        {
            if (img != null && gp != null)
            {
                Rectangle regionArea = Rectangle.Round(gp.GetBounds());
                Rectangle screenRectangle = CaptureHelpers.GetScreenBounds0Based();
                regionArea = Rectangle.Intersect(regionArea, screenRectangle);

                if (regionArea.IsValid())
                {
                    using (Bitmap bmp = img.CreateEmptyBitmap())
                    using (Graphics g = Graphics.FromImage(bmp))
                    using (TextureBrush brush = new TextureBrush(img))
                    {
                        g.PixelOffsetMode = PixelOffsetMode.Half;
                        g.SmoothingMode = SmoothingMode.HighQuality;

                        g.FillPath(brush, gp);

                        return ImageHelpers.CropBitmap(bmp, regionArea);
                    }
                }
            }

            return null;
        }
开发者ID:ElectronicWar,项目名称:ShareX,代码行数:26,代码来源:RegionCaptureTasks.cs

示例11: CreateTornEdge

        public static Image CreateTornEdge(Image sourceImage, int toothHeight, int horizontalToothRange, int verticalToothRange)
        {
            Image result = sourceImage.CreateEmptyBitmap(PixelFormat.Format32bppArgb);

            using (GraphicsPath path = new GraphicsPath())
            {
                Random random = new Random();
                int horizontalRegions = sourceImage.Width / horizontalToothRange;
                int verticalRegions = sourceImage.Height / verticalToothRange;

                // Start
                Point previousEndingPoint = new Point(horizontalToothRange, random.Next(1, toothHeight));
                Point newEndingPoint;

                // Top
                for (int i = 0; i < horizontalRegions; i++)
                {
                    int x = previousEndingPoint.X + horizontalToothRange;
                    int y = random.Next(1, toothHeight);
                    newEndingPoint = new Point(x, y);
                    path.AddLine(previousEndingPoint, newEndingPoint);
                    previousEndingPoint = newEndingPoint;
                }

                // Right
                for (int i = 0; i < verticalRegions; i++)
                {
                    int x = sourceImage.Width - random.Next(1, toothHeight);
                    int y = previousEndingPoint.Y + verticalToothRange;
                    newEndingPoint = new Point(x, y);
                    path.AddLine(previousEndingPoint, newEndingPoint);
                    previousEndingPoint = newEndingPoint;
                }

                // Bottom
                for (int i = 0; i < horizontalRegions; i++)
                {
                    int x = previousEndingPoint.X - horizontalToothRange;
                    int y = sourceImage.Height - random.Next(1, toothHeight);
                    newEndingPoint = new Point(x, y);
                    path.AddLine(previousEndingPoint, newEndingPoint);
                    previousEndingPoint = newEndingPoint;
                }

                // Left
                for (int i = 0; i < verticalRegions; i++)
                {
                    int x = random.Next(1, toothHeight);
                    int y = previousEndingPoint.Y - verticalToothRange;
                    newEndingPoint = new Point(x, y);
                    path.AddLine(previousEndingPoint, newEndingPoint);
                    previousEndingPoint = newEndingPoint;
                }

                path.CloseFigure();

                // Draw the created figure with the original image by using a TextureBrush so we have anti-aliasing
                using (Graphics graphics = Graphics.FromImage(result))
                {
                    graphics.SmoothingMode = SmoothingMode.HighQuality;
                    graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
                    graphics.CompositingQuality = CompositingQuality.HighQuality;
                    graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

                    using (Brush brush = new TextureBrush(sourceImage))
                    {
                        // Imporant note: If the target wouldn't be at 0,0 we need to translate-transform!!
                        graphics.FillPath(brush, path);
                    }
                }
            }

            return result;
        }
开发者ID:kurozael,项目名称:ShareX,代码行数:74,代码来源:ImageHelpers.cs

示例12: RotateImage

        /// <summary>
        /// Method to rotate an Image object. The result can be one of three cases:
        /// - upsizeOk = true: output image will be larger than the input and no clipping occurs
        /// - upsizeOk = false & clipOk = true: output same size as input, clipping occurs
        /// - upsizeOk = false & clipOk = false: output same size as input, image reduced, no clipping
        ///
        /// Note that this method always returns a new Bitmap object, even if rotation is zero - in
        /// which case the returned object is a clone of the input object.
        /// </summary>
        /// <param name="img">input Image object, is not modified</param>
        /// <param name="angleDegrees">angle of rotation, in degrees</param>
        /// <param name="upsize">see comments above</param>
        /// <param name="clip">see comments above, not used if upsizeOk = true</param>
        /// <returns>new Bitmap object, may be larger than input image</returns>
        public static Bitmap RotateImage(Image img, float angleDegrees, bool upsize, bool clip)
        {
            // Test for zero rotation and return a clone of the input image
            if (angleDegrees == 0f)
                return (Bitmap)img.Clone();

            // Set up old and new image dimensions, assuming upsizing not wanted and clipping OK
            int oldWidth = img.Width;
            int oldHeight = img.Height;
            int newWidth = oldWidth;
            int newHeight = oldHeight;
            float scaleFactor = 1f;

            // If upsizing wanted or clipping not OK calculate the size of the resulting bitmap
            if (upsize || !clip)
            {
                double angleRadians = angleDegrees * Math.PI / 180d;

                double cos = Math.Abs(Math.Cos(angleRadians));
                double sin = Math.Abs(Math.Sin(angleRadians));
                newWidth = (int)Math.Round(oldWidth * cos + oldHeight * sin);
                newHeight = (int)Math.Round(oldWidth * sin + oldHeight * cos);
            }

            // If upsizing not wanted and clipping not OK need a scaling factor
            if (!upsize && !clip)
            {
                scaleFactor = Math.Min((float)oldWidth / newWidth, (float)oldHeight / newHeight);
                newWidth = oldWidth;
                newHeight = oldHeight;
            }

            // Create the new bitmap object.
            Bitmap newBitmap = img.CreateEmptyBitmap();

            // Create the Graphics object that does the work
            using (Graphics g = Graphics.FromImage(newBitmap))
            {
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                g.SmoothingMode = SmoothingMode.HighQuality;

                // Set up the built-in transformation matrix to do the rotation and maybe scaling
                g.TranslateTransform(newWidth / 2f, newHeight / 2f);

                if (scaleFactor != 1f)
                    g.ScaleTransform(scaleFactor, scaleFactor);

                g.RotateTransform(angleDegrees);
                g.TranslateTransform(-oldWidth / 2f, -oldHeight / 2f);

                // Draw the result
                g.DrawImage(img, 0, 0, img.Width, img.Height);
            }

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

示例13: TornEdges

        public static Image TornEdges(Image img, int tornDepth, int tornRange, AnchorStyles sides)
        {
            if (sides == AnchorStyles.None)
            {
                return img;
            }

            using (GraphicsPath gp = new GraphicsPath())
            {
                Point previousPoint, currentPoint;
                int horizontalTornCount = img.Width / tornRange;
                int verticalTornCount = img.Height / tornRange;

                if (sides.HasFlag(AnchorStyles.Top))
                {
                    previousPoint = new Point(tornRange, MathHelpers.Random(0, tornDepth));

                    for (int i = 0; i < horizontalTornCount - 1; i++)
                    {
                        currentPoint = new Point(previousPoint.X + tornRange, MathHelpers.Random(0, tornDepth));
                        gp.AddLine(previousPoint, currentPoint);
                        previousPoint = currentPoint;
                    }
                }
                else
                {
                    previousPoint = new Point(0, 0);
                    currentPoint = new Point(img.Width - 1, 0);
                    gp.AddLine(previousPoint, currentPoint);
                    previousPoint = currentPoint;
                }

                if (sides.HasFlag(AnchorStyles.Right))
                {
                    for (int i = 0; i < verticalTornCount; i++)
                    {
                        currentPoint = new Point(img.Width - 1 - MathHelpers.Random(0, tornDepth), previousPoint.Y + tornRange);
                        gp.AddLine(previousPoint, currentPoint);
                        previousPoint = currentPoint;
                    }
                }
                else
                {
                    currentPoint = new Point(img.Width - 1, img.Height - 1);
                    gp.AddLine(previousPoint, currentPoint);
                    previousPoint = currentPoint;
                }

                if (sides.HasFlag(AnchorStyles.Bottom))
                {
                    for (int i = 0; i < horizontalTornCount; i++)
                    {
                        currentPoint = new Point(previousPoint.X - tornRange, img.Height - 1 - MathHelpers.Random(0, tornDepth));
                        gp.AddLine(previousPoint, currentPoint);
                        previousPoint = currentPoint;
                    }
                }
                else
                {
                    currentPoint = new Point(0, img.Height - 1);
                    gp.AddLine(previousPoint, currentPoint);
                    previousPoint = currentPoint;
                }

                if (sides.HasFlag(AnchorStyles.Left))
                {
                    for (int i = 0; i < verticalTornCount; i++)
                    {
                        currentPoint = new Point(MathHelpers.Random(0, tornDepth), previousPoint.Y - tornRange);
                        gp.AddLine(previousPoint, currentPoint);
                        previousPoint = currentPoint;
                    }
                }
                else
                {
                    currentPoint = new Point(0, 0);
                    gp.AddLine(previousPoint, currentPoint);
                    previousPoint = currentPoint;
                }

                gp.CloseFigure();

                Bitmap result = img.CreateEmptyBitmap();

                using (img)
                using (Graphics g = Graphics.FromImage(result))
                using (TextureBrush brush = new TextureBrush(img))
                {
                    g.SetHighQuality();
                    g.FillPath(brush, gp);

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

示例14: CopyImageDefaultFillBackground

        private static bool CopyImageDefaultFillBackground(Image img, Color background)
        {
            using (Bitmap bmp = img.CreateEmptyBitmap(PixelFormat.Format24bppRgb))
            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.Clear(background);
                g.DrawImage(img, 0, 0, img.Width, img.Height);

                IDataObject dataObject = new DataObject();
                dataObject.SetData(DataFormats.Bitmap, true, bmp);

                return CopyData(dataObject);
            }
        }
开发者ID:louisyoo,项目名称:ShareX,代码行数:14,代码来源:ClipboardHelpers.cs

示例15: FillBackground

        public static Bitmap FillBackground(Image img, Brush brush)
        {
            Bitmap result = img.CreateEmptyBitmap();

            using (Graphics g = Graphics.FromImage(result))
            using (img)
            {
                g.FillRectangle(brush, 0, 0, result.Width, result.Height);
                g.SetHighQuality();
                g.DrawImage(img, 0, 0, result.Width, result.Height);
            }

            return result;
        }
开发者ID:ElectronicWar,项目名称:ShareX,代码行数:14,代码来源:ImageHelpers.cs


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