本文整理汇总了C#中System.Drawing.Icon.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Icon.Dispose方法的具体用法?C# Icon.Dispose怎么用?C# Icon.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Icon
的用法示例。
在下文中一共展示了Icon.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateWindowsIcon
private void GenerateWindowsIcon()
{
var stm = new MemoryStream();
var icon = new Icon(new MemoryStream(resource.Bytes));
dlg.Image = Bitmap.FromHicon(icon.Handle);
icon.Dispose();
}
示例2: AddEmbeddedResource
/// <summary>
/// Adds a 32bit alphablended icon or image to an existing imagelist from an embedded image or icon.
/// </summary>
/// <param name="ResourceName">The name of an embedded resource.</param>
/// <param name="Imagelist">An existing imagelist to add the resource to.</param>
/// <example>.AddEmbeddedResource( "ProjectName.file.ico", toolbarImagelist );</example>
public static void AddEmbeddedResource( string resourceName, ImageList destinationImagelist )
{
Bitmap bm = new Bitmap ( Assembly.GetExecutingAssembly ( ).GetManifestResourceStream ( resourceName ) );
if ( bm.RawFormat.Guid == ImageFormat.Icon.Guid ) {
Icon icn = new Icon ( Assembly.GetExecutingAssembly ( ).GetManifestResourceStream ( resourceName ) );
destinationImagelist.Images.Add ( resourceName, Icon.FromHandle ( icn.Handle ) );
icn.Dispose ( );
} else {
AddFromImage ( bm, destinationImagelist );
}
bm.Dispose ( );
}
示例3: Add
public static void Add(string FileName, ImageList Imagelist)
{
Bitmap bitmap = new Bitmap(FileName);
if (bitmap.RawFormat.Guid == ImageFormat.Icon.Guid)
{
Icon icon = new Icon(FileName);
Imagelist.Images.Add(Icon.FromHandle(icon.Handle));
icon.Dispose();
}
else
Add(bitmap, Imagelist);
bitmap.Dispose();
}
示例4: GetTargetWindowIcon
private Image GetTargetWindowIcon()
{
Image image = null;
IntPtr handle = System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, Control.GetSafeHandle(this.target)), 0x7f, 0, 0);
System.Windows.Forms.IntSecurity.ObjectFromWin32Handle.Assert();
try
{
Icon original = (handle != IntPtr.Zero) ? Icon.FromHandle(handle) : Form.DefaultIcon;
Icon icon2 = new Icon(original, SystemInformation.SmallIconSize);
image = icon2.ToBitmap();
icon2.Dispose();
}
finally
{
CodeAccessPermission.RevertAssert();
}
return image;
}
示例5: ConvertFromIcon
public static BitmapSource ConvertFromIcon(Icon icon)
{
try
{
var bs = Imaging
.CreateBitmapSourceFromHIcon(icon.Handle,
new Int32Rect(0, 0, icon.Width, icon.Height),
BitmapSizeOptions.FromWidthAndHeight(icon.Width,
icon.Height));
return bs;
}
finally
{
DeleteObject(icon.Handle);
icon.Dispose();
// ReSharper disable RedundantAssignment
icon = null;
// ReSharper restore RedundantAssignment
}
}
示例6: AddIconToHandle
private int AddIconToHandle(Original original, Icon icon)
{
int num2;
try
{
int num = System.Windows.Forms.SafeNativeMethods.ImageList_ReplaceIcon(new HandleRef(this, this.Handle), -1, new HandleRef(icon, icon.Handle));
if (num == -1)
{
throw new InvalidOperationException(System.Windows.Forms.SR.GetString("ImageListAddFailed"));
}
num2 = num;
}
finally
{
if ((original.options & OriginalOptions.OwnsImage) != OriginalOptions.Default)
{
icon.Dispose();
}
}
return num2;
}
示例7: VCRNETControl
public VCRNETControl( string[] args )
{
// Report
Log( "VCC [2013/06/01] starting up" );
// Autostart service
if (m_Settings.AutoStartService)
if (!ThreadPool.QueueUserWorkItem( StartService ))
StartService( null );
// This is us
Type me = GetType();
// Pattern start
string prefix = me.Namespace + ".TrayIcons.";
string suffix = ".ICO";
// Load tray icons
foreach (string resname in me.Assembly.GetManifestResourceNames())
if (resname.StartsWith( prefix ))
if (resname.EndsWith( suffix ))
{
// Icon
string iconname = resname.Substring( prefix.Length, resname.Length - prefix.Length - suffix.Length );
// Load
using (Stream stream = me.Assembly.GetManifestResourceStream( resname ))
{
// Load the icon
Icon icon = new Icon( stream );
// Check for debugger
if (Debugger.IsAttached)
using (var bmp = icon.ToBitmap())
{
// Change
using (var gc = Graphics.FromImage( bmp ))
using (var color = new SolidBrush( Color.Black ))
{
// Paint
gc.FillRectangle( color, 0, 15, bmp.Width, 5 );
}
// Free icon
icon.Dispose();
// Reload
icon = Icon.FromHandle( bmp.GetHicon() );
}
// Get the related color
var colorIndex = (TrayColors)Enum.Parse( typeof( TrayColors ), iconname, true );
// Add to map
m_TrayIcons[colorIndex] = icon;
}
}
// Load picture
using (var stream = me.Assembly.GetManifestResourceStream( me.Namespace + ".Icons.Connected.ico" ))
m_Connected = Image.FromStream( stream );
// Startup
InitializeComponent();
// Load the top menu string
m_TopMenu = mnuDefault.Text;
// Correct IDE problems (destroyed when language changes)
selHibernate.Value = 5;
selHibernate.Minimum = 1;
selHibernate.Maximum = 30;
selInterval.Value = 10;
selInterval.Minimum = 5;
selInterval.Maximum = 300;
selPort.Maximum = ushort.MaxValue;
selPort.Value = 80;
selPort.Minimum = 1;
selStreamPort.Maximum = ushort.MaxValue;
selStreamPort.Value = 2910;
selStreamPort.Minimum = 1;
lstServers.View = View.Details;
errorMessages.SetIconAlignment( txArgs, ErrorIconAlignment.MiddleLeft );
errorMessages.SetIconAlignment( txMultiCast, ErrorIconAlignment.MiddleLeft );
// Make sure that handle exists
CreateHandle();
// Load servers
if (null != m_Settings.Servers)
foreach (var setting in m_Settings.Servers)
lstServers.Items.Add( setting.View );
// Load settings
ckAutoStart.Checked = m_Settings.AutoStartService;
ckHibernate.Checked = (m_Settings.HibernationDelay > 0);
selHibernate.Value = ckHibernate.Checked ? (int)m_Settings.HibernationDelay : 5;
txMultiCast.Text = m_Settings.MulticastIP;
selStreamPort.Value = m_Settings.MinPort;
selDelay.Value = m_Settings.StartupDelay;
//.........这里部分代码省略.........
示例8: Icon256ToBitmap
public void Icon256ToBitmap ()
{
if (RunningOnUnix)
Assert.Ignore ("Depends on bug #323511");
using (FileStream fs = File.OpenRead (TestBitmap.getInFile ("bitmaps/415581.ico"))) {
Icon icon = new Icon (fs, 48, 48);
using (Bitmap b = icon.ToBitmap ()) {
Assert.AreEqual (0, b.Palette.Entries.Length, "#A1");
Assert.AreEqual (48, b.Height, "#A2");
Assert.AreEqual (48, b.Width, "#A3");
Assert.IsTrue (b.RawFormat.Equals (ImageFormat.MemoryBmp), "#A4");
Assert.AreEqual (2, b.Flags, "#A5");
}
icon.Dispose ();
}
using (FileStream fs = File.OpenRead (TestBitmap.getInFile ("bitmaps/415581.ico"))) {
Icon icon = new Icon (fs, 256, 256);
using (Bitmap b = icon.ToBitmap ()) {
Assert.AreEqual (0, b.Palette.Entries.Length, "#B1");
Assert.AreEqual (48, b.Height, "#B2");
Assert.AreEqual (48, b.Width, "#B3");
Assert.IsTrue (b.RawFormat.Equals (ImageFormat.MemoryBmp), "#B4");
Assert.AreEqual (2, b.Flags, "#B5");
}
}
}
示例9: GetTargetWindowIcon
private Image GetTargetWindowIcon() {
Image systemIcon = null;
IntPtr hIcon = UnsafeNativeMethods.SendMessage(new HandleRef(this, Control.GetSafeHandle(target)), NativeMethods.WM_GETICON, NativeMethods.ICON_SMALL, 0);
IntSecurity.ObjectFromWin32Handle.Assert();
try {
Icon icon = (hIcon != IntPtr.Zero) ? Icon.FromHandle(hIcon) : Form.DefaultIcon;
Icon smallIcon = new Icon(icon, SystemInformation.SmallIconSize);
systemIcon = smallIcon.ToBitmap();
smallIcon.Dispose();
} finally {
CodeAccessPermission.RevertAssert();
}
return systemIcon;
}
示例10: GetBitmapFromIcon
private static Bitmap GetBitmapFromIcon(string iconName)
{
Size desiredSize = new Size(iconsWidth, iconsHeight);
Icon icon = new Icon(BitmapSelector.GetResourceStream(typeof(DataGridViewRowHeaderCell), iconName), desiredSize);
Bitmap b = icon.ToBitmap();
icon.Dispose();
if (DpiHelper.IsScalingRequired && (b.Size.Width != iconsWidth || b.Size.Height != iconsHeight))
{
Bitmap scaledBitmap = DpiHelper.CreateResizedBitmap(b, desiredSize);
if (scaledBitmap != null)
{
b.Dispose();
b = scaledBitmap;
}
}
return b;
}
示例11: AddButtons
private void AddButtons(DesignerForm newDialog, XmlNodeList buttons)
{
foreach (XmlNode button in buttons)
{
try
{
Button newButton = new Button();
SetControlAttributes(newButton, button);
if (button.Attributes["Icon"] != null &&
button.Attributes["Icon"].Value.ToLower() == "yes")
{
string binaryId = GetTextFromXmlElement(button);
try
{
using (Stream imageStream = GetBinaryStream(binaryId))
{
Bitmap bmp = new Icon(imageStream).ToBitmap();
Bitmap dest = new Bitmap((int)Math.Round(bmp.Width * scale), (int)Math.Round(bmp.Height * scale));
Graphics g = Graphics.FromImage(dest);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(bmp,
new Rectangle(0, 0, dest.Width, dest.Height),
new Rectangle(0, 0, bmp.Width, bmp.Height),
GraphicsUnit.Pixel);
g.Dispose();
bmp.Dispose();
newButton.Image = dest;
}
}
catch
{
SetText(newButton, button);
}
}
else
{
newButton.FlatStyle = FlatStyle.System;
SetText(newButton, button);
}
newDialog.AddControl(button, newButton);
}
catch
{
}
}
}
示例12: CreateDotDotDotBitmap
private static Bitmap CreateDotDotDotBitmap()
{
Bitmap bitmap = null;
Icon icon = null;
try
{
icon = new Icon(typeof(TypeEditorHost), "dotdotdot.ico");
using (var original = icon.ToBitmap())
{
bitmap = BitmapFromImageReplaceColor(original);
}
}
catch
{
bitmap = new Bitmap(16, 16);
throw;
}
finally
{
if (icon != null)
{
icon.Dispose();
}
}
return bitmap;
}
示例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: CreateFormIcons
/// <summary>
/// Hides from Alt-TAB
/// </summary>
//protected override CreateParams CreateParams
//{
// get
// {
// CreateParams cp = base.CreateParams;
// // Turns on WS_EX_TOOLWINDOW style bit to hide from Alt-TAB list
// cp.ExStyle |= 0x80;
// return cp;
// }
//}
/// <summary>
/// Creates tray icon from embedded to project icon. Throws execptions
/// </summary>
private void CreateFormIcons()
{
// Create tray icon
Assembly asm = Assembly.GetExecutingAssembly();
FileInfo fi = new FileInfo(asm.GetName().Name);
using(Stream s = asm.GetManifestResourceStream(string.Format("{0}.av1.ico", fi.Name)))
{
// Create icon to be used in Form and Tray
Icon icon = new Icon(s);
Icon = new Icon(icon, icon.Size);
_icon = new NotifyIcon();
_icon.Visible = true;
_icon.Icon = new Icon(icon, icon.Size);
icon.Dispose();
}
}
示例15: CreateDownArrow
private Bitmap CreateDownArrow()
{
Bitmap bitmap = null;
try
{
Icon icon = new Icon(typeof(BindingFormattingDialog), "BindingFormattingDialog.Arrow.ico");
bitmap = icon.ToBitmap();
icon.Dispose();
}
catch
{
bitmap = new Bitmap(0x10, 0x10);
}
return bitmap;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:15,代码来源:BindingFormattingWindowsFormsEditorService.cs