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


C# System.Drawing.Bitmap.Save方法代码示例

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


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

示例1: DownloadImage

        /// <summary>
        /// 
        /// </summary>
        /// <param name="url"></param>
        /// <param name="path"></param>
        /// <param name="timeout"></param>
        public void DownloadImage(string url, string path, int timeout = 50000)
        {
            var response = GetResponseStream(url, timeout);

            if(response == null) throw new Exception("Image not dowloaded, no response from : " + url);

            var bitmap = new System.Drawing.Bitmap(response);
            bitmap.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
        }
开发者ID:temik911,项目名称:audio,代码行数:15,代码来源:WebDownloaderService.cs

示例2: GetVideoFrame

        public static BitmapImage GetVideoFrame(string FileName, double Delta)
        {
            IntPtr Bits = IntPtr.Zero;
            int Width = 0;
            int Height = 0;
            if (!GetVideoFrame(FileName, Delta, ref Bits, ref Width, ref Height))
            {
                throw new Exception("GetVideoFrame called failed");
            }

            var bmp = new System.Drawing.Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            var bmpData = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite,
                System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            MoveMemory(bmpData.Scan0, Bits, bmpData.Stride * bmpData.Height);

            bmp.UnlockBits(bmpData);
            Marshal.FreeHGlobal(Bits);

            var ms = new MemoryStream();
            bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);

            var bmpImage = new BitmapImage();
            bmpImage.BeginInit();
            bmpImage.StreamSource = ms;
            bmpImage.EndInit();
 
            return bmpImage;
        }
开发者ID:vhanla,项目名称:XWindows-Dock-2.0,代码行数:29,代码来源:Video.cs

示例3: Main

        static void Main(string[] args)
        {
            var cam = new Fray.Camera(new Point3D(3.5, -6, 4), new Point3D(0, 0.0, 0), new Vector3D(0, 0, 1), Math.PI/3.0);

            SetupMaterials();
            SetupMatrices();

            var sphere1 = Fray.Shape.NewSphere(m1, mx1);
            var sphere2 = Fray.Shape.NewSphere(m2, mx2);
            var sphere3 = Fray.Shape.NewSphere(m3, mx3);
            var plane = Fray.Shape.NewPlane(m4, mx4);

            var light = new Fray.Light(new Point3D(-3, 0, 2),      new Color(0.7, 0.7, 0.7));
            var light2 = new Fray.Light(new Point3D(-1, -5.5, 2.5), new Color(0.7, 0.7, 0.7));
            var light3 = new Fray.Light(new Point3D(1, 2.5, 2),    new Color(0.7, 0.7, 0.7));

            var scene = new Scene(cam, new[] { sphere1,sphere2,sphere3,plane }, new Color(0.2, 0.2, 0.2), new[] { light,light2,light3 });
            var ray = new Ray(cam.position, new Vector3D(3, 0.0, 0));

            var colors = Fray.Fray.RayTrace(width, height, 3, scene);

            var bmp = new System.Drawing.Bitmap(width, height);

            foreach (var tuple in colors)
            {
                var c = tuple.Item3;
                var color = System.Drawing.Color.FromArgb(255, (int)(255 * c.r), (int)(255 * c.g), (int)(255 * c.b));
                SetPixel(tuple.Item1, tuple.Item2, color, bmp);
            }
            bmp.Save(@"output.jpg");
        }
开发者ID:MartinDoms,项目名称:Fray,代码行数:31,代码来源:Program.cs

