本文整理匯總了C#中System.Drawing.Bitmap.GetHicon方法的典型用法代碼示例。如果您正苦於以下問題:C# Bitmap.GetHicon方法的具體用法?C# Bitmap.GetHicon怎麽用?C# Bitmap.GetHicon使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Drawing.Bitmap
的用法示例。
在下文中一共展示了Bitmap.GetHicon方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Create
public static Icon Create(Bitmap bm)
{
bm.MakeTransparent(Color.White);
IntPtr ich = bm.GetHicon();
return Icon.FromHandle(ich);
}
示例2: CreateCursor
/// <summary>
/// カーソルを作成する
/// </summary>
/// <param name="bitmap">カーソル畫像</param>
/// <param name="xHotSpot">ホットスポットのX座標</param>
/// <param name="yHotSpot">ホットスポットのY座標</param>
/// <returns>作成したカーソル</returns>
public static Cursor CreateCursor(Bitmap bitmap, int xHotSpot, int yHotSpot)
{
Bitmap andMask = new Bitmap(bitmap.Width, bitmap.Height);
Bitmap xorMask = new Bitmap(bitmap.Width, bitmap.Height);
Color transparent = bitmap.GetPixel(bitmap.Width - 1, bitmap.Height - 1);
for (int x = 0; x < bitmap.Width; x++)
{
for (int y = 0; y < bitmap.Height; y++)
{
Color pixel = bitmap.GetPixel(x, y);
if (pixel == transparent)
{
andMask.SetPixel(x, y, Color.White);
xorMask.SetPixel(x, y, Color.Transparent);
}
else
{
andMask.SetPixel(x, y, Color.Black);
xorMask.SetPixel(x, y, pixel);
}
}
}
IntPtr hIcon = bitmap.GetHicon();
IconInfo info = new IconInfo();
NativeMethods.GetIconInfo(hIcon, ref info);
info.xHotspot = xHotSpot;
info.yHotspot = yHotSpot;
info.hbmMask = andMask.GetHbitmap();
info.hbmColor = xorMask.GetHbitmap();
info.fIcon = false;
hIcon = NativeMethods.CreateIconIndirect(ref info);
return new Cursor(hIcon);
}
示例3: WSU_Apparel_Form
/***************************************************************
* Author: Anthony Simmons *
* Assignment: Homework #4 WSU Apparel *
* Course: CptS 422 - Software Testing *
* Date: October 7, 2013 *
* Function Name: WSU_Apparel_Form() *
* Description: Constructs the Main Form UI *
* Preconditions: None *
* Postconditions: None *
****************************************************************/
public WSU_Apparel_Form()
{
InitializeComponent();
loadComboBoxes();
//loadClothes();
treeViewInventory.CheckBoxes = true;
dgvInventory.EditMode = DataGridViewEditMode.EditProgrammatically;
dgvShoppingCart.EditMode = DataGridViewEditMode.EditProgrammatically;
//inventory.saveInventory("../../Inventory.xml");
dgvInventory.ForeColor = Color.Maroon;
dgvShoppingCart.ForeColor = Color.Maroon;
dgvInventory.BackColor = Color.Gray;
dgvShoppingCart.BackColor = Color.Gray;
treeViewInventory.BackColor = Color.Gray;
treeViewInventory.ForeColor = Color.Maroon;
inventory.loadInventory("../../Inventory.xml");
loadDGVInventory();
loadTreeInventory();
timer1.Interval = 500;
timer1.Start();
Ico = new Bitmap("../../wsu.coug.big.gif");
//Ico = new Bitmap("../../ofallon.jpg");
this.Icon = Icon.FromHandle(Ico.GetHicon());
loadDGVDiscount();
}
示例4: LoadFromFile
public static StatusIcon LoadFromFile(string file)
{
try
{
using (FileStream stream = File.Open(file, FileMode.Open, FileAccess.Read))
{
return new StatusIcon(new Icon(stream), true);
}
}
catch (ArgumentException)
{
try
{
// Attempt to load the icon from an image file instead
using (FileStream stream = File.Open(file, FileMode.Open, FileAccess.Read))
{
using (Bitmap image = new Bitmap(stream))
{
return new StatusIcon(Icon.FromHandle(image.GetHicon()), true);
}
}
}
catch (SystemException ex)
{
throw new IconNotFoundException(file, ex);
}
}
catch (SystemException ex)
{
throw new IconNotFoundException(file, ex);
}
}
示例5: FrmLogin_Load
private void FrmLogin_Load(object sender, EventArgs e)
{
Image img = CKGen.Properties.Resources.link;
Bitmap myBitmap = new Bitmap(img);
Icon myIcon = Icon.FromHandle(myBitmap.GetHicon());
this.Icon = myIcon;
this.bar = new ProgressBar();
this.bar.Location = new System.Drawing.Point(18, 0);
this.bar.Size = new System.Drawing.Size(367, 10);
this.bar.Style = System.Windows.Forms.ProgressBarStyle.Marquee;
this.bar.Visible = false;
this.Controls.Add(bar);
this.cbServerType.DataSource = typeof(DatabaseType).ToList();
this.cbServerType.DisplayMember = "Value";
this.cbServerType.ValueMember = "Key";
this.btnOK.Enabled = false;
var connList = ConnectionSetting.GetList();
if (connList != null && connList.Count > 0)
{
cbServerName.DataSource = connList;
cbServerName.DisplayMember = "ServerName";
cbServerName.ValueMember = "ServerName";
ShowServer(connList[0].ServerName);
}
this.AcceptButton = this.btnLogin;
}
示例6: CreateJumpListImages
public static void CreateJumpListImages(string bniFilePath)
{
string jlIconsPath = Path.Combine(Path.GetDirectoryName(bniFilePath), "JumpListIcons");
if (!Directory.Exists(jlIconsPath))
Directory.CreateDirectory(jlIconsPath);
using (BniFileParser bni = new BniFileParser(bniFilePath))
{
foreach (BniIcon icon in bni.AllIcons)
{
if (icon.SoftwareProductCodes.Length == 0)
continue;
string filename = icon.SoftwareProductCodes[0] + ".ico";
using (Bitmap result = new Bitmap(32, 32, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
using (Graphics g = Graphics.FromImage(result))
{
g.DrawImage(icon.Image, new Rectangle(0, 6, 32, 20));
using (Icon ico = Icon.FromHandle(result.GetHicon()))
using (FileStream fs = new FileStream(Path.Combine(jlIconsPath, filename), FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
{
ico.Save(fs);
}
}
}
}
}
示例7: CreateIcon
public static Icon CreateIcon(Image image, int size, bool preserveAspectRatio)
{
var square = new Bitmap(size, size);
var g = Graphics.FromImage(square);
int x, y, w, h;
if (!preserveAspectRatio || image.Height == image.Width)
{
x = y = 0;
w = h = size;
}
else
{
var r = image.Width / (float) image.Height;
if (r > 1)
{
w = size;
h = (int) (size / r);
x = 0;
y = (size - h) / 2;
}
else
{
w = (int) (size * r);
h = size;
y = 0;
x = (size - w) / 2;
}
}
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(image, x, y, w, h);
g.Flush();
return Icon.FromHandle(square.GetHicon());
}
示例8: Show
public void Show()
{
if (!isInit) {
isInit = true;
using (Bitmap newBmp = new Bitmap(16, 16)) {
Graphics g = Graphics.FromImage(newBmp);
ColorMap[] colorMap = new ColorMap[1];
colorMap[0] = new ColorMap();
colorMap[0].OldColor = Color.Fuchsia;
colorMap[0].NewColor = Color.FromKnownColor(KnownColor.ButtonFace);
ImageAttributes attr = new ImageAttributes();
attr.SetRemapTable(colorMap);
g.DrawImage(tbBmp_tbTab, new Rectangle(0, 0, 16, 16), 0, 0, 16, 16, GraphicsUnit.Pixel, attr);
tbIcon = Icon.FromHandle(newBmp.GetHicon());
}
NppTbData _nppTbData = new NppTbData();
_nppTbData.hClient = this.Handle;
_nppTbData.pszName = this.FormName();
_nppTbData.dlgID = id;
_nppTbData.uMask = FormMask;
_nppTbData.hIconTab = (uint)tbIcon.Handle;
_nppTbData.pszModuleName = UnmanagedExports.main.PluginName();
IntPtr _ptrNppTbData = Marshal.AllocHGlobal(Marshal.SizeOf(_nppTbData));
Marshal.StructureToPtr(_nppTbData, _ptrNppTbData, false);
Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_DMMREGASDCKDLG, 0, _ptrNppTbData);
} else {
Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_DMMSHOW, 0, this.Handle);
}
}
示例9: Initialize
public static void Initialize(dynamic window)
{
Bitmap icon;
using (MemoryStream outStream = new MemoryStream())
{
BitmapEncoder enc = new BmpBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create(new Uri(@"pack://application:,,,/Resources/ImageViewer.ico", UriKind.Absolute)));
enc.Save(outStream);
icon = new Bitmap(outStream);
}
_notifyIcon = new NotifyIcon
{
Icon = System.Drawing.Icon.FromHandle(icon.GetHicon()),
Visible = true
};
var cms = new ContextMenuStrip();
var tsm = new ToolStripMenuItem {Text = @"Exit"};
tsm.Click += (sender, e) =>
{
Exit();
};
cms.Items.Add(tsm);
_notifyIcon.ContextMenuStrip = cms;
Window = window;
}
示例10: IconFromBitmap
public static Icon IconFromBitmap(Bitmap bitmap) {
IntPtr hIcon = bitmap.GetHicon();
using(Icon icon = Icon.FromHandle(hIcon)) { // we can use Icon's dispose method because it calls DestroyIcon for us.
return icon.Clone() as Icon;
}
}
示例11: GetIcon
protected override System.Drawing.Icon GetIcon(bool smallIcon, uint iconSize)
{
Icon icon = null;
try
{
XPathDocument doc = new XPathDocument(SelectedItemPath);
XPathNavigator nav = doc.CreateNavigator();
XPathExpression expr;
expr = nav.Compile("/material/preview/@value");
XPathNodeIterator iterator = nav.Select(expr);
if (iterator.MoveNext())
{
XPathNavigator nav2 = iterator.Current.Clone();
var relativepath = nav2.Value;
var root = Path.GetDirectoryName(SelectedItemPath);
var path = Path.Combine(root, relativepath);
Bitmap bitmap = new Bitmap(path);
icon = Icon.FromHandle(bitmap.GetHicon());
}
}
catch (Exception)
{
icon = null;
}
if (icon == null)
{
// assign default icon
}
// todo
return GetIconSpecificSize(icon, new Size((int)iconSize, (int)iconSize));
}
示例12: CreateIcon
public static Icon CreateIcon(Bitmap bmp, int size) {
var hIcon = bmp.GetHicon();
var icon = Icon.FromHandle(hIcon);
icon = new Icon(icon, size, size);
DestroyIcon(hIcon);
return icon;
}
示例13: setPlayerIconAsync
/// <summary>
/// Asynchronously download the player's skin and set the head as console icon
/// </summary>
public static void setPlayerIconAsync(string playerName)
{
if (!Program.isUsingMono) //Windows Only
{
Thread t = new Thread(new ThreadStart(delegate
{
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create("http://skins.minecraft.net/MinecraftSkins/" + playerName + ".png");
try
{
using (HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse())
{
Bitmap skin = new Bitmap(Image.FromStream(httpWebReponse.GetResponseStream())); //Read skin from network
skin = skin.Clone(new Rectangle(8, 8, 8, 8), skin.PixelFormat); //Crop skin
SetConsoleIcon(skin.GetHicon()); //Set skin as icon
}
}
catch (WebException) //Skin not found? Reset to default icon
{
try
{
SetConsoleIcon(Icon.ExtractAssociatedIcon(Application.ExecutablePath).Handle);
}
catch { }
}
}
));
t.Name = "Player skin icon setter";
t.Start();
}
}
示例14: badge
public void badge(string text)
{
if (Utils.IsBlank(text))
{
TransferController.Instance.TaskbarOverlayIcon(null, String.Empty);
}
else
{
using (Bitmap bm = new Bitmap(16, 16))
using (Graphics g = Graphics.FromImage(bm))
{
g.SmoothingMode = SmoothingMode.AntiAlias;
g.FillEllipse(Brushes.Navy, new Rectangle(0, 0, 15, 15));
if (text.Length == 1)
{
Font f = new Font("Segoe UI", 8, FontStyle.Bold);
g.DrawString(text, f, new SolidBrush(Color.White), 3, 1);
}
else
{
Font f = new Font("Segoe UI", 7, FontStyle.Bold);
g.DrawString(text, f, new SolidBrush(Color.White), 1, 1);
}
TransferController.Instance.TaskbarOverlayIcon(Icon.FromHandle(bm.GetHicon()), text);
}
}
}
示例15: GetEraserCursor
private static Cursor GetEraserCursor()
{
Image fn = ImageResources.GetImageByName("eraser_cursor");
Bitmap bitmap = new Bitmap(fn);
IntPtr handle = bitmap.GetHicon();
Cursor myCursor = new Cursor(handle);
return myCursor;
}