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


C# Bitmap.Save方法代码示例

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


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

示例1: RegisterCommands

        private void RegisterCommands(ImagePresentationViewModel viewModel)
        {
            viewModel.SaveCommand = UICommand.Regular(() =>
            {
                var dialog = new SaveFileDialog
                {
                    Filter = "PNG Image|*.png|Bitmap Image|*.bmp",
                    InitialDirectory = Settings.Instance.DefaultPath
                };
                var dialogResult = dialog.ShowDialog();
                if (dialogResult.HasValue && dialogResult.Value)
                {
                    var tmp = viewModel.Image;
                    using (var bmp = new Bitmap(tmp))
                    {
                        if (File.Exists(dialog.FileName))
                        {
                            File.Delete(dialog.FileName);
                        }

                        switch (dialog.FilterIndex)
                        {
                            case 0:
                                bmp.Save(dialog.FileName, ImageFormat.Png);
                                break;
                            case 1:
                                bmp.Save(dialog.FileName, ImageFormat.Bmp);
                                break;
                        }
                    }
                }
            });
        }
开发者ID:PictoCrypt,项目名称:ImageTools,代码行数:33,代码来源:ImagePresentationController.cs

示例2: TakeSnapshot

 private void TakeSnapshot()
 {
     var stamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm");
     Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
     Graphics.FromImage(bmp).CopyFromScreen(0, 0, 0, 0, bmp.Size);
     bmp.Save(@"C:\Temp\" + stamp + ".jpg", ImageFormat.Jpeg);
 }
开发者ID:FrontFabric,项目名称:Link,代码行数:7,代码来源:FrmMain.cs

示例3: CaptureScreen

 /// <summary>
 /// Capture the screen and saves as image
 /// </summary>
 /// <returns> The creted image filename</returns>
 public string CaptureScreen()
 {
     date = DateTime.Now.ToString("ddMMyyyy");
     string fileName = DateTime.Now.ToString("hhmmss");
     int ix, iy, iw, ih;
     ix = Convert.ToInt32(Screen.PrimaryScreen.Bounds.X);
     iy = Convert.ToInt32(Screen.PrimaryScreen.Bounds.Y);
     iw = Convert.ToInt32(Screen.PrimaryScreen.Bounds.Width);
     ih = Convert.ToInt32(Screen.PrimaryScreen.Bounds.Height);
     Bitmap image = new Bitmap(iw, ih,
            System.Drawing.Imaging.PixelFormat.Format32bppArgb);
     Graphics g = Graphics.FromImage(image);
     g.CopyFromScreen(ix, iy, ix, iy,
              new System.Drawing.Size(iw, ih),
              CopyPixelOperation.SourceCopy);
     try
     {
         if (Directory.Exists(GlobalContants.screenshotFolderPath))
             image.Save(Path.Combine(GlobalContants.screenshotFolderPath, fileName + ".jpeg"), ImageFormat.Jpeg);
         else
         {
             Directory.CreateDirectory(GlobalContants.screenshotFolderPath);
             image.Save(Path.Combine(GlobalContants.screenshotFolderPath, fileName + ".jpeg"), ImageFormat.Jpeg);
         }
     }
     catch (Exception) { }
     return fileName;
 }
开发者ID:niv7488,项目名称:final-project---class-board,代码行数:32,代码来源:ImageCaptureManager.cs

示例4: button2_Click

 private void button2_Click(object sender, EventArgs e)
 {
     Bitmap[] bimp = new Bitmap[openFileDialog1.SafeFileNames.Length];
     for (int i = 0; i < bimp.Length; i++)
     {
         bimp[i] = new Bitmap(openFileDialog1.FileNames[i]);
     }
     Bitmap resutl = new Bitmap(bimp[0].Width * bimp.Length, bimp[1].Height);
     Graphics q = Graphics.FromImage(resutl);
      //   q.ScaleTransform(0.5f, 0.5f);
     for (int i = 0; i < bimp.Length; i++)
     {
         q.DrawImage((Image)bimp[i], new Point(bimp[i].Width * i, 0));
     }
     q.Flush();
     if ((!checkBox1.Checked) && (saveFileDialog1.FileName != null))
     {
         resutl.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Png);
     }
     else
     {
         resutl.Save(openFileDialog1.FileNames[0] + "RESULT.png", System.Drawing.Imaging.ImageFormat.Png);
     }
     MessageBox.Show("Готово");
 }
开发者ID:Spyman,项目名称:Game,代码行数:25,代码来源:Form1.cs

