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


C# Image.Save方法代码示例

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


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

示例1: Save

        public void Save(string filename, Image image)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                string ext = R.Util.Str.getFileExtension(filename);
                switch (ext)
                {
                    case "jpg":
                    case "jpeg":
                        JpegEncoder jpgencoder = new JpegEncoder();
                        image.Save(ms, jpgencoder);
                        break;

                    case "png":
                        PngEncoder pngencoder = new PngEncoder();
                        image.Save(ms, pngencoder);
                        break;

                }
                //save to disk
                using (FileStream fs = new FileStream(R.Server.MapPath(filename), FileMode.Create))
                {
                    ms.Position = 0;
                    ms.WriteTo(fs);
                    fs.Dispose();
                }
                ms.Dispose();
            }
        }
开发者ID:nhtera,项目名称:Home,代码行数:29,代码来源:Images.cs

示例2: ImageToString

	static string ImageToString (Image img)
	{
		MemoryStream stream = new MemoryStream ();
		img.Save (stream, ImageFormat.Png);
		stream.Position = 0;
		int LengthOfBuffer = (int) stream.Length;
		byte [] buff = new byte [LengthOfBuffer];
		stream.Read (buff, 0, LengthOfBuffer);
		return Convert.ToBase64String (buff);
	}
开发者ID:mono,项目名称:gert,代码行数:10,代码来源:test.cs

示例3: Start

    // Use this for initialization
    void Start()
    {
        Image<Bgr, byte> picture = new Image<Bgr, byte> ("/Users/jacobhanshaw/Desktop/picture1.jpg");
        Bgr myWhiteColor = new Bgr (255, 255, 255);
        for (int i=0; i<200; i++) {
            picture [0, i] = myWhiteColor;
        }
        picture.Save ("/Users/jacobhanshaw/Desktop/picture2.jpg");

        //FaceRecognizer faceRec = new FaceRecognizer();
    }
开发者ID:jacobhanshaw,项目名称:OpenCVUnity-Emgu-Mac,代码行数:12,代码来源:OpenCVTest.cs

示例4: AddFrame

 /// <summary>
 /// Adds a frame to this animation.
 /// </summary>
 /// <param name="img">The image to add</param>
 /// <param name="x">The positioning x offset this image should be displayed at.</param>
 /// <param name="y">The positioning y offset this image should be displayed at.</param>
 public void AddFrame(Image img, int x = 0, int y = 0, TimeSpan? frameDelay = null)
 {
     using (var gifStream = new MemoryStream())
     {
         img.Save(gifStream, ImageFormat.Gif);
         if (_isFirstImage) // Steal the global color table info
         {
             InitHeader(gifStream, img.Width, img.Height);
         }
         WriteGraphicControlBlock(gifStream, frameDelay.GetValueOrDefault(FrameDelay));
         WriteImageBlock(gifStream, !_isFirstImage, x, y, img.Width, img.Height);
     }
     _isFirstImage = false;
 }
开发者ID:oduslabs,项目名称:Spreeder,代码行数:20,代码来源:GifEncode.cs

示例5: SaveJpeg

    public static void SaveJpeg(string path, Image image, int quality)
    {
        if ((quality < 0) || (quality > 100))
            {
                string error = string.Format("Jpeg image quality must be between 0 and 100, with 100 being the highest quality.  A value of {0} was specified.", quality);
                throw new ArgumentOutOfRangeException(error);
            }

            EncoderParameter qualityParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)quality);
            ImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg");

            EncoderParameters encoderParams = new EncoderParameters(1);
            encoderParams.Param[0] = qualityParam;
            image.Save(path, jpegCodec, encoderParams);
    }
开发者ID:SeanYuan,项目名称:ImageUtilities,代码行数:15,代码来源:ImageUtilities.cs

