【发布时间】:2011-10-26 07:37:14
【问题描述】:
我正在尝试在 WPF/c# 中使用 geckoFX 创建网站的图像。运行代码时出现错误。
error 是使用 geckoWebBorwser (int)wWidth 和 (int) wHeight 的位图宽度和高度 错误文本是(参数无效)和 System.ArgumentException
在线出错
Bitmap bmp = new Bitmap(wWidth, wHeight); //Error here (Parameter is not valid.
System.ArgumentException)
示例代码:
class GetWebCapture
{
public static BitmapSource GetThumb(Skybound.Gecko.GeckoWebBrowser wb, int w, int h, int wWidth, int wHeight)
{
if (wb != null)
{
Bitmap bmp = new Bitmap(wWidth, wHeight);
Rectangle rec = new Rectangle(0, 0, wWidth, wHeight);
Rectangle rec1 = new Rectangle(0, 0, w, h);
wb.DrawToBitmap(bmp, rec);
Graphics gfx = Graphics.FromImage(bmp);
gfx.CompositingQuality = CompositingQuality.HighQuality;
gfx.SmoothingMode = SmoothingMode.HighQuality;
gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
gfx.DrawImage(bmp, rec);
Bitmap newImage = new Bitmap(290, 200);
using (Graphics gr = Graphics.FromImage(newImage))
{
gr.SmoothingMode = SmoothingMode.AntiAlias;
gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
gr.DrawImage(bmp, new Rectangle(0, 0, 290, 200));
}
BitmapSource source = loadBitmaps(newImage);
gfx.Dispose();
bmp.Dispose();
return source;
}
else
{
return null;
}
public static BitmapSource loadBitmaps(System.Drawing.Bitmap source)
{
return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(source.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
}
}
使用 WebKit.Net 这个方法很好用,用 IE webBrowser 我有不同的方法,这个方法很好用,但是它们不适合我的项目。
【问题讨论】:
-
你得到什么错误?请通过编辑您的帖子提供更多信息。为了更好地阅读,我已经对其进行了一些修改
-
能否提供参数值?
标签: c# browser thumbnails geckofx