示例5: GetImageStream

        private static void GetImageStream( ImageFormat outputFormat, Bitmap bitmap, MemoryStream ms )
        {
            var imageEncoders = ImageCodecInfo.GetImageEncoders ();
            var encoderParameters = new EncoderParameters (1);
            encoderParameters.Param[0] = new EncoderParameter (Encoder.Quality, 100L);

            if (ImageFormat.Jpeg.Equals (outputFormat))
            {
                bitmap.Save (ms, imageEncoders[1], encoderParameters);
            }
            else if (ImageFormat.Png.Equals (outputFormat))
            {
                bitmap.Save (ms, imageEncoders[4], encoderParameters);
            }
            else if (ImageFormat.Gif.Equals (outputFormat))
            {
                var quantizer = new OctreeQuantizer (255, 8);
                using (var quantized = quantizer.Quantize (bitmap))
                {
                    quantized.Save (ms, imageEncoders[2], encoderParameters);
                }
            }
            else if (ImageFormat.Bmp.Equals (outputFormat))
            {
                bitmap.Save (ms, imageEncoders[0], encoderParameters);
            }
            else
            {
                bitmap.Save (ms, outputFormat);
            }
        }
开发者ID:andriybilas,项目名称:MasterM,代码行数:31,代码来源:ScalableImageUtility.cs

示例6: timer1_Tick

 private void timer1_Tick(object sender, EventArgs e)
 {
     if (Clipboard.ContainsImage() & System.IO.Directory.Exists(textBox1.Text))
     {
         frameNr++;
         Bitmap scr = new Bitmap(Clipboard.GetImage());
         if (checkBox1.Checked)
         {
             Graphics g = Graphics.FromImage(scr);
             Rectangle re = new Rectangle();
             re.X = MousePosition.X - 10;
             re.Y = MousePosition.Y - 10;
             re.Size = Cursor.Size;
             Cursor.Draw(g, re);
         }
         if (!System.IO.Directory.Exists(textBox1.Text + "\\Pictures"))
             System.IO.Directory.CreateDirectory(textBox1.Text + "\\Pictures");
         string fn = frameNr.ToString();
         while (fn.Length < 3)
             fn = "0" + fn;
         if (radioButton3.Checked)
             scr.Save(textBox1.Text + "\\Pictures\\" + fn + radioButton3.Text, System.Drawing.Imaging.ImageFormat.Bmp);
         else if (radioButton1.Checked)
             scr.Save(textBox1.Text + "\\Pictures\\" + fn + radioButton1.Text, System.Drawing.Imaging.ImageFormat.Jpeg);
         else if (radioButton2.Checked)
             scr.Save(textBox1.Text + "\\Pictures\\" + fn + radioButton2.Text, System.Drawing.Imaging.ImageFormat.Png);
         Clipboard.Clear();
         Application.DoEvents();
     }
 }
开发者ID:d-kakhiani,项目名称:C_Sharp,代码行数:30,代码来源:Form1.cs

示例7: saveImage2File

 private void saveImage2File(Bitmap screenshot, string fileName)
 {
     if (String.IsNullOrEmpty(fileName))
         return;
     string ext = Path.GetExtension(fileName);
     switch (ext.ToLower())
     {
         case ".png":
             screenshot.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
             break;
         case ".jpg":
         case ".jpeg":
             screenshot.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
             break;
         case ".tiff":
             screenshot.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
             break;
         case ".bmp":
             screenshot.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
             break;
         case ".gif":
             screenshot.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
             break;
     }
 }
开发者ID:TownSuite,项目名称:cobra,代码行数:25,代码来源:Screenshot.cs

示例8: BmpSave

        public static void BmpSave(Bitmap newBmp, string outFile)
        {
            EncoderParameters encoderParams = new EncoderParameters();
            long[] quality = new long[1];
            quality[0] = 100;

            EncoderParameter encoderParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
            encoderParams.Param[0] = encoderParam;

            //获得包含有关内置图像编码解码器的信息的ImageCodecInfo 对象。
            ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
            ImageCodecInfo jpegICI = null;
            for (int x = 0; x < arrayICI.Length; x++)
            {
                if (arrayICI[x].FormatDescription.Equals("JPEG"))
                {
                    jpegICI = arrayICI[x];//设置JPEG编码
                    break;
                }
            }

            if (jpegICI != null)
            {
                newBmp.Save(outFile, jpegICI, encoderParams);
            }
            else
            {
                newBmp.Save(outFile, ImageFormat.Jpeg);
            }
            newBmp.Dispose();
        }
