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


C# ImageConverter.ConvertTo方法代码示例

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


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

示例1: ImageToByte

        public static byte[] ImageToByte(Image img)
        {
            ImageConverter converter = new ImageConverter();
            MessageBox.Show("metodo ImageToByte:" + "" + (byte[])converter.ConvertTo(img, typeof(byte[])));

            return (byte[])converter.ConvertTo(img, typeof(byte[]));
        }
开发者ID:josehmaza,项目名称:MIREPOSICAPJH,代码行数:7,代码来源:frmRegistrarPersonal.cs

示例2: Compare

    public static CompareResult Compare(Bitmap bmp1, Bitmap bmp2)
    {
        CompareResult cr = CompareResult.ciCompareOk;

        //Test to see if we have the same size of image
        if (bmp1.Size != bmp2.Size)
        {
            cr = CompareResult.ciSizeMismatch;
        }
        else
        {
            //Convert each image to a byte array
            System.Drawing.ImageConverter ic = new System.Drawing.ImageConverter();
            byte[] btImage1 = new byte[1];
            btImage1 = (byte[])ic.ConvertTo(bmp1, btImage1.GetType());
            byte[] btImage2 = new byte[1];
            btImage2 = (byte[])ic.ConvertTo(bmp2, btImage2.GetType());

            //Compute a hash for each image
            SHA256Managed shaM = new SHA256Managed();
            byte[] hash1 = shaM.ComputeHash(btImage1);
            byte[] hash2 = shaM.ComputeHash(btImage2);

            //Compare the hash values
            for (int i = 0; i < hash1.Length && i < hash2.Length && cr == CompareResult.ciCompareOk; i++)
            {
                if (hash1[i] != hash2[i])
                    cr = CompareResult.ciPixelMismatch;
            }
            shaM.Clear();
        }

        return cr;
    }
开发者ID:AlinRaju,项目名称:ImageComparison,代码行数:34,代码来源:Class1.cs

示例3: Compare

        public static CompareResult Compare(Bitmap bmp1, Bitmap bmp2)
        {
            CompareResult cr = CompareResult.ciCompareOk;
            // removed the size test - all images compared will be the same size! (32-bit x height x width)

            //Convert each image to a byte array
            System.Drawing.ImageConverter ic =
                   new System.Drawing.ImageConverter();
            byte[] btImage1 = new byte[1];
            btImage1 = (byte[])ic.ConvertTo(bmp1, btImage1.GetType());
            byte[] btImage2 = new byte[1];
            btImage2 = (byte[])ic.ConvertTo(bmp2, btImage2.GetType());

            //Compute a hash for each image
            //Pointless to use SHA256 when MD5 is good enough. Speed advantage is worth it here.
            MD5 shaM = new MD5CryptoServiceProvider();
            byte[] hash1 = shaM.ComputeHash(btImage1);
            byte[] hash2 = shaM.ComputeHash(btImage2);

            //Compare the hash values
            for (int i = 0; i < hash1.Length && i < hash2.Length && cr == CompareResult.ciCompareOk; i++)
            {
                if (hash1[i] != hash2[i])
                    cr = CompareResult.ciPixelMismatch;
            }

            return cr;
        } // end function
开发者ID:nelsestu,项目名称:a-vnc,代码行数:28,代码来源:CompareImages.cs

