我用這個功能來刪除與硒的alpha通道:
public static Bitmap RemoveAlphaChannel(Bitmap bitmapSrc) {
Rectangle rect = new Rectangle(0, 0, bitmapSrc.Width, bitmapSrc.Height);
Bitmap bitmapDest = (Bitmap)new Bitmap(bitmapSrc.Width, bitmapSrc.Height, PixelFormat.Format24bppRgb);
BitmapData dataSrc = bitmapSrc.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
BitmapData dataDest = bitmapDest.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
NativeMethods.CopyMemory(dataDest.Scan0, dataSrc.Scan0, (uint)dataSrc.Stride * (uint)dataSrc.Height);
bitmapSrc.UnlockBits(dataSrc);
bitmapDest.UnlockBits(dataDest);
return bitmapDest;
}
static class NativeMethods {
const string KERNEL32 = "Kernel32.dll";
[DllImport(KERNEL32)]
public extern static void CopyMemory(IntPtr dest, IntPtr src, uint length);
}
這是硒的使用例子:
var screenshot = driver.GetScreenshot();
using(var img = (Bitmap)Bitmap.FromStream(new MemoryStream(screenshot.AsByteArray), false, false)){
RemoveAlphaChannel(img).Save("abcd.png", ImageFormat.Png);
}
你用什麼庫? – 2016-04-14 20:53:25
@sara我正在使用System.Drawing.Imaging和OpenQA.Selenium –