示例4: CreateThumbnail

        public static void CreateThumbnail(string source, string dest)
        {
            try
            {
                System.Drawing.Image src_image = System.Drawing.Image.FromFile(source);

                int smallDim = 100;
                int SMALLWIDTH, SMALLHEIGHT;
                if (src_image.Width > src_image.Height)
                {
                    SMALLWIDTH = smallDim;
                    SMALLHEIGHT = (int)((((decimal)SMALLWIDTH) * src_image.Height) / src_image.Width);
                }
                else
                {
                    SMALLHEIGHT = smallDim;
                    SMALLWIDTH = (int)((((decimal)SMALLHEIGHT) * src_image.Width) / src_image.Height);
                }
                System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(SMALLWIDTH, SMALLHEIGHT, src_image.PixelFormat);
                System.Drawing.Graphics new_g = System.Drawing.Graphics.FromImage(bitmap);

                new_g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                new_g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                new_g.DrawImage(src_image, 0, 0, bitmap.Width, bitmap.Height);
                bitmap.Save(dest, System.Drawing.Imaging.ImageFormat.Jpeg);

                return;
            }
            catch
            {
                return;
            }
        }
开发者ID:sujalp,项目名称:WPFALC,代码行数:33,代码来源:MiscPhotoServices.cs

示例5: SomeClass

        public static void SomeClass()
        {
            var graph = new MSAGL.Drawing.Graph("");
            graph.AddEdge("A", "B");
            graph.AddEdge("A", "B");
            graph.FindNode("A").Attr.FillColor = MSAGL.Drawing.Color.BlanchedAlmond;
            graph.FindNode("B").Attr.FillColor = MSAGL.Drawing.Color.BurlyWood;
            var renderer = new MSAGL.GraphViewerGdi.GraphRenderer(graph);
            renderer.CalculateLayout();
            const int width = 50;
            int height = (int)(graph.Height * (width / graph.Width));
            const PixelFormat pixfmt = System.Drawing.Imaging.PixelFormat.Format32bppPArgb;
            using (var bitmap = new System.Drawing.Bitmap(width, height, pixfmt))
            {
                using (var gfx = System.Drawing.Graphics.FromImage(bitmap))
                {
                    gfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    gfx.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                    gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                    var rect = new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height);
                    renderer.Render(gfx, rect);
                    bitmap.Save("test.png");

                }

            }
           
        }
开发者ID:Exclr8,项目名称:CloudCore,代码行数:29,代码来源:MsaglGraph.cs

示例6: MakeImagesNegative

        static void MakeImagesNegative(string sourceDirectoryPath, string targetDirectoryPath)
        {
            string[] filenames = System.IO.Directory.GetFiles(sourceDirectoryPath);

            foreach (var filename in filenames)
            {
                System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(filename);
                Parallel.For(0, bitmap.Height, (bitmapRowIndex) =>
                {
                    lock (bitmap)
                    {
                        for (int bitmapColIndex = 0; bitmapColIndex < bitmap.Width; bitmapColIndex++)
                        {

                            var pixel = bitmap.GetPixel(bitmapColIndex, bitmapRowIndex);
                            var negativePixel = System.Drawing.Color.FromArgb(
                                byte.MaxValue - pixel.A,
                                byte.MaxValue - pixel.R,
                                byte.MaxValue - pixel.G,
                                byte.MaxValue - pixel.B);

                            bitmap.SetPixel(bitmapColIndex, bitmapRowIndex, negativePixel);
                        }
                    }
                });

                bitmap.Save(filename.Replace(sourceDirectoryPath, targetDirectoryPath));
            }
        }
开发者ID:TelerikAcademy,项目名称:TelerikAcademyPlus,代码行数:29,代码来源:Program.cs

示例7: CreateAvatar

        public static byte[] CreateAvatar(int sideLength, System.IO.Stream fromStream)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream();

            using (var image = System.Drawing.Image.FromStream(fromStream))
            using (var thumbBitmap = new System.Drawing.Bitmap(sideLength, sideLength))
            {

                var a = Math.Min(image.Width, image.Height);

                var x = (image.Width - a) / 2;

                var y = (image.Height - a) / 2;

                using (var thumbGraph = System.Drawing.Graphics.FromImage(thumbBitmap))
                {

                    thumbGraph.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;

                    thumbGraph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                    thumbGraph.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                    var imgRectangle = new System.Drawing.Rectangle(0, 0, sideLength, sideLength);

                    thumbGraph.DrawImage(image, imgRectangle, x, y, a, a, System.Drawing.GraphicsUnit.Pixel);

                    thumbBitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

                }

            }
            return (ms.ToArray());
        }
