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


C# Icon.Save方法代码示例

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


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

示例1: ConvertFromIcon

		private static BitmapFrame ConvertFromIcon(Icon icon)
		{
			var memoryStream = new MemoryStream();
			icon.Save(memoryStream);
			memoryStream.Seek(0, SeekOrigin.Begin);
			return BitmapFrame.Create(memoryStream);
		}  
开发者ID:olivierdagenais,项目名称:GoToWindow,代码行数:7,代码来源:DesignTimeMainViewModel.cs

示例2: ExtractVistaIcon

 Bitmap ExtractVistaIcon(Icon icoIcon)
 {
     Bitmap bmpPngExtracted = null;
     try
     {
         byte[] srcBuf = null;
         using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
         { icoIcon.Save(stream); srcBuf = stream.ToArray(); }
         const int SizeICONDIR = 6;
         const int SizeICONDIRENTRY = 16;
         int iCount = BitConverter.ToInt16(srcBuf, 4);
         for (int iIndex = 0; iIndex < iCount; iIndex++)
         {
             int iWidth = srcBuf[SizeICONDIR + SizeICONDIRENTRY * iIndex];
             int iHeight = srcBuf[SizeICONDIR + SizeICONDIRENTRY * iIndex + 1];
             int iBitCount = BitConverter.ToInt16(srcBuf, SizeICONDIR + SizeICONDIRENTRY * iIndex + 6);
             if (iWidth == 0 && iHeight == 0 && iBitCount == 32)
             {
                 int iImageSize = BitConverter.ToInt32(srcBuf, SizeICONDIR + SizeICONDIRENTRY * iIndex + 8);
                 int iImageOffset = BitConverter.ToInt32(srcBuf, SizeICONDIR + SizeICONDIRENTRY * iIndex + 12);
                 System.IO.MemoryStream destStream = new System.IO.MemoryStream();
                 System.IO.BinaryWriter writer = new System.IO.BinaryWriter(destStream);
                 writer.Write(srcBuf, iImageOffset, iImageSize);
                 destStream.Seek(0, System.IO.SeekOrigin.Begin);
                 bmpPngExtracted = new Bitmap(destStream); // This is PNG! :)
                 break;
             }
         }
     }
     catch { return null; }
     return bmpPngExtracted;
 }
开发者ID:resedmodel,项目名称:ResedUI,代码行数:32,代码来源:AboutForm.cs

示例3: IconToBytes

 public static byte[] IconToBytes(Icon icon)
 {
     using (var ms = new MemoryStream())
     {
         icon.Save(ms);
         return ms.ToArray();
     }
 }
开发者ID:gmlohaels,项目名称:fuzzyLauncher,代码行数:8,代码来源:IconHelper.cs

示例4: Init

		public virtual void Init()
		{
			originalIcon = new Icon(GetType(), "TestIcon.ico");
			file = "./yellow.ico";
			using (FileStream stream = File.Create(file))
			{
				originalIcon.Save(stream);
			}
		}
开发者ID:kascomp,项目名称:CruiseControl.NET,代码行数:9,代码来源:IconFileFixture.cs

示例5: GetIconBytes

 private byte[] GetIconBytes(Icon icon)
 {
     using (var ms = new MemoryStream())
     {
         icon.Save(ms);
         ms.Flush();
         return ms.GetBuffer();
     }
 }
开发者ID:jeremywiebe,项目名称:Sql-Aliaser,代码行数:9,代码来源:Growler.cs

示例6: ExtractVistaIcon

        private static Bitmap ExtractVistaIcon(Icon icon)
        {
            Bitmap extractedIcon = null;

            if (icon == null)
            {
                return extractedIcon;
            }

            try
            {
                byte[] srcBuf = null;
                using (var stream = new MemoryStream())
                {
                    icon.Save(stream);
                    srcBuf = stream.ToArray();
                }

                const int SizeICONDIR = 6;
                const int SizeICONDIRENTRY = 16;
                int iCount = BitConverter.ToInt16(srcBuf, 4);
                for (int iIndex = 0; iIndex < iCount; iIndex++)
                {
                    int width = srcBuf[SizeICONDIR + SizeICONDIRENTRY * iIndex];
                    int height = srcBuf[SizeICONDIR + SizeICONDIRENTRY * iIndex + 1];
                    int bitCount = BitConverter.ToInt16(srcBuf, SizeICONDIR + SizeICONDIRENTRY * iIndex + 6);

                    if (width == 0 && height == 0 && bitCount == 32)
                    {
                        int imageSize = BitConverter.ToInt32(srcBuf, SizeICONDIR + SizeICONDIRENTRY * iIndex + 8);
                        int imageOffset = BitConverter.ToInt32(srcBuf, SizeICONDIR + SizeICONDIRENTRY * iIndex + 12);
                        using (var destStream = new MemoryStream())
                        {
                            var writer = new BinaryWriter(destStream);
                            writer.Write(srcBuf, imageOffset, imageSize);
                            destStream.Seek(0, SeekOrigin.Begin);

                            extractedIcon = new Bitmap(destStream); // This is PNG! :)
                            return extractedIcon;
                        }
                    }
                }
            }
            catch
            {
                return null;

            }

            return extractedIcon;
        }
