앞에서 설명한 것처럼 비트 맵 파일에는 반드시 팔레트가있을 필요는 없습니다. 사실, 256 색 이상을 가진 현대적인 컬러 파일은 팔레트를 사용하지는 않을 것입니다 (하지만 여전히 생각할 수 있습니다). 대신 색상 정보는 픽셀 값 자체에서 가져옵니다 (팔레트 표를 가리키는 것이 아니라)
(http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/4a10d440-707f-48d7-865b-1d8804faf649/)에서 다음 코드를 발견했습니다. 나는 그것을 테스트하지 못했다. (저자가 "VS 2008 C#에서 테스트를 했는데도 .net 3.5").
는
당신이 비트 맵 팔레트를해야합니다 생각하는 이유 ... (가) 자동으로 색상 수를 축소
[System.Runtime.InteropServices.DllImport("user32.dll")]
extern static bool DestroyIcon(IntPtr handle);
private void buttonConvert2Ico_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog
openFileDialog1.InitialDirectory = "C:\\Data\\\" ;
openFileDialog1.Filter = "BitMap(*.bmp)|*.bmp" ;
openFileDialog1.FilterIndex = 2 ;
openFileDialog1.RestoreDirectory = true ;
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
string sFn = openFileDialog1.FileName;
MessageBox.Show("Filename=" + sFn);
string destFileName = sFn.Substring(0, sFn.Length -3) +"ico";
// Create a Bitmap object from an image file.
Bitmap bmp = new Bitmap(sFn);
// Get an Hicon for myBitmap.
IntPtr Hicon = bmp.GetHicon();
// Create a new icon from the handle.
Icon newIcon = Icon.FromHandle(Hicon);
//Write Icon to File Stream
System.IO.FileStream fs = new System.IO.FileStream(destFileName, System.IO.FileMode.OpenOrCreate);
newIcon.Save(fs);
fs.Close();
DestroyIcon(Hicon);
setStatus("Created icon From=" + sFn + ", into " + destFileName);
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read/write file. Original error: " + ex.Message);
}
}
}
를 처리하는 것? –
@LeeTaylor 두 번째 링크로 인해 첫 번째 링크에서 한스 패스ant의 의견이 있었기 때문에 [MSDN] (http://msdn.microsoft.com/en-us/library/system.drawing.imaging.colorpalette% 28v = vs.100 % 29.aspx). 그러나 내가 틀렸다면 나를 바로 잡습니다. 어떻게 했어? – ispiro
비트 맵에 256 색 이하가 포함 된 경우에만 비트 맵에 팔레트가 있습니다. 따라서 높은 색상의 이미지가있는 경우 픽셀 값은 팔레트 항목과 반대되는 RGB 색상으로 매핑됩니다. –