开发者ID:rew170,项目名称:soomecode,代码行数:31,代码来源:ImageHandle.cs

示例9: switch

        void iDS.Save(Bitmap b, string fileName)
        {
            var formatFile = fileName;
            formatFile = formatFile.Substring(formatFile.Length - 3);

            switch (formatFile)
            {
                case "bmp":
                    b.Save(fileName, System.Drawing.Imaging.ImageFormat.Bmp);
                    break;
                case "jepg":
                case "jpg":
                    b.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                    break;
                case "png":
                    b.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
                    break;
                case "gif":
                    b.Save(fileName, System.Drawing.Imaging.ImageFormat.Gif);
                    break;
                case "tiff":
                    b.Save(fileName, System.Drawing.Imaging.ImageFormat.Tiff);
                    break;
            }           
        }
开发者ID:Igor-Rashyn,项目名称:exercises,代码行数:25,代码来源:DS_Standard.cs

示例10: Form1_Load

        private void Form1_Load(object sender, EventArgs e)
        {
            Bitmap bmpImage = new Bitmap("sagarmatha.jpg");
            pictureBox1.Image = new Bitmap("sagarmatha.jpg");
            int width = bmpImage.Width;
            int height = bmpImage.Height;
            for (int j = 0; j< height; j++)
            {
                for (int i = 0; i< width; i++)
                {
                    Color pixel1 = bmpImage.GetPixel(i, j);
                    Color newcolor = Color.FromArgb(pixel1.A, pixel1.R, 0, 0);
                    bmpImage.SetPixel(i, j, newcolor);
                }

                bmpImage.Save("output_redscale.jpg");
                }
            for (int j = 0; j < height; j++)
            {
                for (int i = 0; i < width; i++)
                {
                    Color pixel1 = bmpImage.GetPixel(i, j);
                    int average = (pixel1.R + pixel1.G + pixel1.B) / 3;
                    Color newcolor = Color.FromArgb(0, average, average, average);
                    bmpImage.SetPixel(i, j, newcolor);
                }
                bmpImage.Save("output_grayscale.jpg");
                }
            pictureBox2.Image = new Bitmap("output_redscale.jpg");
            pictureBox3.Image = new Bitmap("output_grayscale.jpg");
        }
开发者ID:sadipgiri,项目名称:Sadip1,代码行数:31,代码来源:Form1.cs

示例11: Main

        static void Main(string[] args)
        {
            FileSize("noname.jpg");
            var image = new Bitmap("noname.jpg");

            var jgpEncoder = GetEncoder(ImageFormat.Jpeg);
            var myEncoder = Encoder.Quality;

            var myEncoderParameters = new EncoderParameters(1);
            var myEncoderParameter = new EncoderParameter(myEncoder, 50L);
            myEncoderParameters.Param[0] = myEncoderParameter;
            image.Save(@"TestPhotoQualityFifty.jpg", jgpEncoder, myEncoderParameters);
            FileSize("TestPhotoQualityFifty.jpg");

            myEncoderParameter = new EncoderParameter(myEncoder, 100L);
            myEncoderParameters.Param[0] = myEncoderParameter;
            image.Save(@"TestPhotoQualityHundred.jpg", jgpEncoder, myEncoderParameters);
            FileSize("TestPhotoQualityHundred.jpg");

            myEncoderParameter = new EncoderParameter(myEncoder, 70L);
            myEncoderParameters.Param[0] = myEncoderParameter;
            image.Save(@"TestPhotoQualityZero.jpg", jgpEncoder, myEncoderParameters);
            FileSize("TestPhotoQualityZero.jpg");

            Console.ReadLine();
        }
开发者ID:kurniawirawan,项目名称:ImageCompression,代码行数:26,代码来源:Program.cs

