Graphics.FromImage(Image) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
public:
static System::Drawing::Graphics ^ FromImage(System::Drawing::Image ^ image);
public static System.Drawing.Graphics FromImage(System.Drawing.Image image);
static member FromImage : System.Drawing.Image -> System.Drawing.Graphics
Public Shared Function FromImage (image As Image) As Graphics
매개 변수
반환
이 메서드는 지정된 Image대한 새 Graphics 반환합니다.
예외
image
null.
image 인덱싱된 픽셀 형식이 있거나 해당 형식이 정의되지 않았습니다.
예제
다음 코드 예제는 Windows Forms에서 사용하도록 설계되었으며 Paint 이벤트 처리기의 매개 변수인 PaintEventArgse필요합니다. 코드는 다음 작업을 수행합니다.
public:
void FromImageImage( PaintEventArgs^ e )
{
// Create image.
Image^ imageFile = Image::FromFile( "SampImag.jpg" );
// Create graphics object for alteration.
Graphics^ newGraphics = Graphics::FromImage( imageFile );
// Alter image.
newGraphics->FillRectangle( gcnew SolidBrush( Color::Black ), 100, 50, 100, 100 );
// Draw image to screen.
e->Graphics->DrawImage( imageFile, PointF(0.0F,0.0F) );
// Dispose of graphics object.
delete newGraphics;
}
private void FromImageImage(PaintEventArgs e)
{
// Create image.
Image imageFile = Image.FromFile("SampImag.jpg");
// Create graphics object for alteration.
Graphics newGraphics = Graphics.FromImage(imageFile);
// Alter image.
newGraphics.FillRectangle(new SolidBrush(Color.Black), 100, 50, 100, 100);
// Draw image to screen.
e.Graphics.DrawImage(imageFile, new PointF(0.0F, 0.0F));
// Dispose of graphics object.
newGraphics.Dispose();
}
Private Sub FromImageImage2(ByVal e As PaintEventArgs)
' Create image.
Dim imageFile As Image = Image.FromFile("SampImag.jpg")
' Create graphics object for alteration.
Dim newGraphics As Graphics = Graphics.FromImage(imageFile)
' Alter image.
newGraphics.FillRectangle(New SolidBrush(Color.Black), _
100, 50, 100, 100)
' Draw image to screen.
e.Graphics.DrawImage(imageFile, New PointF(0.0F, 0.0F))
' Dispose of graphics object.
newGraphics.Dispose()
End Sub
설명
이미지에 인덱싱된 픽셀 형식이 있는 경우 이 메서드는 "그래픽 개체는 인덱싱된 픽셀 형식의 이미지에서 만들 수 없습니다."라는 메시지와 함께 예외를 throw합니다. 인덱싱된 픽셀 형식은 다음 목록에 표시됩니다.
Save(String, ImageFormat) 메서드를 사용하여 인덱싱된 이미지를 다른 형식으로 저장한 다음 새 이미지에 대한 Graphics 개체를 검색할 수 있습니다.
이 메서드는 이미지에 다음 픽셀 형식이 있는 경우에도 예외를 throw합니다.
항상 Dispose 메서드를 호출하여 FromImage 메서드에서 만든 Graphics 및 관련 리소스를 해제해야 합니다.
적용 대상
추가 정보
- 방법: 런타임에 비트맵 만들기
- 이미지, 비트맵, 아이콘 및 메타파일 작업
- 방법: 그리기 그래픽 개체 만들기