开发者ID:kyallbarrows,项目名称:LifeguardServer,代码行数:34,代码来源:Utilities.cs

示例8: IsBig

        public string IsBig(string originalImagePath, int intWidth)
        {
            bool isExist = WXSSK.Common.DirectoryAndFile.FileExists(originalImagePath);
            System.Drawing.Image imgOriginal = System.Drawing.Image.FromFile(Server.MapPath(originalImagePath));

            //获取原图片的的宽度与高度
            int originalWidth = imgOriginal.Width;
            int originalHeight = imgOriginal.Height;

            //如果原图片宽度大于原图片的高度
            if (originalWidth > intWidth)
            {
                originalWidth = intWidth;  //宽度等于缩略图片尺寸
                originalHeight = originalHeight * (intWidth / originalWidth);  //高度做相应比例缩小
            }

            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(originalWidth, originalHeight);
            System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap);

            //设置缩略图片质量
            graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
            graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            graphics.DrawImage(imgOriginal, 0, 0, originalWidth, originalHeight);

            //System.Drawing.Graphics temp = graphics;
            // 保存缩略图片
            imgOriginal.Dispose();
            WXSSK.Common.DirectoryAndFile.DeleteFile(originalImagePath);
            bitmap.Save(Server.MapPath(originalImagePath), System.Drawing.Imaging.ImageFormat.Jpeg);
            return originalImagePath;
        }
开发者ID:leroy358,项目名称:CircusIOC,代码行数:33,代码来源:PictureController.cs

示例9: Run

        public static void Run()
        {
            // ExStart:RenderWorksheetToGraphicContext
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Create workbook object from source file
            Workbook workbook = new Workbook(dataDir + "SampleBook.xlsx");

            // Access first worksheet
            Worksheet worksheet = workbook.Worksheets[0];

            // Create empty Bitmap
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(1100, 600);

            // Create Graphics Context
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
            g.Clear(System.Drawing.Color.Blue);

            // Set one page per sheet to true in image or print options
            Aspose.Cells.Rendering.ImageOrPrintOptions opts = new Aspose.Cells.Rendering.ImageOrPrintOptions();
            opts.OnePagePerSheet = true;

            // Render worksheet to graphics context
            Aspose.Cells.Rendering.SheetRender sr = new Aspose.Cells.Rendering.SheetRender(worksheet, opts);
            sr.ToImage(0, g, 0, 0);

            // Save the graphics context image in Png format
            bmp.Save(dataDir + "OutputImage_out.png", System.Drawing.Imaging.ImageFormat.Png);
            //ExEnd:RenderWorksheetToGraphicContext
        }
开发者ID:aspose-cells,项目名称:Aspose.Cells-for-.NET,代码行数:31,代码来源:RenderWorksheetToGraphicContext.cs

示例10: Run

        public static void Run()
        {
            // ExStart:ExtractAllImagesFromPage
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Shapes();

            // Call a Diagram class constructor to load a VSD diagram
            Diagram diagram = new Diagram(dataDir + "ExtractAllImagesFromPage.vsd");

            // Enter page index i.e. 0 for first one
            foreach (Shape shape in diagram.Pages[0].Shapes)
            {
                // Filter shapes by type Foreign
                if (shape.Type == Aspose.Diagram.TypeValue.Foreign)
                {
                    using (System.IO.MemoryStream stream = new System.IO.MemoryStream(shape.ForeignData.Value))
                    {
                        // Load memory stream into bitmap object
                        System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(stream);

                        // Save bmp here
                        bitmap.Save(dataDir + "ExtractAllImages" + shape.ID + "_out.bmp");
                    }
                }
            }
            // ExEnd:ExtractAllImagesFromPage
        }