示例12: LoadImage

        private static void LoadImage(HttpPostedFileBase file, string filename, string folder)
        {
            string largePhotoFullName = Path.Combine(HttpContext.Current.Server.MapPath("~/Content"),
                                                  folder, "FullSize", file.FileName);
            string smallPhotoFullName = Path.Combine(HttpContext.Current.Server.MapPath("~/Content"),
                                                    folder, "Small", file.FileName);

            if (!String.IsNullOrEmpty(file.FileName))
            {
                file.SaveAs(largePhotoFullName);
                try
                {
                    //изменяем размер изображения и перезаписываем на диск
                    var imageLogo = System.Drawing.Image.FromFile(largePhotoFullName);
                    var bitmapLogo = new Bitmap(imageLogo);
                    imageLogo.Dispose();
                    int newWidth = 500;
                    bitmapLogo = Resize(bitmapLogo, newWidth, bitmapLogo.Height * newWidth / bitmapLogo.Width);
                    bitmapLogo.Save(largePhotoFullName);
                    newWidth = 100;
                    bitmapLogo = Resize(bitmapLogo, newWidth, bitmapLogo.Height * newWidth / bitmapLogo.Width);
                    bitmapLogo.Save(smallPhotoFullName);

                    //пересохраняем с нужным нам названием
                    File.Move(largePhotoFullName, HttpContext.Current.Server.MapPath("~/Content/" + folder + "/FullSize/") + filename);
                    File.Move(smallPhotoFullName, HttpContext.Current.Server.MapPath("~/Content/" + folder + "/Small/") + filename);
                }
                catch //пользователь загрузил не изображение (ну или другая ошибка)
                {
                    File.Delete(largePhotoFullName);
                    File.Delete(smallPhotoFullName);
                }
            }
        }
开发者ID:JIy3AHKO,项目名称:MvcApplication1,代码行数:34,代码来源:ImageHelper.cs

示例13: SizeScaling

 public Image SizeScaling(Bitmap image, int width, int height, bool distorted)
 {
     try
     {
         double realRatio = ((double) image.Height)/((double) image.Width);
         if (width != 0 & height != 0)
         {
             if (distorted) return image.GetThumbnailImage(width, height, ThumbnailCallback, IntPtr.Zero);
             var heightAfterRatio = (int) Math.Floor(realRatio*width);
             var widthAfterRatio = (int) Math.Floor(height/realRatio);
             using (var mem1 = new MemoryStream())
             {
                 using (var mem2 = new MemoryStream())
                 {
                     image.Save(mem1, ImageFormat.Tiff);
                     ImageBuilder.Current.Build(new ImageJob(mem1, mem2,
                         new ResizeSettings(widthAfterRatio, heightAfterRatio, FitMode.None, null)));
                     return Image.FromStream(mem2);
                 }
             }
             //return image.GetThumbnailImage(widthAfterRatio, heightAfterRatio, ThumbnailCallback, IntPtr.Zero);
         }
         if (width != 0)
         {
             var heightAfterRatio = (int) Math.Floor(realRatio*width);
             using (var mem1 = new MemoryStream())
             {
                 using (var mem2 = new MemoryStream())
                 {
                     image.Save(mem1, ImageFormat.Jpeg);
                     ImageBuilder.Current.Build(new ImageJob(mem1, mem2,
                         new ResizeSettings(width, heightAfterRatio, FitMode.None, null)));
                     return Image.FromStream(mem2);
                 }
             }
             //return image.GetThumbnailImage(width, heightAfterRatio, ThumbnailCallback, IntPtr.Zero);
         }
         if (height != 0)
         {
             var widthAfterRatio = (int) Math.Floor(height/realRatio);
             using (var mem1 = new MemoryStream())
             {
                 using (var mem2 = new MemoryStream())
                 {
                     image.Save(mem1, ImageFormat.Jpeg);
                     ImageBuilder.Current.Build(new ImageJob(mem1, mem2,
                         new ResizeSettings(widthAfterRatio, height, FitMode.None, null)));
                     return Image.FromStream(mem2);
                 }
             }
             //return image.GetThumbnailImage(widthAfterRatio, height, ThumbnailCallback, IntPtr.Zero);
         }
         return image;
     }
     catch (Exception ex)
     {
         return image;
     }
 }
开发者ID:CheViana,项目名称:ImageServer,代码行数:59,代码来源:ScalingProcessor.cs

