我有一個問題,我有一個方法,需要一個圖像對象,處理它到1個顏色通道(其他2個是純黑色),然後從該過程返回一個新的圖像。方法不正確地返回圖像對象c#.Net
現在我遇到的問題是,當我在方法中創建新圖像,並在調試過程中查看對象時,圖像對象顯得非常好。但是當我返回一個空的圖像對象即Image對象裏面的屬性都秀「System.ArgumentException」
這裏是方法的代碼:
public Image GetRedImage(Image sourceImage)
{
using (Bitmap bmp = new Bitmap(sourceImage))
using (Bitmap redBmp = new Bitmap(sourceImage.Width, sourceImage.Height))
{
for (int x = 0; x < bmp.Width; x++)
{
for (int y = 0; y < bmp.Height; y++)
{
Color pxl = bmp.GetPixel(x, y);
Color redPxl = Color.FromArgb((int)pxl.R, 1, 1);
redBmp.SetPixel(x, y, redPxl);
}
}
Image tout = (Image)redBmp;
return tout;
}
}
任何人有任何想法上什麼是地獄正在進行?
非常感謝。
*咧嘴* 三江源所有您的幫助(尤其是達維德) 返回正確現在 很多很多的感謝 – Gelion
再投答案,並接受你認爲最好的一個;-) –