2014년 4월 15일 화요일

C# 에서 A Graphics object cannot be created from an image that has an indexed pixel format. 에러 발생시

Tif 이미지를 불러 와서 편집할려고 하는데.

Graphics graphics = Graphics.FromImage(img);

에서

A Graphics object cannot be created from an image that has an indexed pixel format.

라는 에러가 발생한다.
구글링 해보니, GDI+ 에서 indexed Image 를 지원하지 않는다고 한다.
좀 난감하지만,

private void fnImageLoad()
{
    Bitmap Tmp = new Bitmap(@"D:\MyProgramming\map.tiff");
    img = new Bitmap(Tmp, Tmp.Width, Tmp.Height);

    pictureBox1.Invalidate();
}

로 간단히 처리된다.
참고로, 특별히 이미지 양식을 지정해 주지 않으면, "PixelFormat.Format32bppArgb" 로 지정된다.