示例4: TestUploadMultiplePhotoMemories

        public void TestUploadMultiplePhotoMemories()
        {
            var converter = new ImageConverter();
            var bytes1 = (Byte[])converter.ConvertTo(TestBacking.GetCreatePhoto(), typeof(Byte[]));
            var bytes2 = (Byte[])converter.ConvertTo(TestBacking.GetCreatePhoto(), typeof(Byte[]));
            var dataSource1 = new BasicDataSource(Guid.NewGuid().ToString("n") + ".jpg", "image/jpeg", bytes1);
            var dataSource2 = new BasicDataSource(Guid.NewGuid().ToString("n") + ".jpg", "image/jpeg", bytes2);
            var description = new SourceDescription().SetTitle(new TextValue().SetValue("PersonImage")).SetCitation("Citation for PersonImage");
            var artifacts = new List<IDataSource>();

            artifacts.Add(dataSource1);
            artifacts.Add(dataSource2);

            IRestRequest request = new RedirectableRestRequest()
                .AddHeader("Authorization", "Bearer " + tree.CurrentAccessToken)
                .Accept(MediaTypes.GEDCOMX_JSON_MEDIA_TYPE)
                .ContentType(MediaTypes.MULTIPART_FORM_DATA_TYPE)
                .Build("https://sandbox.familysearch.org/platform/memories/memories", Method.POST);

            foreach (var artifact in artifacts)
            {
                String mediaType = artifact.ContentType;

                foreach (TextValue value in description.Titles)
                {
                    request.AddFile("title", Encoding.UTF8.GetBytes(value.Value), null, MediaTypes.TEXT_PLAIN_TYPE);
                }

                foreach (SourceCitation citation in description.Citations)
                {
                    request.AddFile("citation", Encoding.UTF8.GetBytes(citation.Value), null, MediaTypes.TEXT_PLAIN_TYPE);
                }

                if (artifact.Name != null)
                {
                    request.Files.Add(new FileParameter()
                    {
                        Name = "artifact",
                        FileName = artifact.Name,
                        ContentType = artifact.ContentType,
                        Writer = new Action<Stream>(s =>
                        {
                            artifact.InputStream.Seek(0, SeekOrigin.Begin);
                            using (var ms = new MemoryStream(artifact.InputStream.ReadAsBytes()))
                            using (var reader = new StreamReader(ms))
                            {
                                reader.BaseStream.CopyTo(s);
                            }
                        })
                    });
                }
            }

            var state = tree.Client.Handle(request);

            Assert.IsNotNull(state);
            Assert.AreEqual(HttpStatusCode.Created, state.StatusCode);
        }
开发者ID:Herbert42,项目名称:gedcomx-csharp,代码行数:58,代码来源:MemoriesTests.cs

示例5: GetByteArrayFromImage

 public static byte[] GetByteArrayFromImage(Image image)
 {
     ImageConverter converter = new ImageConverter();
     byte[] imgArray = (byte[])converter.ConvertTo(image, typeof(byte[]));
     //TODO: check to see if this needs a dispose
     return imgArray;
 }
开发者ID:Buchan28,项目名称:PLM,代码行数:7,代码来源:PictureResizer.cs

示例6: Image

        public Image(Bitmap bmp)
        {
            //load code
            Pixel np=new Pixel();
            m_width = (uint)bmp.Width;
            m_height = (uint)bmp.Height;
            m_needFlush = false;

            if (bmp.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed)
            {
                m_components = 3;
            }
            else if (bmp.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed ||
                     bmp.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed ||
                     bmp.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed)
            {
                m_components = 4;
            }
            else if (bmp.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed)
            {
                m_components = 1;
            }

            ImageConverter imageConverter = new ImageConverter();
             m_buffer = (byte[])imageConverter.ConvertTo(bmp, typeof(byte[]));
        }
开发者ID:keroishak,项目名称:Pattern-Recognition,代码行数:26,代码来源:Image.cs

示例7: toImgur

        public static ImageInfo toImgur(Bitmap bmp)
        {
            ImageConverter convert = new ImageConverter();
            byte[] toSend = (byte[])convert.ConvertTo(bmp, typeof(byte[]));
            using (WebClient wc = new WebClient())
            {
                NameValueCollection nvc = new NameValueCollection
                {
                    { "image", Convert.ToBase64String(toSend) }
                };
                wc.Headers.Add("Authorization", Imgur.getAuth());
                ImageInfo info = new ImageInfo();
                try  
                {
                    byte[] response = wc.UploadValues("https://api.imgur.com/3/upload.xml", nvc);
                    string res = System.Text.Encoding.Default.GetString(response);

                    var xmlDoc = new System.Xml.XmlDocument();
                    xmlDoc.LoadXml(res);
                    info.link = new Uri(xmlDoc.SelectSingleNode("data/link").InnerText);
                    info.deletehash = xmlDoc.SelectSingleNode("data/deletehash").InnerText;
                    info.id = xmlDoc.SelectSingleNode("data/id").InnerText;
                    info.success = true;
                }
                catch (Exception e)
                {
                    info.success = false;
                    info.ex = e;
                }
                return info;
            }
        }
开发者ID:Enoz,项目名称:InfiniPad,代码行数:32,代码来源:Imgur.cs

示例8: WriteJson

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			var bmp = value as Bitmap;
			if (bmp == null) return;
			var converter = new ImageConverter();
			writer.WriteValue(Convert.ToBase64String((byte[])converter.ConvertTo(bmp, typeof(byte[]))));
		}
