[心得] 用LockBits處理影像時..
剛才de掉一個bug,發現到C#一個特別(or 奇怪o_Oa")的地方..
load進一張8bits的灰階影像,如果用LockBits方法去access image,
coding時可能會被誤認作32bits機會...。
假設執行期間,load進8bits影像後,會經過下面的程式流程..
// FileStream used for reading image file stream
myImageFileNameStream = new FileStream(tempFileName, FileMode.Open);
// object "pictureBox1" created from class PictureBox in .Net
pictureBox1.Image = new Bitmap(myImageFileNameStream);
// test image1
image1 = new Bitmap(myImageFileNameStream);
// test image2
image2 = new Bitmap((Image)image1.Clone());
...
PixelFormat x; // I want to test the pixel formats of image1 and image2
BitmapData bmd = image1.LockBits(new Rectangle(0, 0,
image1.Width, image1.Height),
System.Drawing.Imaging.ImageLockMode.ReadWrite,
x=image1.PixelFormat);
上面 bmd 那四行是用image1
結果 x 的值會是 Format8bppIndexed;
但如果上面那四行是用image2取代image1
那 x 的值就會是 Format32bppRgb 。
心得:真是不方便,不自己debug測看看真的還不知道... XD"
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.116.246.39
討論串 (同標題文章)
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章
7
20