Click here to Skip to main content
15,900,973 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Close window Pin
Sandeep Akhare12-Sep-08 2:34
Sandeep Akhare12-Sep-08 2:34 
GeneralRe: Close window Pin
omlac12-Sep-08 2:58
omlac12-Sep-08 2:58 
GeneralRe: Close window Pin
Sandeep Akhare12-Sep-08 3:04
Sandeep Akhare12-Sep-08 3:04 
GeneralRe: Close window Pin
omlac12-Sep-08 3:17
omlac12-Sep-08 3:17 
QuestionConverting a webpage into an image Pin
K V Sekhar11-Sep-08 20:08
K V Sekhar11-Sep-08 20:08 
AnswerRe: Converting a webpage into an image Pin
metallica_rock1011-Sep-08 21:24
metallica_rock1011-Sep-08 21:24 
GeneralRe: Converting a webpage into an image Pin
K V Sekhar11-Sep-08 21:32
K V Sekhar11-Sep-08 21:32 
AnswerRe: Converting a webpage into an image Pin
K V Sekhar12-Sep-08 1:31
K V Sekhar12-Sep-08 1:31 
I got the logic.

Here is logic i am pasting for others.

Code In VB.Net
==============
Imports Microsoft.VisualBasic
Imports System.Threading
Imports System.Drawing
Imports System.Windows.Forms

Private Class HtmlToImage

Private PageUrl As String
Private ConvertedImage As Bitmap
Private m_intHeight As Integer
Public Property Height() As Integer
Get
Return m_intHeight
End Get
Set(ByVal value As Integer)
m_intHeight = value
End Set
End Property

Private m_intWidth As Integer
Public Property Width() As Integer
Get
Return m_intWidth
End Get
Set(ByVal value As Integer)
m_intWidth = value
End Set
End Property



Public Function ConvertPage(ByVal PageUrl As String) As Bitmap
Me.PageUrl = PageUrl
Dim thrCurrent As New Thread(New ThreadStart(AddressOf CreateImage))
thrCurrent.SetApartmentState(ApartmentState.STA)
thrCurrent.Start()
thrCurrent.Join()
Return ConvertedImage
End Function
Private Sub CreateImage()

Dim BrowsePage As New WebBrowser()
BrowsePage.ScrollBarsEnabled = False
BrowsePage.Navigate(PageUrl)
AddHandler BrowsePage.DocumentCompleted, AddressOf WebBrowser_DocumentCompleted
While BrowsePage.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
End While
BrowsePage.Dispose()
End Sub

Private Sub WebBrowser_DocumentCompleted(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
Dim BrowsePage As WebBrowser = DirectCast(sender, WebBrowser)
BrowsePage.ClientSize = New Size(Width, Height)
BrowsePage.ScrollBarsEnabled = False
ConvertedImage = New Bitmap(Width, Height)
BrowsePage.BringToFront()
BrowsePage.DrawToBitmap(ConvertedImage, BrowsePage.Bounds)

End Sub

End Class
/////////////////////////////


In C#.Net
=========
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Drawing;

namespace HtmlToImage
{
class ImageFromHtml
{
private string PageUrl;
private Bitmap ConvertedImage;

private int m_intHeight;
public int Height
{
get { return m_intHeight; }
set { m_intHeight = value; }
}
private int m_intWidth;
public int Width
{
get { return m_intWidth; }
set { m_intWidth = value; }
}
public Bitmap ConvertPage(string PageUrl)
{
this.PageUrl = PageUrl;
//ThreadStart thrCur = new ThreadStart(new EventHandler(CreateImage));
Thread thrCurrent = new Thread(new ThreadStart(CreateImage));
thrCurrent.SetApartmentState(ApartmentState.STA);
thrCurrent.Start();
thrCurrent.Join();
//ConvertedImage.Save(@"D:\imges.jpg");
return ConvertedImage;
}
private void CreateImage()
{
WebBrowser BrowsePage = new WebBrowser();
BrowsePage.ScrollBarsEnabled = false;
BrowsePage.Navigate(PageUrl);
BrowsePage.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(WebBrowser_DocumentCompleted);

while (BrowsePage.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}

BrowsePage.Dispose();
}
private void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser BrowsePage = (WebBrowser)(sender);
BrowsePage.ClientSize = new Size(Width, Height);
BrowsePage.ScrollBarsEnabled = false;
ConvertedImage = new Bitmap(Width, Height);
BrowsePage.BringToFront();
BrowsePage.DrawToBitmap(ConvertedImage, BrowsePage.Bounds);
}
}
}
//////////////////////////////////////