示例14: GenThumbnail

 public static void GenThumbnail(Image imageFrom, string pathImageTo, int width, int height,string fileExt)
 {
     if (imageFrom == null)
     {
         return;
     }
     // 源图宽度及高度
     int imageFromWidth = imageFrom.Width;
     int imageFromHeight = imageFrom.Height;
     // 生成的缩略图实际宽度及高度
     int bitmapWidth = width;
     int bitmapHeight = height;
     // 生成的缩略图在上述"画布"上的位置
     int X = 0;
     int Y = 0;
     // 根据源图及欲生成的缩略图尺寸,计算缩略图的实际尺寸及其在"画布"上的位置
     if (bitmapHeight * imageFromWidth > bitmapWidth * imageFromHeight)
     {
         bitmapHeight = imageFromHeight * width / imageFromWidth;
         Y = (height - bitmapHeight) / 2;
     }
     else
     {
         bitmapWidth = imageFromWidth * height / imageFromHeight;
         X = (width - bitmapWidth) / 2;
     }
     // 创建画布
     Bitmap bmp = new Bitmap(width, height);
     Graphics g = Graphics.FromImage(bmp);
     // 用白色清空
     g.Clear(Color.White);
     // 指定高质量的双三次插值法。执行预筛选以确保高质量的收缩。此模式可产生质量最高的转换图像。
     g.InterpolationMode = InterpolationMode.HighQualityBicubic;
     // 指定高质量、低速度呈现。
     g.SmoothingMode = SmoothingMode.HighQuality;
     // 在指定位置并且按指定大小绘制指定的 Image 的指定部分。
     g.DrawImage(imageFrom, new Rectangle(X, Y, bitmapWidth, bitmapHeight), new Rectangle(0, 0, imageFromWidth, imageFromHeight), GraphicsUnit.Pixel);
     try
     {
         //经测试 .jpg 格式缩略图大小与质量等最优
         if (fileExt == ".png")
         {
             bmp.Save(pathImageTo, ImageFormat.Png);
         }
         else
         {
             bmp.Save(pathImageTo, ImageFormat.Jpeg);
         }
     }
     catch
     {
     }
     finally
     {
         //显示释放资源
         bmp.Dispose();
         g.Dispose();
     }
 }
开发者ID:XingsiStudio,项目名称:ArtGallery,代码行数:59,代码来源:UploadFileHandler.ashx.cs

示例15: CreateVerifyImg

        /// <summary>
        /// 生成验证码图片
        /// </summary>
        private void CreateVerifyImg()
        {
            string vMapPath = string.Empty;                     //验证码路径
            Random rnd = new Random();                          //随机发生器
            Bitmap imgTemp = null;                              //验证码图片
            Graphics g = null;                                  //图形库函数
            SolidBrush blueBrush = null;                        //缓冲区

            //暂时注销
            //string rndstr = rnd.Next(1111, 9999).ToString();    //验证码

            string rndstr = string.Empty;    //验证码
            //测试时,将验证码统一设为0000
            rndstr = rnd.Next(1111, 9999).ToString();

            int totalwidth = 0;                                 //验证码图片总宽度
            int totalheight = 0;                                //验证码图片总高度

            //给缓存添加验证码
            SetVerifyCookie(rndstr);

            //生成验证码图片文件
            System.Drawing.Image ReducedImage1 = System.Drawing.Image.FromFile(Server.MapPath("images/yzm/" + rndstr.Substring(0, 1) + ".gif"));
            System.Drawing.Image ReducedImage2 = System.Drawing.Image.FromFile(Server.MapPath("images/yzm/" + rndstr.Substring(1, 1) + ".gif"));
            System.Drawing.Image ReducedImage3 = System.Drawing.Image.FromFile(Server.MapPath("images/yzm/" + rndstr.Substring(2, 1) + ".gif"));
            System.Drawing.Image ReducedImage4 = System.Drawing.Image.FromFile(Server.MapPath("images/yzm/" + rndstr.Substring(3, 1) + ".gif"));

            totalwidth = 52;
            totalheight = 17;
            imgTemp = new Bitmap(totalwidth, totalheight);
            g = Graphics.FromImage(imgTemp);
            blueBrush = new SolidBrush(Color.Black);
            g.FillRectangle(blueBrush, 0, 0, totalwidth, totalheight);
            g.DrawImage(ReducedImage1, 0, 0);
            g.DrawImage(ReducedImage2, ReducedImage1.Width, 0);
            g.DrawImage(ReducedImage3, ReducedImage1.Width + ReducedImage2.Width, 0);
            g.DrawImage(ReducedImage4, ReducedImage1.Width + ReducedImage2.Width + ReducedImage3.Width, 0);

            vMapPath = Server.MapPath("images/yzm/verify.gif");
            try
            {
                imgTemp.Save(vMapPath);
            }
            catch
            {
                //utils.JsAlert("创建验证验错误!");
            }

            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            imgTemp.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
            Response.ClearContent();
            Response.ContentType = "image/Gif";
            Response.BinaryWrite(ms.ToArray());

            blueBrush.Dispose();
            g.Dispose();
            imgTemp.Dispose();
        }
开发者ID:scutsky,项目名称:iyuewan,代码行数:61,代码来源:verifyimg.aspx.cs


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