Image.FromFile Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Belirtilen dosyadan bir Image oluşturur.
Aşırı Yüklemeler
FromFile(String) |
Belirtilen dosyadan bir Image oluşturur. |
FromFile(String, Boolean) |
Belirtilen dosyadan, bu dosyaya katıştırılmış renk yönetimi bilgilerini kullanarak bir Image oluşturur. |
FromFile(String)
- Kaynak:
- Image.cs
- Kaynak:
- Image.cs
- Kaynak:
- Image.cs
Belirtilen dosyadan bir Image oluşturur.
public:
static System::Drawing::Image ^ FromFile(System::String ^ filename);
public static System.Drawing.Image FromFile (string filename);
static member FromFile : string -> System.Drawing.Image
Public Shared Function FromFile (filename As String) As Image
Parametreler
Döndürülenler
Bu Image yöntem oluşturur.
Özel durumlar
Dosyanın geçerli bir görüntü biçimi yok.
-veya-
GDI+, dosyanın piksel biçimini desteklemez.
Belirtilen dosya yok.
filename
bir Uri' dir.
Örnekler
Aşağıdaki kod örneğinde ve SetPropertyItem yöntemlerinin FromFileGetPropertyItem nasıl kullanılacağı gösterilmektedir. Bu örnek, Windows Forms ile kullanılmak üzere tasarlanmıştır. Bu örneği çalıştırmak için bir forma yapıştırın ve yöntemini çağırarak formun PaintDemonstratePropertyItem
olayını işleyip e
olarak PaintEventArgsgeçirin.
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 );
}
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);
}
Private Sub DemonstratePropertyItem(ByVal e As PaintEventArgs)
' Create two images.
Dim image1 As Image = Image.FromFile("c:\FakePhoto1.jpg")
Dim image2 As Image = Image.FromFile("c:\FakePhoto2.jpg")
' Get a PropertyItem from image1.
Dim propItem As PropertyItem = 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)
End Sub
Açıklamalar
Yönetilen GDI+, aşağıdaki dosya türlerini destekleyen yerleşik kodlayıcılara ve kod çözücülere sahiptir:
BMP
GIF
JPEG
PNG
TIFF
dosya atılana Image kadar kilitli kalır.
Dosya geçerli bir görüntü biçimine sahip değilse veya GDI+ dosyanın piksel biçimini desteklemiyorsa, bu yöntem bir OutOfMemoryException özel durum oluşturur.
Not
Image sınıfı bit eşlemlerde alfa saydamlığı desteklemez. Alfa saydamlığı etkinleştirmek için piksel başına 32 bit ile PNG görüntüleri kullanın.
Ayrıca bkz.
Şunlara uygulanır
FromFile(String, Boolean)
- Kaynak:
- Image.cs
- Kaynak:
- Image.cs
- Kaynak:
- Image.cs
Belirtilen dosyadan, bu dosyaya katıştırılmış renk yönetimi bilgilerini kullanarak bir Image oluşturur.
public:
static System::Drawing::Image ^ FromFile(System::String ^ filename, bool useEmbeddedColorManagement);
public static System.Drawing.Image FromFile (string filename, bool useEmbeddedColorManagement);
static member FromFile : string * bool -> System.Drawing.Image
Public Shared Function FromFile (filename As String, useEmbeddedColorManagement As Boolean) As Image
Parametreler
- useEmbeddedColorManagement
- Boolean
true
görüntü dosyasına katıştırılmış renk yönetimi bilgilerini kullanacak şekilde ayarlayın; aksi takdirde , false
.
Döndürülenler
Bu Image yöntem oluşturur.
Özel durumlar
Dosyanın geçerli bir görüntü biçimi yok.
-veya-
GDI+, dosyanın piksel biçimini desteklemez.
Belirtilen dosya yok.
filename
bir Uri' dir.
Örnekler
Aşağıdaki kod örneği, yöntemini kullanarak yeni bir bit eşlem elde etme işlemini FromFile gösterir. Ayrıca bir TextureBrushgösterir.
Bu örnek, Windows Forms ile kullanılmak üzere tasarlanmıştır. adlı Button2
düğmeyi içeren bir form İçerik Oluşturucu. Kodu forma yapıştırın ve yöntemini düğmenin Click olayıyla ilişkilendirinButton2_Click
.
private:
void Button2_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
try
{
Bitmap^ image1 = dynamic_cast<Bitmap^>(Image::FromFile( "C:\\Documents and Settings\\"
"All Users\\Documents\\My Music\\music.bmp", true ));
TextureBrush^ texture = gcnew TextureBrush( image1 );
texture->WrapMode = System::Drawing::Drawing2D::WrapMode::Tile;
Graphics^ formGraphics = this->CreateGraphics();
formGraphics->FillEllipse( texture, RectangleF(90.0F,110.0F,100,100) );
delete formGraphics;
}
catch ( System::IO::FileNotFoundException^ )
{
MessageBox::Show( "There was an error opening the bitmap."
"Please check the path." );
}
}
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.");
}
}
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim image1 As Bitmap = _
CType(Image.FromFile("C:\Documents and Settings\" _
& "All Users\Documents\My Music\music.bmp", True), Bitmap)
Dim texture As New TextureBrush(image1)
texture.WrapMode = Drawing2D.WrapMode.Tile
Dim formGraphics As Graphics = Me.CreateGraphics()
formGraphics.FillEllipse(texture, _
New RectangleF(90.0F, 110.0F, 100, 100))
formGraphics.Dispose()
Catch ex As System.IO.FileNotFoundException
MessageBox.Show("There was an error opening the bitmap." _
& "Please check the path.")
End Try
End Sub
Açıklamalar
Yönetilen GDI+, aşağıdaki dosya türlerini destekleyen yerleşik kodlayıcılara ve kod çözücülere sahiptir:
BMP
GIF
JPEG
PNG
TIFF
Dosya geçerli bir görüntü biçimine sahip değilse veya GDI+ dosyanın piksel biçimini desteklemiyorsa, bu yöntem bir OutOfMemoryException özel durum oluşturur.
dosya atılana Image kadar kilitli kalır.
parametresi, useEmbeddedColorManagement
yeninin Image görüntü dosyasına eklenmiş renk yönetimi bilgilerine göre renk düzeltmesi uygulayıp uygulamayacağını belirtir. Ekli bilgiler Uluslararası Renk Konsorsiyumu (ICC) profillerini, gama değerlerini ve kromasite bilgilerini içerebilir.
Not
Image sınıfı bit eşlemlerde alfa saydamlığı desteklemez. Alfa saydamlığı etkinleştirmek için piksel başına 32 bit ile PNG görüntüleri kullanın.