[Offtopic]請原諒我,如果我不夠準確,這是我的第一個問題,我也是編程新手。爲什麼我正在保存的ARGB組件與我從保存的文件中檢索到的組件有區別?
[問題]我想使用Bitmap.SetPixel將位圖(photo,jpg文件)的單個像素的ARGB組件更改爲精確值,並使用Bitmap.Save將其保存到新文件中。不幸的是它沒有奏效。當我重新打開文件時,我想改變的像素(0,0)具有稍微不同的ARGB值。爲什麼發生這種情況?是否有可能創建一個完全符合某個像素所需的ARGB組件的文件?
下面是我的代碼有:
Bitmap originalMap = new Bitmap("image.jpg");
Color current = originalMap.GetPixel(0, 0);
//This one shows the original ARGB values
Console.WriteLine(current);
originalMap.SetPixel(0, 0, Color.FromArgb(255, 100, 100, 100));
originalMap.Save("new.jpg");
//This one shows the result that I want, but the bitmap is not re-opened
Console.WriteLine(originalMap.GetPixel(0, 0));
Bitmap openTheNewFile = new Bitmap("new.jpg");
//The actual result after I open the saved file, A=255, R=108, G=113, B=117
Console.WriteLine(openTheNewFile.GetPixel(0, 0));
爲什麼它的108,113和117,而不是100,100,100?
在此先感謝您的答案,我非常肯定這是一些基本的東西(至少可以這麼說),但它真的讓我困擾。
_jpg ..確切的價值_這些是互斥的。 – TaW
謝謝TaW!下次嘗試對圖像進行這種更改時,我會牢記這一點。 –