ali.aghdam
دوشنبه 09 فروردین 1389, 17:48 عصر
دوستان ممنون از توجهتون.
من دارم یه برنامه می نویسم که تو یه تیکش یه آدرس سایت از کاربر می گیره و عکس thumbnail اون سایت رو نشون می ده ولی یه مشکلی هست.
بنده دارم از WebBrowser استفاده می کنم ولی نمی دونم چرا تابع DrawToBitmap رو support نمی کنه ولی تا جایی که می دونم همه کنترلها دارنش (از control به ارث می برن )
اگه کسی راه حلی داره مطرح کنه .
public Bitmap GenerateScreenshot(string url)
{
// This method gets a screenshot of the webpage
// rendered at its full size (height and width)
return GenerateScreenshot(url, -1, -1);
}
public Bitmap GenerateScreenshot(string url, int width, int height)
{
// Load the webpage into a WebBrowser control
WebBrowser wb = new WebBrowser();
wb.ScrollBarsEnabled = false;
wb.ScriptErrorsSuppressed = true;
wb.Navigate(url);
while (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }
// Set the size of the WebBrowser control
wb.Width = width;
wb.Height = height;
if (width == -1)
{
// Take Screenshot of the web pages full width
wb.Width = wb.Document.Body.ScrollRectangle.Width;
}
if (height == -1)
{
// Take Screenshot of the web pages full height
wb.Height = wb.Document.Body.ScrollRectangle.Height;
}
// Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
Bitmap bitmap = new Bitmap(wb.Width, wb.Height);
wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
wb.Dispose();
return bitmap;
}
مشکل اینجاست
wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
من دارم یه برنامه می نویسم که تو یه تیکش یه آدرس سایت از کاربر می گیره و عکس thumbnail اون سایت رو نشون می ده ولی یه مشکلی هست.
بنده دارم از WebBrowser استفاده می کنم ولی نمی دونم چرا تابع DrawToBitmap رو support نمی کنه ولی تا جایی که می دونم همه کنترلها دارنش (از control به ارث می برن )
اگه کسی راه حلی داره مطرح کنه .
public Bitmap GenerateScreenshot(string url)
{
// This method gets a screenshot of the webpage
// rendered at its full size (height and width)
return GenerateScreenshot(url, -1, -1);
}
public Bitmap GenerateScreenshot(string url, int width, int height)
{
// Load the webpage into a WebBrowser control
WebBrowser wb = new WebBrowser();
wb.ScrollBarsEnabled = false;
wb.ScriptErrorsSuppressed = true;
wb.Navigate(url);
while (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }
// Set the size of the WebBrowser control
wb.Width = width;
wb.Height = height;
if (width == -1)
{
// Take Screenshot of the web pages full width
wb.Width = wb.Document.Body.ScrollRectangle.Width;
}
if (height == -1)
{
// Take Screenshot of the web pages full height
wb.Height = wb.Document.Body.ScrollRectangle.Height;
}
// Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
Bitmap bitmap = new Bitmap(wb.Width, wb.Height);
wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
wb.Dispose();
return bitmap;
}
مشکل اینجاست
wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));