Graphics::FromImage 메서드(gdiplusgraphics.h)

Graphics::FromImage 메서드는 지정된 Image 개체와 연결된 Graphics 개체를 만듭니다.

구문

Graphics * FromImage(
  [in] Image *image
);

매개 변수

[in] image

형식: 이미지*

Graphics 개체와 연결할 Image 개체에 대한 포인터입니다.

반환 값

형식: 그래픽*

이 메서드는 새 Graphics 개체에 대한 포인터를 반환합니다.

설명

Image 개체가 읽기 위해 열린 메타파일을 기반으로 하는 경우 이 메서드가 실패합니다. Image::Image(filename, useEmbeddedColorManagement)Metafile::Metafile(filename) 생성자는 읽기용 메타파일을 엽니다. 기록을 위해 메타파일을 열려면 디바이스 컨텍스트 핸들을 수신하는 메타파일 생성자를 사용합니다.

이미지에 다음 픽셀 형식 중 하나가 있는 경우에도 이 메서드가 실패합니다.

  • PixelFormatUndefined
  • PixelFormatDontCare
  • PixelFormat1bppIndexed
  • PixelFormat4bppIndexed
  • PixelFormat8bppIndexed
  • PixelFormat16bppGrayScale
  • PixelFormat16bppARGB1555

예제

다음 예제에서는 Graphics::FromImage 메서드를 호출하여 Image 개체와 연결된 Graphics 개체를 만듭니다. Graphics::FillEllipse에 대한 호출은 디스플레이 디바이스에 그리기되지 않습니다. 대신 Image 개체의 비트맵을 변경합니다. Graphics::D rawImage에 대한 호출은 변경된 비트맵을 표시합니다.

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;
}

요구 사항

   
지원되는 최소 클라이언트 Windows XP, Windows 2000 Professional [데스크톱 앱만 해당]
지원되는 최소 서버 Windows 2000 Server[데스크톱 앱만]
대상 플랫폼 Windows
헤더 gdiplusgraphics.h(Gdiplus.h 포함)
라이브러리 Gdiplus.lib
DLL Gdiplus.dll

참고 항목

프로그래밍 모델의 변경 내용

FromHDC 메서드

그래픽

그래픽 생성자

그래픽::FromHWND

그래픽::GetHDC

이미지, 비트맵 및 메타파일 사용