本文整理汇总了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);
}
示例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;
}
示例3: IconToBytes
public static byte[] IconToBytes(Icon icon)
{
using (var ms = new MemoryStream())
{
icon.Save(ms);
return ms.ToArray();
}
}
示例4: Init
public virtual void Init()
{
originalIcon = new Icon(GetType(), "TestIcon.ico");
file = "./yellow.ico";
using (FileStream stream = File.Create(file))
{
originalIcon.Save(stream);
}
}
示例5: GetIconBytes
private byte[] GetIconBytes(Icon icon)
{
using (var ms = new MemoryStream())
{
icon.Save(ms);
ms.Flush();
return ms.GetBuffer();
}
}
示例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;
}
示例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;
}
示例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 "";
}
}
示例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;
}
示例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));
}
}
}
}
}
}
}
示例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 "";
}
}
示例12: CreateIcon
private void CreateIcon(String name, Icon icon)
{
using (Stream iconStream = new FileStream(name, FileMode.Create))
{
icon.Save(iconStream);
}
icon.Dispose();
}
示例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();
}
}
示例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;
}
示例15: SaveIcon
public static void SaveIcon(Icon SourceIcon, string IconFilename)
{
FileStream NewIconStream = new FileStream(IconFilename, FileMode.Create);
SourceIcon.Save(NewIconStream);
NewIconStream.Close();
}