Using the above Class from code behind.

In widows application:
======================
ImageFromHtml image = new ImageFromHtml();
image.Height = 800;
image.Width = 1020;
Bitmap img = image.ConvertPage("http://www.google.com");//Website name to capture
img.Save(@"D:\imge.jpg");// Save the image in D:\ directory

In Web Application:
===================
//Add the above class in your 'App_Code' direcory of project. Add reference of "System.Threading,System.Windows.Forms,System.Drawing"
//Or Its better to Create a Class Library project for above Class "ImageFromHtml". And add the .dll as reference to your website.

//Place a One button on Form
//In Button_Click Event Write the below code

ImageFromHtml image = new ImageFromHtml();
image.Height = 800;
image.Width = 1020;
Bitmap img = image.ConvertPage(Request.Url.ToString());//This is url of your application which is running.
img.Save(@"D:\imge.jpg"); //Saving image in D directory


Cheers,
sekhar
Questionasp.net page on linux server Pin
Krazy Programmer11-Sep-08 19:42
Krazy Programmer11-Sep-08 19:42 
QuestionCapturing Download Dialog box events using javascript Pin
goradaranaresh11-Sep-08 18:58
goradaranaresh11-Sep-08 18:58 
AnswerRe: Capturing Download Dialog box events using javascript Pin
Steven A. Lowe12-Sep-08 18:27
Steven A. Lowe12-Sep-08 18:27 
Questionhow manage the event hanlder of dynamically created checkbox list Pin
Shaista Shafiq11-Sep-08 17:59
Shaista Shafiq11-Sep-08 17:59 
AnswerRe: how manage the event hanlder of dynamically created checkbox list Pin
Christian Graus11-Sep-08 18:05
protectorChristian Graus11-Sep-08 18:05 
AnswerRe: how manage the event hanlder of dynamically created checkbox list Pin
metallica_rock1011-Sep-08 19:16
metallica_rock1011-Sep-08 19:16 
GeneralRe: how manage the event hanlder of dynamically created checkbox list Pin
Abhijit Jana11-Sep-08 19:29
professionalAbhijit Jana11-Sep-08 19:29 
QuestionUnable to Catch SQLException Pin
salmonraju11-Sep-08 17:51
salmonraju11-Sep-08 17:51 
AnswerRe: Unable to Catch SQLException Pin
Christian Graus11-Sep-08 17:58
protectorChristian Graus11-Sep-08 17:58 
GeneralRe: Unable to Catch SQLException Pin
salmonraju11-Sep-08 18:09
salmonraju11-Sep-08 18:09 
QuestionHow to Create Pagging Like Google Search with datalist Pin
Pr@deep Kr. Sh@rm@11-Sep-08 12:44
Pr@deep Kr. Sh@rm@11-Sep-08 12:44 
AnswerRe: How to Create Pagging Like Google Search with datalist Pin
Christian Graus11-Sep-08 16:45
protectorChristian Graus11-Sep-08 16:45 
GeneralRe: How to Create Pagging Like Google Search with datalist Pin
Ricardo Casquete11-Sep-08 18:10
Ricardo Casquete11-Sep-08 18:10 
Question[Message Deleted] Pin
Omar Gameel Salem11-Sep-08 11:02
professionalOmar Gameel Salem11-Sep-08 11:02 
AnswerRe: Validation controls disable navigation Pin
Christian Graus11-Sep-08 16:46
protectorChristian Graus11-Sep-08 16:46 
AnswerRe: Validation controls disable navigation Pin
dajuanenonli19-Nov-08 22:10
dajuanenonli19-Nov-08 22:10 
Questionconnection string prob, works in VS but not IIS Pin
gerryR.com11-Sep-08 10:55
gerryR.com11-Sep-08 10:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.