示例6: SaveImage

    public static void SaveImage(Image img)
    {
        try
        {
            using (var sfd = new SaveFileDialog { Title = "Redact | Save Image", Filter = "PNG Files (.png) | *.png" })
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    img.Save(sfd.FileName, ImageFormat.Png);

                    MessageBox.Show("Image successfully saved to " + sfd.FileName, "Redact", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
        }
        catch
        {
            MessageBox.Show("An error occured when attempting to save.", "Redact", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
开发者ID:PavilionVI,项目名称:Redact,代码行数:17,代码来源:Export.cs

示例7: SaveImage

 /// <summary>
 /// Окно сохранения изображений
 /// </summary>
 /// <param name="image"></param>
 public static void SaveImage(Image image)
 {
     SaveFileDialog sfd = new SaveFileDialog();
     sfd.Filter = "Images|*.png;*.bmp;*.jpg";
     ImageFormat format = ImageFormat.Png;
     if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         string ext = System.IO.Path.GetExtension(sfd.FileName);
         switch (ext)
         {
             case ".jpg":
                 format = ImageFormat.Jpeg;
                 break;
             case ".bmp":
                 format = ImageFormat.Bmp;
                 break;
         }
         image.Save(sfd.FileName, format);
     }
 }
开发者ID:xsimbvx,项目名称:IRIntegration,代码行数:24,代码来源:Form1.cs

示例8: SaveImage

 static void SaveImage(Image img, Stream outputStream, ImageFormat fmt)
 {
     if (fmt==ImageFormat.Jpeg) {
         // for jpeg, lets set 90% quality explicitely
         ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
         var jpegCodec = codecs.Where( c=> c.FormatID == ImageFormat.Jpeg.Guid ).FirstOrDefault();
         if (jpegCodec!=null) {
             var jpegEncoderParameters = new EncoderParameters(1);
             jpegEncoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 90L);
              img.Save(outputStream, jpegCodec, jpegEncoderParameters);
             return;
         }
     }
      img.Save(outputStream, fmt);
 }
开发者ID:Mariamfelicia,项目名称:nreco,代码行数:15,代码来源:ImageHelper.cs

示例9: HashFromImage

    string HashFromImage(Image img)
    {
        string hash;
        byte[] bytes = null;

        using (MemoryStream ms = new MemoryStream()) {
            img.Save (ms, img.RawFormat);
            bytes = ms.ToArray ();
        }

        using (SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider()) {
            bytes = sha1.ComputeHash (bytes);
            hash = BitConverter.ToString (bytes).Replace ("-", "").ToLower ();
        }

        return hash;
    }
开发者ID:ezavaleta,项目名称:toys,代码行数:17,代码来源:Main.cs

示例10: saveImageToLocation

    // Saves the image to specific location, save location includes filename
    private static void saveImageToLocation(Image theImage, string saveLocation)
    {
        // Strip the file from the end of the dir
        string saveFolder = Path.GetDirectoryName(saveLocation);
        if (!Directory.Exists(saveFolder))
        {
            Directory.CreateDirectory(saveFolder);
        }

        ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg);

        // Create an Encoder object based on the GUID
        // for the Quality parameter category.
        System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;

        // Create an EncoderParameters object.
        // An EncoderParameters object has an array of EncoderParameter
        // objects. In this case, there is only one
        // EncoderParameter object in the array.
        EncoderParameters myEncoderParameters = new EncoderParameters(1);
        EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 90L);
        myEncoderParameters.Param[0] = myEncoderParameter;

        // Save to disk
        theImage.Save(saveLocation, jgpEncoder, myEncoderParameters);
    }
开发者ID:rafikramsis,项目名称:Test,代码行数:27,代码来源:ImageResizer.cs