开发者ID:w01f,项目名称:VolgaTeam.Dashboard,代码行数:7,代码来源:JsonImageConverter.cs

示例9: Index

        public ActionResult Index(HttpPostedFileBase image)
        {
            if (image == null) return Index("Where's the beef?");
            var imageStreamConverter = new ImageStreamConverter();
            var bitmap = imageStreamConverter.GetBitmapFromPostedFile(image);

            if (bitmap == null) return Index("That's not an image, homie...");

            var serviceBusConnectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
            var blobConnectionString = CloudConfigurationManager.GetSetting("BlobStorage.ConnectionString");

            var storageAccount = CloudStorageAccount.Parse(blobConnectionString);
            var blobClient = storageAccount.CreateCloudBlobClient();
            var container = blobClient.GetContainerReference("images");
            container.CreateIfNotExists();

            var blockReference = container.GetBlockBlobReference(image.FileName);
            var converter = new ImageConverter();
            var bitmapBytes = (byte[])converter.ConvertTo(bitmap, typeof(byte[]));

            blockReference.UploadFromByteArray(bitmapBytes, 0, bitmapBytes.Length);

            var namespaceManager = NamespaceManager.CreateFromConnectionString(serviceBusConnectionString);

            if (!namespaceManager.QueueExists("ImageProcessing"))
            {
                namespaceManager.CreateQueue("ImageProcessing");
            }

            var client = QueueClient.CreateFromConnectionString(serviceBusConnectionString, "ImageProcessing");
            var message = new BrokeredMessage(new ImageMessage { BlobBlockName = blockReference.Name });

            client.Send(message);
            return Index();
        }
开发者ID:justinSelf,项目名称:AzureServiceBusDemo,代码行数:35,代码来源:HomeController.cs

示例10: ImageToByte

        /// <summary>
        /// Donne le byte[] d'une image grâce à son chemin
        /// </summary>
        public static byte[] ImageToByte(string path)
        {
            Image oldImage = Image.FromFile(path);

            // Définie les nouvelles height et with
            int newWidth;
            int newHeight;
            if (oldImage.Width > oldImage.Height)
            {
                newWidth = 120;
                newHeight = 120 * oldImage.Height / oldImage.Width;
            }
            else
            {
                newHeight = 120;
                newWidth = 120 * oldImage.Width / oldImage.Height;
            }

            // Redimensionne l'image
            Bitmap newImage = new Bitmap(newWidth, newHeight);
            Graphics resizer = Graphics.FromImage(newImage);
            resizer.InterpolationMode = InterpolationMode.HighQualityBicubic;
            resizer.DrawImage(oldImage, 0, 0, newWidth, newHeight);

            // Transforme l'image en byte[]
            ImageConverter converter = new ImageConverter();
            byte[] newImageByteArray = (byte[])converter.ConvertTo(newImage, typeof(byte[]));

            // Libération mémoire
            oldImage.Dispose();
            newImage.Dispose();
            resizer.Dispose();

            return newImageByteArray;
        }
开发者ID:Softcadbury,项目名称:WpfProject,代码行数:38,代码来源:Tools.cs

示例11: Upload

        public string Upload(Image image)
        {
            ImageConverter converter = new ImageConverter();
            byte[] imageData = (byte[])converter.ConvertTo(image, typeof(byte[]));

            if (imageData == null)
                return string.Empty;

            try
            {
                string fileName = String.Format("{0}.png", DateTime.Now.ToString("dd.MM.yyyy-HH.mm.ss"));
                FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(String.Format("{0}/{1}/{2}", settings.Server, settings.Directory, fileName));
                {
                    request.Method = WebRequestMethods.Ftp.UploadFile;
                    request.Credentials = new NetworkCredential(settings.Username, settings.Password);
                    request.UsePassive = true;
                    request.UseBinary = true;
                    request.KeepAlive = false;
                    request.ReadWriteTimeout = 15000;
                    request.Timeout = 15000;
                }

                Stream reqStream = request.GetRequestStream();
                reqStream.Write(imageData, 0, imageData.Length);
                reqStream.Close();

                return String.Format("{0}/{1}", settings.Url, fileName);
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
开发者ID:TBXin,项目名称:Fireball,代码行数:33,代码来源:PluginBody.cs

示例12: dataGridView1_CellClick

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 4)
            {
                // -------------- Loading An Image From File ---------------
                // ------------------- As Bytes Array ----------------------

                var ofd = new OpenFileDialog();

                if (ofd.ShowDialog() != DialogResult.OK)
                    return;

                Image img = Image.FromFile(ofd.FileName);

                // Converting An Image To Array Of Bytes
                ImageConverter converter = new ImageConverter();
                byte[] imgBytes = (byte[])converter.ConvertTo(img, typeof(byte[]));

                // Removing Image From RAM
                // Also, you can use "uses" keyword for Auto Dispose
                img.Dispose();
                dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = imgBytes;
                ((DataGridViewImageColumn)dataGridView1.Columns[e.ColumnIndex]).ImageLayout = DataGridViewImageCellLayout.Zoom;

            }
        }
