本文整理汇总了C#中System.Drawing.Image.FromFile方法的典型用法代码示例。如果您正苦于以下问题:C# Image.FromFile方法的具体用法?C# Image.FromFile怎么用?C# Image.FromFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Image
的用法示例。
在下文中一共展示了Image.FromFile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DemonstratePropertyItem
private void DemonstratePropertyItem(PaintEventArgs e)
{
// Create two images.
Image image1 = Image.FromFile("c:\\FakePhoto1.jpg");
Image image2 = Image.FromFile("c:\\FakePhoto2.jpg");
// Get a PropertyItem from image1.
PropertyItem propItem = image1.GetPropertyItem(20624);
// Change the ID of the PropertyItem.
propItem.Id = 20625;
// Set the PropertyItem for image2.
image2.SetPropertyItem(propItem);
// Draw the image.
e.Graphics.DrawImage(image2, 20.0F, 20.0F);
}
示例2: Button2_Click
private void Button2_Click(System.Object sender, System.EventArgs e)
{
try
{
Bitmap image1 = (Bitmap) Image.FromFile(@"C:\Documents and Settings\" +
@"All Users\Documents\My Music\music.bmp", true);
TextureBrush texture = new TextureBrush(image1);
texture.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile;
Graphics formGraphics = this.CreateGraphics();
formGraphics.FillEllipse(texture,
new RectangleF(90.0F, 110.0F, 100, 100));
formGraphics.Dispose();
}
catch(System.IO.FileNotFoundException)
{
MessageBox.Show("There was an error opening the bitmap." +
"Please check the path.");
}
}
示例3: Image.FromFile(String path)
/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury,
Zach Greenvoss, Shripad Kulkarni, Neil Whitlow
Publisher: Peer Information
ISBN: 1861007663
*/
// Change the path(s) if needed. If you have VS.NET write:
// "..\\..\\Altamira5.bmp" or @"..\..\Altamira5.bmp"
// otherwise
// "Altamira5.bmp"
// and compile with:
// csc Altamira.cs
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Altamira
{
public class Altamira1 : Form
{
Pen p;
SolidBrush b, bT = new SolidBrush(Color.Black);
string path = "Altamira5.bmp"; // change the path if needed
Image im;
Font f;
public Altamira1()
{
InitializeComponent();
MyIni();
}
private void InitializeComponent()
{
this.SuspendLayout();
this.ClientSize = new System.Drawing.Size(290, 260);
this.Text = "Altamira";
this.ResumeLayout(false);
}
private void MyIni()
{
Color cP = Color.Gray;
Color cB = Color.LightGray;
p = new Pen(cP, 6);
b = new SolidBrush(cB);
im = Image.FromFile(path);
f = new Font(new FontFamily("Times New Roman"), 10);
}
static void Main()
{
Application.Run(new Altamira1());
}
protected override void OnPaint(PaintEventArgs pea)
{
Sketch();
//SketchDBuf();
}
private void Sketch()
{
Graphics g = Graphics.FromHwnd(this.Handle); // <=> g = CreateGraphics();
g.FillRectangle(b, 4, 4, 260, 220); // passe-partout
g.DrawRectangle(p, 4, 4, 260, 220); // frame
g.DrawImage(im, 33, 35, 200, 145 ); // image
g.DrawString("ALTAMIRA", f, bT, 180, 190); // text
g.Dispose();
}
private void SketchDBuf()
{
int hh = 3, w = 260, h = 220;
Graphics g;
Bitmap bm = new Bitmap(w + 2*hh, h + 2*hh);
g = Graphics.FromImage(bm); // buffer graphics
g.FillRectangle(b, hh , hh, w, h); // passe-partout
g.DrawRectangle(new Pen(Color.Gray, 2*hh), hh, hh, w, h); // frame
g.DrawImage(im, hh + 30, hh + 32, 200, 145); // image
g.DrawString("ALTAMIRA", f, bT, 180, 190); // text
g = Graphics.FromHwnd(this.Handle); // real graphics
g.DrawImage(bm, 1, 1);
g.Dispose();
}
}
}