示例11: CompositionTarget_Rendering

        private async void CompositionTarget_Rendering(object sender, EventArgs e)
        {
            currentFrame = grabber.QueryFrame().Resize(320, 240, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);            

            if (_rects == null || _rects.Length == 0)
            {
                gray = currentFrame.Convert<Gray, Byte>();

                var size = new System.Drawing.Size(20, 20);
                var window = new System.Drawing.Size(grabber.Width, grabber.Height);
                _rects = _faceClassifier.DetectMultiScale(gray, 1.2, 10, size, window);

                _vmodel.PersonRecognized = _rects.Length;

                if (_rects.Length > 0)
                {                    
                    /*
                    1) save the current rendered faces
                    2) upload the current frame to detect
                    3) verify with trained images
                    */
                    string snapshot = CommonData.TARGET_SNAPSHOT_PAHT + DateTime.Now.ToString().Replace('/', '_').Replace(':', '_') + "." + CommonData.IMAGE_EXT;
                    currentFrame.Save(snapshot);

                    _progressRec.IsIndeterminate = false;
                    _progressRec.IsEnabled = true;

                    var fr = await UploadAndDetectFaces(snapshot);

                    //detect all faces
                    foreach (var trainedFile in CommonData.ImageFiles)
                    {
                        var fileStream = File.OpenRead(trainedFile);
                        var f = await faceServiceClient.DetectAsync(fileStream);
                        _trainedFacesAI.AddRange(f.ToList());
                    }

                    int i = 0;
                    //verify reading from all db
                    foreach (var face in _detectedFaceFromAI)
                    {
                        foreach (var secondFace in _trainedFacesAI)
                        {
                            var res = await faceServiceClient.VerifyAsync(face.FaceId, secondFace.FaceId);

                            PictureModel _model = new PictureModel();
                            _model.ImgSource = new WriteableBitmap(new BitmapImage(new Uri(CommonData.ImageFiles[i])));
                            _model.AIID = face.FaceId.ToString();

                            if (res.IsIdentical)
                            {
                                _model.Name = CommonData.Names[i];
                                _model.ID = i;
                                _model.IsVerified = true;
                                _model.Confidence = res.Confidence;
                            }
                            else
                            {
                                _model.Name = "Unkonwn";
                                _model.IsVerified = false;
                                _model.Confidence = res.Confidence;
                            }

                            var c = _vmodel.Pictures.Where(x => x.AIID == _model.AIID).Count();
                            if (!(c > 0))//adds only if is not already added
                            {
                                _vmodel.Pictures.Add(_model);
                            }

                            i++;
                        }
                    }

                    _progressRec.IsIndeterminate = false;
                    _progressRec.IsEnabled = false;
                }                
            }            

            _imgSource.Source = ImageHelper.ToBitmapSource(currentFrame);
        }
开发者ID:davluzzu,项目名称:FaceAuth,代码行数:80,代码来源:AIRecognition.xaml.cs

示例12: ImageToByte2

 public static byte[] ImageToByte2(Image img)
 {
     byte[] byteArray = new byte[0];
     using (MemoryStream stream = new MemoryStream())
     {
         img.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
         stream.Close();
         byteArray = stream.ToArray();
     }
     return byteArray;
 }
开发者ID:radiopaedia,项目名称:uploader-agent,代码行数:11,代码来源:AIMG.cs

示例13: ConvertToString

 public string ConvertToString(Image value)
 {
     MemoryStream imageStream = new MemoryStream();
     EncoderParameters pams = new EncoderParameters(1);
     pams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L);
     value.Save(imageStream, VideoEncoder.GetEncoder(ImageFormat.Jpeg), pams);
     return Convert.ToBase64String(imageStream.ToArray());
 }
开发者ID:byteit101,项目名称:ZomB-Dashboard-System,代码行数:8,代码来源:VideoStreamSaver.cs

示例14: ImageToBinary

 internal static byte[] ImageToBinary( Image NewImage)
 {
     try
     {
         byte[] ImageByteArray = null;
         MemoryStream ReadImage = new MemoryStream();
         NewImage.Save(ReadImage, System.Drawing.Imaging.ImageFormat.Png);
         ImageByteArray = new byte[Convert.ToInt32(ReadImage.Length - 1) + 1];
         ReadImage.Position = 0;
         ReadImage.Read(ImageByteArray, 0, Convert.ToInt32(ReadImage.Length));
         return ImageByteArray;
     }catch(Exception ex){
         MessageBox.Show(ex.Message);
         return null;
     }
 }
开发者ID:soungeng,项目名称:TRUE_POS,代码行数:16,代码来源:Program.cs

示例15: ImageToBase64

    public string ImageToBase64(Image image, System.Drawing.Imaging.ImageFormat format)
    {
        using (MemoryStream ms = new MemoryStream())
        {
            // Convert Image to byte[]
            image.Save(ms, format);
            byte[] imageBytes = ms.ToArray();

            // Convert byte[] to Base64 String
            string base64String = Convert.ToBase64String(imageBytes);
            return base64String;
        }
    }
开发者ID:scet1043,项目名称:1043_MyELib,代码行数:13,代码来源:Service.cs


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