开发者ID:WildGums,项目名称:Orchestra,代码行数:51,代码来源:IconHelper.cs

示例7: ConvertIconToBitmap

        /// <summary>
        /// Converts the specified icon into a bitmap
        /// </summary>
        /// <param name="icon">icon to convert</param>
        /// <returns>bitmap representation of icon</returns>
        public static Bitmap ConvertIconToBitmap(Icon icon)
        {
            if (icon != null)
            {
                using (var memoryStream = new MemoryStream())
                {
                    icon.Save(memoryStream);
                    using (var bitmap = (Bitmap)Image.FromStream(memoryStream))
                    {
                        return new Bitmap(bitmap);
                    }
                }
            }

            return null;
        }
开发者ID:glwu,项目名称:acat,代码行数:21,代码来源:ImageUtils.cs

示例8: IconToBytes

 public string IconToBytes(Icon icon)
 {
     try
     {
         using (MemoryStream ms = new MemoryStream())
         {
             icon.Save(ms);
             byte[] bytes = ms.ToArray();
             return Convert.ToBase64String(bytes);
         }
     }
     catch (Exception e)
     {
         return "";
     }
 }
开发者ID:pekand,项目名称:infinite-diagram,代码行数:16,代码来源:Form1.cs

示例9: Build

        public static AddinInstallerFile Build(string license, List<string> dependencies, string assembly, Icon icon)
        {
            var ret = new AddinInstallerFile();
            ret.License = license;

            if (icon != null)
            {
                var ims = new MemoryStream();
                icon.Save(ims);
                ret.Icon = ims.ToArray();
            }

            if (dependencies != null)
            {
                foreach (var dependency in dependencies)
                {
                    ret.Dependecies.Add(Path.GetFileName(dependency), File.ReadAllBytes(dependency));
                }
            }

            ret.Assembly = new KeyValuePair<string, byte[]>(Path.GetFileName(assembly), File.ReadAllBytes(assembly));

            return ret;
        }
开发者ID:Myvar,项目名称:Eclang,代码行数:24,代码来源:AddinInstallerFile.cs