开发者ID:MatthewWelch,项目名称:FTPDemo,代码行数:26,代码来源:IndustryForm.cs

示例13: ComputeIconHash

 private byte[] ComputeIconHash(Icon icon)
 {
     ImageConverter converter = new ImageConverter();
     byte[] rawIcon = converter.ConvertTo(icon.ToBitmap(), typeof(byte[])) as byte[];
     MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
     return md5.ComputeHash(rawIcon);
 }
开发者ID:M4sterShake,项目名称:BitcoinPriceMonitor,代码行数:7,代码来源:NotificationTrayIconTests.cs

示例14: ExcelPicture

        internal ExcelPicture(ExcelDrawings drawings, XmlNode node) :
            base(drawings, node, "xdr:pic/xdr:nvPicPr/xdr:cNvPr/@name")
        {
            XmlNode picNode = node.SelectSingleNode("xdr:pic/xdr:blipFill/a:blip", drawings.NameSpaceManager);
            if (picNode != null)
            {
                RelPic = drawings.Part.GetRelationship(picNode.Attributes["r:embed"].Value);
                UriPic = PackUriHelper.ResolvePartUri(drawings.UriDrawing, RelPic.TargetUri);

                Part = drawings.Part.Package.GetPart(UriPic);
                FileInfo f = new FileInfo(UriPic.OriginalString);
                ContentType = GetContentType(f.Extension);
                _image = Image.FromStream(Part.GetStream());
                ImageConverter ic=new ImageConverter();
                var iby=(byte[])ic.ConvertTo(_image, typeof(byte[]));
                var ii = _drawings._package.LoadImage(iby, UriPic, Part);
                ImageHash = ii.Hash;

                string relID = GetXmlNodeString("xdr:pic/xdr:nvPicPr/xdr:cNvPr/a:hlinkClick/@r:id");
                if (!string.IsNullOrEmpty(relID))
                {
                    HypRel = drawings.Part.GetRelationship(relID);
                    if (HypRel.TargetUri.IsAbsoluteUri)
                    {
                        _hyperlink = new ExcelHyperLink(HypRel.TargetUri.AbsoluteUri);
                    }
                    else
                    {
                        _hyperlink = new ExcelHyperLink(HypRel.TargetUri.OriginalString, UriKind.Relative);
                    }
                    ((ExcelHyperLink)_hyperlink).ToolTip = GetXmlNodeString("xdr:pic/xdr:nvPicPr/xdr:cNvPr/a:hlinkClick/@tooltip");
                }
            }
        }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:34,代码来源:ExcelPicture.cs

示例15: GenerateTextImage

        public byte[] GenerateTextImage(string text, string stringFont, int fontSize, FontStyle[] fontStyles, string stringColor, Size imageSize, bool isVertical)
        {
            fontSize = (fontSize == 0 ? 1024 : fontSize);

            Color color = new Color();
            try
            {
                color = ColorTranslator.FromHtml(stringColor);
            }
            catch { }

            FontStyle styles = FontStyle.Regular;
            if (fontStyles != null)
            {
                foreach (FontStyle style in fontStyles)
                {
                    styles |= style;
                }
            }

            Image image = ImageProcessor.GenerateTextImage(text, new Font(stringFont, fontSize, styles), new SolidBrush(color), isVertical);

            if (imageSize != null && imageSize.Width > 0 && imageSize.Height > 0)
            {
                image = new Bitmap(image, imageSize);
            }

            ImageConverter converter = new ImageConverter();
            return (byte[])converter.ConvertTo(image, typeof(byte[]));
        }
开发者ID:minchen898,项目名称:ImageService,代码行数:30,代码来源:ProcessImage.asmx.cs


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