作者euleramon (X'mas)
看板C_Sharp
标题[心得] 处理影像..
时间Fri Dec 22 20:33:49 2006
刚才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