示例10: SaveAndCompare

		internal static void SaveAndCompare (string msg, Icon icon, bool alpha)
		{
			using (MemoryStream ms = new MemoryStream ()) {
				icon.Save (ms);
				ms.Position = 0;

				using (Icon loaded = new Icon (ms)) {
					Assert.AreEqual (icon.Height, loaded.Height, msg + ".Loaded.Height");
					Assert.AreEqual (icon.Width, loaded.Width, msg + ".Loaded.Width");

					using (Bitmap expected = icon.ToBitmap ()) {
						using (Bitmap actual = loaded.ToBitmap ()) {
							Assert.AreEqual (expected.Height, actual.Height, msg + ".Bitmap.Height");
							Assert.AreEqual (expected.Width, actual.Width, msg + ".Bitmap.Width");

							for (int y = 0; y < expected.Height; y++) {
								for (int x = 0; x < expected.Width; x++) {
									Color e = expected.GetPixel (x, y);
									Color a = actual.GetPixel (x, y);
									if (alpha)
										Assert.AreEqual (e.A, a.A, String.Format ("{0}:{1}x{2}:A", msg, x, y));
									Assert.AreEqual (e.R, a.R, String.Format ("{0}:{1}x{2}:R", msg, x, y));
									Assert.AreEqual (e.G, a.G, String.Format ("{0}:{1}x{2}:G", msg, x, y));
									Assert.AreEqual (e.B, a.B, String.Format ("{0}:{1}x{2}:B", msg, x, y));
								}
							}
						}
					}
				}
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:31,代码来源:TestIcon.cs

示例11: IconToString

 /// <summary>
 /// convert Icon to base64 string </summary>
 public static string IconToString(Icon icon)
 {
     try
     {
         using (MemoryStream ms = new MemoryStream())
         {
             icon.Save(ms);
             byte[] bytes = ms.ToArray();
             return Convert.ToBase64String(bytes);
         }
     }
     catch (Exception e)
     {
         Program.log.write("IconToString error: " + e.Message);
         return "";
     }
 }
开发者ID:pekand,项目名称:infinite-diagram,代码行数:19,代码来源:Media.cs

示例12: CreateIcon

 private void CreateIcon(String name, Icon icon)
 {
     using (Stream iconStream = new FileStream(name, FileMode.Create))
     {
         icon.Save(iconStream);
     }
     icon.Dispose();
 }
开发者ID:krack,项目名称:notifier,代码行数:8,代码来源:Factory.cs

示例13: CreateIcon

		private void CreateIcon(string path, bool useDefault = true) {
			var str = Legacy.UserSettings.ImageDir + @"\" + g.FileSafeTitle + ".ico";
			if (useDefault) {
				using (var stream = new FileStream(str, FileMode.OpenOrCreate, FileAccess.ReadWrite)) {
					Properties.Resources.icon.Save(stream);
					return;
				}
			}
			var icon = new Icon(path);
			using (var stream2 = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite)) {
				icon.Save(stream2);
				icon.Dispose();
			}
		}
开发者ID:CyberFoxHax,项目名称:PCSXBonus,代码行数:14,代码来源:wndGenerateExecutable.xaml.cs

示例14: SaveStreamResource

        private int SaveStreamResource(string resName, Stream s, string saveDir)
        {
            if (s == null)
                return 0;

            int count = 0;
            bool handled = false;
            string outputFile = GetOutputResourceFile(resName, saveDir);

            if (PathUtils.IsIconExt(outputFile))
            {
                try
                {
                    if (s.CanSeek)
                        s.Seek(0, SeekOrigin.Begin);
                    Icon ico = new Icon(s);
                    using (FileStream fs = File.Create(outputFile))
                    {
                        ico.Save(fs);
                    }
                    count++;
                    handled = true;
                }
                catch (ArgumentException) { }
            }
            else if (PathUtils.IsCursorExt(outputFile))
            {
                try
                {
                    //it seems there is no easy way to write cursor to file
                    //http://msdn.microsoft.com/en-us/library/ms997538.aspx
                    Cursor c = LoadCursor(s);
                    Bitmap bmp = ConvertToBitmap(c);
                    bmp.Save(outputFile + GetImageExt(bmp));
                    count++;
                    handled = true;
                }
                catch (Exception ex)
                {
                    _form.SetStatusText(String.Format("Failed to save {0}: {1}", resName, ex.Message));
                }                
            }
            else if (ResourceFile.Default.IsImageResource(outputFile))
            {
                try
                {
                    Bitmap bmp = new Bitmap(s);
                    bmp.Save(outputFile);
                    count++;
                    handled = true;
                }
                catch (ArgumentException) { }
            }
            else if (PathUtils.IsBamlExt(outputFile))
            {
                try
                {
                    string newOutputFile = Path.ChangeExtension(outputFile, ".xaml");
                    using (StreamWriter sw = File.CreateText(newOutputFile))
                    {
                        sw.WriteLine(DecompileBaml(s));
                    }
                    count++;
                    //handled = true; 
                }
                catch (Exception ex)
                {
                    _form.SetStatusText(String.Format("Failed to translate {0}: {1}", resName, ex.Message));
                }
            }

            if (!handled)
            {
                byte[] buffer = new byte[s.Length];
                if (s.CanSeek)
                {
                    s.Seek(0, SeekOrigin.Begin);
                }
                s.Read(buffer, 0, buffer.Length);
                using (FileStream fs = File.Create(outputFile))
                {
                    fs.Write(buffer, 0, buffer.Length);
                }
                count++;
            }

            return count;
        }
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:88,代码来源:ClassEditResourceHandler.cs

示例15: SaveIcon

        public static void SaveIcon(Icon SourceIcon, string IconFilename)
        {
            FileStream NewIconStream = new FileStream(IconFilename, FileMode.Create);

            SourceIcon.Save(NewIconStream);

            NewIconStream.Close();
        }
开发者ID:RSchwoerer,项目名称:Terminals,代码行数:8,代码来源:IconHandler.cs


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