2013-07-20 4 views
0

Windows XP에서 아이콘을 만드는 데 문제가 있습니다.Windows에서 비트 맵 아이콘 만들기 xp

void SaveAsIcon(Bitmap SourceBitmap, string FilePath) 
{ 

      FileStream FS = new FileStream(FilePath, FileMode.Create); 
      // ICO header 
      FS.WriteByte(0); FS.WriteByte(0); 
      FS.WriteByte(1); FS.WriteByte(0); 
      FS.WriteByte(1); FS.WriteByte(0); 

      // Image size 
      FS.WriteByte((byte)SourceBitmap.Width); 
      FS.WriteByte((byte)SourceBitmap.Height); 
      // Palette 
      FS.WriteByte(0); 
      // Reserved 
      FS.WriteByte(0); 
      // Number of color planes 
      FS.WriteByte(0); FS.WriteByte(0); 
      // Bits per pixel 
      FS.WriteByte(32); FS.WriteByte(0); 

      // Data size, will be written after the data 
      FS.WriteByte(0); 
      FS.WriteByte(0); 
      FS.WriteByte(0); 
      FS.WriteByte(0); 

      // Offset to image data, fixed at 22 
      FS.WriteByte(22); 
      FS.WriteByte(0); 
      FS.WriteByte(0); 
      FS.WriteByte(0); 

      // Writing actual data 
      SourceBitmap.Save(FS, ImageFormat.Png); 

      // Getting data length (file length minus header) 
      long Len = FS.Length - 22; 

      // Write it in the correct place 
      FS.Seek(14, SeekOrigin.Begin); 
      FS.WriteByte((byte)Len); 
      FS.WriteByte((byte)(Len >> 8)); 

      FS.Close(); 
} 

비스타 이상에서 작품을 좋아 : 다음은 내 코드입니다.

Windows XP에서 비트 맵에서 아이콘을 만들려면 어떻게해야합니까? Win32에서 리소스를 생성

오류 : 오류 읽기 아이콘

비스타에서

, 7, 작동 팔 난이 오류가 위의

는 내가 방법을 사용 아이콘을하려고하면.

+0

어디서이 오류가 발생합니까? 나는 아이콘이 ico 파일 일 필요가 있다고 생각했다. – Sayse

+0

나는 C#에서 동적 컴파일 중에이 오류가 발생한다. CompilerParameters cp = 새로운 CompilerParameters(); cp.CompilerOptions = "/ optimize/warn : 4/target : winexe /win32icon:icon.ico"; – Yozer

답변

1
SourceBitmap.Save(FS, ImageFormat.Png); 

XP는 PNG 형식의 아이콘을 지원하지 않으므로 Vista 이전에는 해당 기능이 추가되지 않았습니다.

XP 지원이 중요하면 BMP 형식으로 폴백해야합니다. ImageFormat을 변경하는 것만으로는 충분하지 않다는 것을 유의하십시오. 픽셀 형식이 헤더에 쓴 것과 일치해야하며 BITMAPFILEHEADER를 쓰지 않아야합니다. 즉, Save() 메서드가 쓰는 처음 14 바이트를 건너 뜁니다.

+0

내 편집을보세요. – Yozer

+0

당신은 내 대답을 무효화했습니다. 그건 괜찮지 않아, Ask Question 버튼을 다시 클릭하십시오. –

+0

http://stackoverflow.com/questions/17763227/creating-icon-from-bitmap-strange-resizing – Yozer