2012-06-05 54 views
2

我嘗試過研究,但似乎在ASP.NET中沒有解決方案,只有webforms等。如何隱藏ASP.NET中的RGB通道之一?

例如,我可以爲.jpg隱藏RGB通道(比如說只有RED通道)嗎?

+2

「隱藏」是什麼意思?用另一種顏色替換它? – Magnus

+0

不,我的意思是讓它變成0(255)。例如:red = 0; – thormayer

回答

1
using(var bmp = new Bitmap("C:\\temp\\source.jpg")) 
{ 
    for (int x = 0; x < bmp.Width; x++) 
    for (int y = 0; y < bmp.Height; y++) 
    { 
     var c = bmp.GetPixel(x, y); 
     bmp.SetPixel(x, y, Color.FromArgb(c.A, 0, c.G, c.B)); 
    } 
    bmp.Save("C:\\temp\\target.jpg", ImageFormat.Jpeg); 
} 
+0

如果我嘗試運行這個東西,它會得到一個異常:「GDI +發生了一個通用錯誤」。在「ImageFormat.Jpeg」事件 – thormayer

+1

@thormayer:我使用控制檯應用程序測試它,它的工作原理。它可能不適用於您的寫入權限。 –

+0

@thormayer是的,它最有可能是一個許可的事情。如果從ASP應用程序運行此應用程序,運行應用程序池的用戶帳戶必須具有該目錄的權限。 – Magnus