开发者ID:aspose-diagram,项目名称:Aspose.Diagram-for-.NET,代码行数:27,代码来源:ExtractAllImagesFromPage.cs

示例11: Main

        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //Call the diagram constructor to load diagram from a VSD file
            Diagram diagram = new Diagram(dataDir + "drawing.vsd");

            //enter page index i.e. 0 for first one
            foreach (Shape shape in diagram.Pages[0].Shapes)
            {
                //Filter shapes by type Foreign
                if (shape.Type == Aspose.Diagram.TypeValue.Foreign)
                {
                    using (System.IO.MemoryStream stream = new System.IO.MemoryStream(shape.ForeignData.Value))
                    {
                        //Load memory stream into bitmap object
                        System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(stream);

                        // save bmp here
                        bitmap.Save(dataDir + "Image" + shape.ID + ".bmp");
                    }
                }
            }
        }
开发者ID:johansonkatherine,项目名称:Aspose_Diagram_NET,代码行数:25,代码来源:Program.cs

示例12: Index

        public ActionResult Index()
        {
            try
            {
                using (Context db = new Context())
                {
                    var _bll = new BLL.EntidadeBLL(db, _idUsuario);
                    var entidade = _bll.FindSingle();

                    if (entidade == null)
                        return View(new RP.Sistema.Web.Models.Entidade.EntidadeVM());

                    var model = RP.Sistema.Web.Models.Entidade.EntidadeVM.E2VM(entidade);
                    if (entidade.imLogo != null)
                    {
                        var stream = new System.IO.MemoryStream(entidade.imLogo);

                        var image = new System.Drawing.Bitmap(stream);
                        var file = Guid.NewGuid() + ".jpg";
                        var fullPath = System.IO.Path.Combine(System.Configuration.ConfigurationManager.AppSettings["PathFile"], file);
                        image.Save(fullPath, System.Drawing.Imaging.ImageFormat.Jpeg);

                        var virtualPath = "/Files/" + file;
                        model.pathLogo = virtualPath;
                    }
                    return View(model);
                }
            }
            catch (Exception ex)
            {
                Util.Entity.ErroLog.Add(ex, Session.SessionID, _idUsuario);
                return RedirectToAction("Index", "Erro", new { area = string.Empty });
            }
        }
开发者ID:odairkreuzberg,项目名称:simetrica,代码行数:34,代码来源:EntidadeController.cs

示例13: Main

        static void Main(string[] args)
        {
            System.Windows.Forms.Application.EnableVisualStyles();
            System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);

            TestApp.Form1 f = new TestApp.Form1();
            f.ShowDialog();
            return;
            string ftest = @"C:\_garbage_\TEST_3_CGM.cgm";
            //ftest = "ICN-S1000DBIKE-AAA-DA51000-0-U8025-00519-A-04-1.CGM";
            //ftest = @"C:\_garbage_\TEST_3_CGM.cgm";
            net.sf.jcgm.core.CGM cgmm = new net.sf.jcgm.core.CGM(
                new java.io.File(ftest));
            cgmm.showCGMCommands(new java.io.PrintStream(@"jcgmout.txt"));
            return;
            CGMSharp.CGMImage img = new CGMSharp.CGMImage(ftest);
            System.Drawing.Bitmap bp = new System.Drawing.Bitmap(img.Size.Width, img.Size.Height);
            System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bp);
            gr.Clear(System.Drawing.Color.White);
            System.Drawing.Size sz = img.Size;
            //string x = ((CGMSharp.CGMPolyLine)img.structuresFocused[8]).Map;
            for (int i = 0; i < img.structuresFocused.Count; i++)
            {
                if (img.structuresFocused[i] is CGMSharp.CGMPolyLine)
                {
                    ((CGMSharp.CGMPolyLine)img.structuresFocused[i]).Draw(gr, sz);
                }
            }
            img.getSize(96);
            //((CGMSharp.CGMPolyLine)img.structuresFocused[8]).Draw(ref gr);
            bp.Save("test.png", System.Drawing.Imaging.ImageFormat.Png);
            System.IO.File.WriteAllText("dump.txt", img.TraceLoading);
            Console.ReadLine();
        }
