2013-06-24 51 views
1

即時通訊使用C#構建應用程序的新內容。我正在處理圖像並與他們分析。點擊圖片後,我得到當前像素的RGB值。接下來將所有值存儲在帶有預覽圖像的列表視圖中。這是我的問題。預覽圖像與當前像素的RGB值不同。如果我對這個相同的圖片框,那麼顏色是正確的。但我不知道如何將pictureboxes實現到listView或listBox。 有我的源代碼,它爲我的顏色預覽創建位圖。C#錯誤的顏色預覽圖像

private Image createImage(Color col) 
    { 
     PixelFormat px_format = PixelFormat.Format32bppRgb; 

     int pixelFormatSize = Image.GetPixelFormatSize(px_format)/8; 
     int stride = 16 * pixelFormatSize; 
     int padding = (stride % 4); 
     stride += padding == 0 ? 0 : 4 - padding; //pad out to multiple of 4 
     SharedPinnedByteArray byteArray = new SharedPinnedByteArray(stride * 16); 
     Bitmap bmp = new Bitmap(16, 16, stride, px_format, byteArray.bitPtr); 
     Graphics gpx = Graphics.FromImage(bmp); 
     SolidBrush brush = new SolidBrush(col); 
     gpx.FillRectangle(brush, 0, 0, 16, 16); 
     gpx.Dispose(); 
     return bmp; 
    } 

這裏是如何即時通話功能,並添加項目的ListView

listView1.SmallImageList.Images.Add(createImage(color)); 
listView1.Items.Add(color.R.ToString() + "," + color.G.ToString() + "," + color.B.ToString() + ",", listView1.SmallImageList.Images.Count - 1); 

問候

加布裏埃爾

+0

它有什麼不同?什麼是分配給'listView1.SmallImageList'的'ImageList'的顏色格式大小? – manji

+1

問題解決了。默認listView顏色深度設置爲8位。我改成了32bit。 – Gapex

+0

是的,這就是我的意思是'顏色深度'。 – manji

回答

0

由於默認的列表視圖色彩深度爲8位,則需要將其更改爲24或32位:

listView1.SmallImageList.ColorDepth = ColorDepth.Depth24Bit;