Grafis::Metode FromImage (gdiplusgraphics.h)
Metode Graphics::FromImage membuat objek Grafis yang terkait dengan objek Gambar tertentu.
Sintaks
Graphics * FromImage(
[in] Image *image
);
Parameter
[in] image
Jenis: Gambar*
Penunjuk ke objek Gambar yang akan dikaitkan dengan objek Grafis baru.
Menampilkan nilai
Jenis: Grafik*
Metode ini mengembalikan penunjuk ke objek Grafis baru.
Keterangan
Metode ini gagal jika objek Gambar didasarkan pada metafile yang dibuka untuk dibaca. Konstruktor Image::Image(filename, useEmbeddedColorManagement) dan Metafile::Metafile(filename) membuka metafile untuk dibaca. Untuk membuka metafile untuk perekaman, gunakan konstruktor Metafile yang menerima handel konteks perangkat.
Metode ini juga gagal jika gambar memiliki salah satu format piksel berikut:
- PixelFormatUndefined
- PixelFormatDontCare
- PixelFormat1bppIndexed
- PixelFormat4bppIndexed
- PixelFormat8bppIndexed
- PixelFormat16bppGrayScale
- PixelFormat16bppARGB1555
Contoh
Contoh berikut memanggil metode Graphics::FromImage untuk membuat objek Grafis yang terkait dengan objek Gambar . Panggilan ke Grafis::FillEllipse tidak melukis pada perangkat tampilan; sebagai gantinya, ini mengubah bitmap objek Gambar . Panggilan ke Graphics::D rawImage menampilkan bitmap yang diubah.
VOID Example_FromImage(HDC hdc)
{
Graphics graphics(hdc);
// Create an Image object from a PNG file.
Image image(L"Mosaic.png");
// Create a Graphics object that is associated with the image.
Graphics* imageGraphics = Graphics::FromImage(&image);
// Alter the image.
SolidBrush brush(Color(255, 0, 0, 255));
imageGraphics->FillEllipse(&brush, 10, 40, 100, 50);
// Draw the altered image.
graphics.DrawImage(&image, 30, 20);
delete imageGraphics;
}
Persyaratan
Klien minimum yang didukung | Windows XP, Windows 2000 Professional [hanya aplikasi desktop] |
Server minimum yang didukung | Windows 2000 Server [hanya aplikasi desktop] |
Target Platform | Windows |
Header | gdiplusgraphics.h (termasuk Gdiplus.h) |
Pustaka | Gdiplus.lib |
DLL | Gdiplus.dll |