开发者ID:skipme,项目名称:ComGraMet,代码行数:34,代码来源:Program.cs

示例14: Build

        public static byte[] Build(Xml.FileGroupXml group, string spriteFile)
        {
            var bmps = group.Files.Select(x => new System.Drawing.Bitmap(x.Path));

            var maxWidth = bmps.Max(x => x.Width);
            var totalHeight = bmps.Sum(x => x.Height);

            int top = 0;
            using (var sprite = new System.Drawing.Bitmap(maxWidth, totalHeight))
            using (var mem = new System.IO.MemoryStream())
            using (var g = System.Drawing.Graphics.FromImage(sprite))
            {
                foreach (var bmp in bmps)
                {
                    using (bmp)
                    {
                        g.DrawImage(bmp, new System.Drawing.Rectangle(0, top, bmp.Width, bmp.Height), new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.GraphicsUnit.Pixel);
                        top += bmp.Height;
                    }
                }

                sprite.Save(mem, GetFormat(spriteFile) ?? System.Drawing.Imaging.ImageFormat.Png);
                return mem.ToArray();
            }
        }
开发者ID:cbilson,项目名称:chirpy,代码行数:25,代码来源:ImageSprite.cs

示例15: DrawBinaryImage

        //BinaryWrite方法将一个二进制字符串写入HTTP输出流
        //public void BinaryWrite(byte[] buffer)
        public void DrawBinaryImage()
        {
            //要绘制的字符串
            string word = "5142";

            //设定画布大小,Math.Ceiling向上取整
            int width = int.Parse(Math.Ceiling(word.Length * 20.5).ToString());
            int height = 22;

            //创建一个指定大小的画布
            System.Drawing.Bitmap image = new System.Drawing.Bitmap(width, height);
            //创建一个指定的GDI+绘图图面
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);
            try
            {
                //用白色填充图面
                g.Clear(System.Drawing.Color.White);

                //绘制背景噪音线
                Random r = new Random();
                int x1, x2, y1, y2;
                for (int i = 0; i < 2; i++)
                {
                    x1 = r.Next(image.Width);
                    x2 = r.Next(image.Width);
                    y1 = r.Next(image.Height);
                    y2 = r.Next(image.Height);
                    g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Black), x1, y1, x2, y2);
                }

                //绘制文字
                System.Drawing.Font font = new System.Drawing.Font("Arial", 12, (System.Drawing.FontStyle.Bold));
                System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush
                                                        (new System.Drawing.Rectangle(0, 0, image.Width, image.Height),
                                                        System.Drawing.Color.Blue, System.Drawing.Color.DarkRed, 5.2f, true);
                g.DrawString(word, font, brush, 2, 2);

                //绘制前景噪点
                int x, y;
                for (int i = 0; i < 100; i++)
                {
                    x = r.Next(image.Width);
                    y = r.Next(image.Height);
                    image.SetPixel(x, y, System.Drawing.Color.FromArgb(r.Next()));
                }

                //绘制边框
                g.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
                System.IO.MemoryStream ms = new MemoryStream();
                image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
                Response.ClearContent();
                Response.ContentType = "image/Gif";
                Response.BinaryWrite(ms.ToArray());
            }
            catch (Exception)
            {
                g.Dispose();
                image.Dispose();
            }
        }
开发者ID:ZhuangChen,项目名称:CSharpBasicTraining,代码行数:62,代码来源:04Built-in_Object.aspx.cs


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