We're building a brand new version of the site, and we'd love to hear your ideas
Members
Technology Zones
IBM Learning Center
Articles
Hosted By
Info
|
[4712] Generate an Image of a Web Page
Last post 07-11-2008 4:19 PM by gregcost. 28 replies.
-
-
smarc


- Joined on 01-25-2008
- Estonia

- Points 30
|
Re: [4712] Generate an Image of a Web Page
Actually I have tried to specifically dispose all objects where and whenever possible (even though they are destroyed anyway as soon as the scope they are in is completed) but it makes no difference. The WebBrowser object is created within code and it works fine for me: WebBrowser x = new WebBrowser(); x.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted); x.Navigate("http://www.somesite.com"); Anyways, I have concluded my quest for solution with the conclusion that multiple WebBrowser objects running simultaneously simply create some problems in the underlying framework (IE) that, and at some point (too many simultaneous WebBrowser objects/requests as it's possible in web-server environment), can result in unexpected results. And, that this issue can't be solved from within the calling code.
|
|
Advertisement
|
|
-
-
justncase80


- Joined on 03-11-2008
- United States

- Points 25
|
Re: [4712] Generate an Image of a Web Page
I managed to get the WebBrowser to work off screen too, I'm not sure what fixed it though. I totally buy that multiple WebBrowser controls will cause problems too, makes sense.
However, calling Dispose() explicitly is actually very important. Simply going out of scope isn't good enough, calling dispose will clear up any unmanaged resources and simply going out of scope will cause the GC to only clean up managed resources. It is VERY important to always call dispose on an object implementing IDisposable. Wrap it in a using(IDisposable d = ...) { ... } to make your life easier (so dispose will still get called if there is an exception).
|
|
-
-
-
-
gregcost


- Joined on 08-05-2003
- United States

- Points 65
|
Re: [4712] Generate an Image of a Web Page
Have used this Code for a long time with multiple weBrowser controls without problems but recently I've noticed that FLASH, SIlverlight and other stuff are not being thumbnailed. While most of the standard HTML shows up the newer stuff shows as black spots in the case of FLASH and Styler-sheets with xml, Sliverlight just ends up showing the background color. Standard HTML works fine! Does the DOM/IHTMLELEMENT not carry these nodes or items? Are they carried somewhere else? ANY HELP GREATLY APPRECIATED!
MY VERSION of CODE BELOW VS2005/Net 2.0 - VB.net
Public Enum TernaryRasterOperations SRCCOPY = &HCC0020 ' dest = source SRCPAINT = &HEE0086 ' dest = source OR dest SRCAND = &H8800C6 ' dest = source AND dest SRCINVERT = &H660046 ' dest = source XOR dest SRCERASE = &H440328 ' dest = source AND (NOT dest ) NOTSRCCOPY = &H330008 ' dest = (NOT source) NOTSRCERASE = &H1100A6 ' dest = (NOT src) AND (NOT dest) MERGECOPY = &HC000CA ' dest = (source AND pattern) MERGEPAINT = &HBB0226 ' dest = (NOT source) OR dest PATCOPY = &HF00021 ' dest = pattern PATPAINT = &HFB0A09 ' dest = DPSnoo PATINVERT = &H5A0049 ' dest = pattern XOR dest DSTINVERT = &H550009 ' dest = (NOT dest) BLACKNESS = &H42 ' dest = BLACK WHITENESS = &HFF0062 ' dest = WHITE End Enum
<Guid("3050f669-98b5-11cf-bb82-00aa00bdce0b"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComVisible(True), ComImport()> _ Interface IHTMLElementRender Sub DrawToDC(<[In]()> ByVal hDC As IntPtr)
Sub SetDocumentPrinter(<[In](), MarshalAs(UnmanagedType.BStr)> _ ByVal bstrPrinterName As String, <[In]()> _ ByVal hDC As IntPtr) End Interface
Public Sub Thumb() 'Console.WriteLine("Public Class BrowserThumbnail-Public Sub Thumb|E-- ") Try Dim document As mshtml.IHTMLDocument2 = DirectCast(Myform2.Ax15Form2Browser.Document.DomDocument, mshtml.IHTMLDocument2) Dim element As mshtml.IHTMLElement2 = DirectCast(document.body, mshtml.IHTMLElement2) Dim render As IHTMLElementRender = DirectCast(element, IHTMLElementRender) Dim GraphicsObject As Graphics = Myform2.thumbScr15.CreateGraphics Dim PointerToGraphics As IntPtr = GraphicsObject.GetHdc Dim PointerToDC As IntPtr = CreateCompatibleDC(PointerToDC) Dim PointerToBitmap As IntPtr = CreateCompatibleBitmap(PointerToGraphics, ThumbCopyFromWT, ThumbCopyFromHT) SelectObject(PointerToDC, PointerToBitmap) render.DrawToDC(PointerToDC) GraphicsObject.ReleaseHdc(PointerToGraphics) Dim dummyCallBack As System.Drawing.Image.GetThumbnailImageAbort dummyCallBack = New System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback) Dim fullSizeImg As System.Drawing.Image fullSizeImg = System.Drawing.Image.FromHbitmap(PointerToBitmap) Dim URLfullSizeImg As System.Drawing.Image URLfullSizeImg = System.Drawing.Image.FromHbitmap(PointerToBitmap) Myform2.thumbScr15.Image = fullSizeImg.GetThumbnailImage(ThumbWidth, ThumbSizeHT, dummyCallBack, IntPtr.Zero) URLHistThumbImage15 = URLfullSizeImg.GetThumbnailImage(URLHistImageWD, URLHistImageHT, dummyCallBack, IntPtr.Zero) 'Cleanup CType(GraphicsObject, IDisposable).Dispose() DeleteDC(PointerToDC) DeleteObject(PointerToBitmap) T15Done = True Catch ex As System.NullReferenceException Console.WriteLine("--- NullReferenceException ---" & " " & _ vbCrLf & "Message --- " & ex.Message & " " & _ vbCrLf & "Source --- " & ex.Source & " " & _ vbCrLf & "StackTrace --- " & ex.StackTrace & " " & _ vbCrLf & "TargetSite --- " & ex.TargetSite.ToString) ' Code reacting to NullReferenceException Catch ex As Exception ' Code reacting to any exception Console.WriteLine(vbCrLf & "Message --- " & ex.Message & " " & _ vbCrLf & "Source --- " & ex.Source & " " & _ vbCrLf & "StackTrace --- " & ex.StackTrace & " " & _ vbCrLf & "TargetSite --- " & ex.TargetSite.ToString) End Try
|
|
-
-
alan.dean


- Joined on 04-28-2005

- Points 25
|
Re: [4712] Generate an Image of a Web Page
Greg, Unfortunately, the code is unable to capture Flash or Silverlight and I am not aware of any way around this. Sorry, Alan
|
|
-
-
gregcost


- Joined on 08-05-2003
- United States

- Points 65
|
Re: [4712] Generate an Image of a Web Page
Hi Alan,
I’ve looked around a bit and no one has a solution. I certainly can do a screen capture and thumbnail it that way; unfortunately this is a display and capture mechanism and I lose the benefit of thumb-nailing multiple browsers under the cover.
Do you think it’s possible (under the cover) to navigate to a site, then somehow device context it upon browser completion and thumbnail it from a DC?
Well… maybe not. If I find a way to do this I will certainly post it here.
Thanks Alan,
Greg
|
|
-
-
gregcost


- Joined on 08-05-2003
- United States

- Points 65
|
Re: [4712] Generate an Image of a Web Page
Hi Alan,
Found a timing bug in my project (browser completion was occurring before FLASH was completed) so FLASH now does work, but SilverLight and xsl/parser/xml HTML generated images do not.
It was suggested via MSDN that IHTMLElementRender has problems (misses’ stuff) that could be resolved by using IViewObject’s Draw Function. What I need is a VB.net example of the parameters required by IViewObject:Draw to draw [BELOW--- (DIM) Drawrender to a DC (device Context)]. I been searching all over to find an example but have had no luck… Do you have a VB.net example?
Thanks Alan, Greg
Imports Microsoft.VisualStudio.OLE.Interop
<Guid("0000010D-0000-0000-C000-000000000046")> <InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown), ComVisible(True), ComImport()> _ Interface IViewObject
Sub Draw(ByVal dwDrawAspect As UInteger, _ ByVal lindex As Integer, _ ByVal pvAspect As UInteger, _ ByVal ptd() As Microsoft.VisualStudio.OLE.Interop.DVTARGETDEVICE, _ ByVal hdcTargetDev As UInteger, ByVal hdcDraw As UInteger, _ ByVal lprcBounds() As Microsoft.VisualStudio.OLE.Interop.RECTL, _ ByVal lprcWBounds() As Microsoft.VisualStudio.OLE.Interop.RECTL, _ ByVal pContinue As Microsoft.VisualStudio.OLE.Interop.IContinue)
End Interface
Try Dim document As mshtml.IHTMLDocument2 = DirectCast(Me.WebBrowser1.Document.DomDocument, mshtml.IHTMLDocument2) Dim element As mshtml.IHTMLElement2 = DirectCast(document.body, mshtml.IHTMLElement2)
'Dim render As IHTMLElementRender = DirectCast(element, IHTMLElementRender) Dim Drawrender As IViewObject = DirectCast(element, IViewObject)
Dim GraphicsObject As Graphics = Me.PictureBox1.CreateGraphics Dim PointerToGraphics As IntPtr = GraphicsObject.GetHdc Dim PointerToDC As IntPtr = CreateCompatibleDC(IntPtr.Zero) Dim PointerToBitmap As IntPtr = CreateCompatibleBitmap(PointerToGraphics, Me.WebBrowser1.Width, Me.WebBrowser1.Height)
SelectObject(PointerToDC, PointerToBitmap)
DrawRender.Draw(?????...
'render.DrawToDC(PointerToDC)
|
|
-
-
davepl


- Joined on 06-26-2008
- United States

- Points 15
|
Re: [4712] Generate an Image of a Web Page
I'd love to know the solution, as I'm in the same boat. So if you do figure it out, please post back here to this thread!
The code I came up with is below. However, it faults inside of the Draw call. I'm really not sure if passing an "array of one RECTL" is the right way to handle this interface, which wants a pointer to a RECTL when you're writing it natively. public Image GetHtmlThumbnail(Size size)
{ Image imgThumb = new Bitmap(size.Width, size.Height, PixelFormat.Format24bppRgb);
Rectangle rectDest = new Rectangle(new Point(0, 0), size);_browser.Navigate("about:blank;");
while (_browser.ReadyState != WebBrowserReadyState.Complete)Application.DoEvents();
_browser.DocumentText = aobjData[ DataFormats.Html] as string;Size sizeDocument = Utilities.GetHTMLDocumentSize(_browser.Document);
IViewObjectEx viewObjectEx = _browser.Document.DomDocument as IViewObjectEx;IOleObject oleObject = viewObjectEx as IOleObject;
double xScale = (double)size.Width / (double)sizeDocument.Width;int iPadding = (int)(xScale * System.Windows.Forms.SystemInformation.VerticalScrollBarWidth);
SIZEL sizel;sizel.cx = Utilities.PixelsToHIMETRICX(sizeDocument.Width);sizel.cy = Utilities.PixelsToHIMETRICY(sizeDocument.Height);
// Save away the old size so we can restore it SIZEL [] sizelOld = new SIZEL[1];
oleObject.GetExtent(1, sizelOld); // DVASPECT_CONTENT == 1
using (Graphics g = Graphics.FromImage(imgThumb))
{ RECTL [] rectl = new RECTL[1];
rectl[0].top = 0;
rectl[0].left = 0;
rectl[0].right = size.Width + iPadding; // Extra padding so scrollbar renders outside thumbnail
rectl[0].bottom = size.Height; IntPtr hdc = g.GetHdc();viewObjectEx.Draw(1, -1, 0, null, 0, (uint) hdc, rectl, null, null);
g.ReleaseHdc(hdc);
}
oleObject.SetExtent(1, sizelOld); return null;
}
|
|
-
-
gregcost


- Joined on 08-05-2003
- United States

- Points 65
|
Re: [4712] Generate an Image of a Web Page
Hi Dave I’m working on it.
I have a variation of the code that gets the WebBrowser control from its rendered address passed to the context of the rendered desktop window. This means It works only if the WebBrowser control is displayed on the desktop in a form (Code Below) and it does not matter where the webBrowser control is on the desktop or what is in it XSL/XML, Silverlight whatever. I am trying to figure out how the rendered desktop window gets passed the rendered HTML.
From code below: BitBlt(AddrCreateCompatibleDC, 0, 0, WinWidth, WinHeight, GetWindowDC(Me.WebBrowser1.Handle), 0, 0, SRCCOPY)
StretchBlt(AddrOfPB1, 0, 0, 100, 100, AddrCreateCompatibleDC, 0, 0, Me.WebBrowser1.Width, Me.WebBrowser1.Height, TernaryRasterOperations.SRCCOPY)
Of course this is not what I want and for whatever reason I cannot figure out where the rendered HTML is being stored. So now I am using WinDBG to go through the assembly to find out what address (buffer) all HTML for display are being rendered to before being posted to the screens context! Once I figure this out I’ll write a callable assembler or C++ routine from any .Net language.
I tried to go another route to see what the value of Webbrowse1.handle would be outside of NET so I Marshaled it from the outside back to NET – got the same result. I’ve included the code if you want to play around with it. To use the mshtml._RemotableHandle, a BitBlt call which I have commented out getRHandle(Me.WebBrowser1.Handle) You’ll need the following sub to grap it from outside of NET
------- Public remotableHandle As mshtml._RemotableHandle
'This essentially stores the IntPtr into unmanaged memory and then marshalls it again into a new structure, in this case a _RemotableHandle. Can be used as follows:
Public Function getRHandle(ByVal windowHandle As IntPtr) 'Allocate unmanaged memory to store this IntPtr0 Dim address As IntPtr = Marshal.AllocHGlobal(IntPtr.Size)
'Write the IntPtr into unmanaged memory Marshal.WriteIntPtr(address, windowHandle)
'Return the RemotableHandle by marshalling it from unmanaged memory Return Marshal.PtrToStructure(address, GetType(mshtml._RemotableHandle)) End Function
--------------
Private Structure RECT Dim Left As Integer Dim Top As Integer Dim Right As Integer Dim Bottom As Integer End Structure
Try 'Handle for the desktop window Dim AddrDesktopWindow As IntPtr If AddrDesktopWindow = 0 Then AddrDesktopWindow = GetDesktopWindow
'getWindow Size Dim rcWindow As RECT GetWindowRect(AddrDesktopWindow, rcWindow) Dim WinHeight As Integer = rcWindow.Right - rcWindow.Left Dim WinWidth As Integer = rcWindow.Bottom - rcWindow.Top
Dim PB1 As Graphics = Me.PictureBox1.CreateGraphics Dim AddrOfPB1 As IntPtr = PB1.GetHdc
Dim AddrOfPictureBox1 As IntPtr = Me.PictureBox1.Handle
'create a compatible DC Dim AddrCreateCompatibleDC As IntPtr = CreateCompatibleDC(IntPtr.Zero)
'create a memory bitmap in the DC just created, the size of the window we're capturing Dim AddrCreateCompatibleBitmap As IntPtr = CreateCompatibleBitmap(AddrOfPB1, WinWidth, WinHeight)
'Prepare DC as a Bitmap using selectObject to configure the DC SelectObject(AddrCreateCompatibleDC, AddrCreateCompatibleBitmap)
'copy the screen image into the DC 'BitBlt(AddrCreateCompatibleDC, 0, 0, WinWidth, WinHeight, GetWindowDC(AddrDesktopWindow), 0, 0, SRCCOPY) BitBlt(AddrCreateCompatibleDC, 0, 0, WinWidth, WinHeight, GetWindowDC(Me.WebBrowser1.Handle), 0, 0, SRCCOPY) 'BitBlt(AddrCreateCompatibleDC, 0, 0, WinWidth, WinHeight, getRHandle(Me.WebBrowser1.Handle), 0, 0, SRCCOPY)
'Clone image of PictureBox1 to Picturebox2 when the IMAGE is in the Device Context '#### BitBlt(AddrOfPB1, 0, 0, WinWidth, WinHeight, AddrCreateCompatibleDC, 0, 0, SRCCOPY) StretchBlt(AddrOfPB1, 0, 0, 100, 100, AddrCreateCompatibleDC, 0, 0, Me.WebBrowser1.Width, Me.WebBrowser1.Height, TernaryRasterOperations.SRCCOPY)
PB1.ReleaseHdc(AddrOfPB1) CType(PB1, IDisposable).Dispose() DeleteDC(AddrCreateCompatibleDC) DeleteObject(AddrCreateCompatibleBitmap)
Catch ex As System.NullReferenceException MsgBox("--- NullReferenceException ---" & " " & _ vbCrLf & "Message --- " & ex.Message & " " & _ vbCrLf & "Source --- " & ex.Source & " " & _ vbCrLf & "StackTrace --- " & ex.StackTrace & " " & _ vbCrLf & "TargetSite --- " & ex.TargetSite.ToString) ' Code reacting to NullReferenceException Catch ex As Exception ' Code reacting to any exception MsgBox(vbCrLf & "Message --- " & ex.Message & " " & _ vbCrLf & "Source --- " & ex.Source & " " & _ vbCrLf & "StackTrace --- " & ex.StackTrace & " " & _ vbCrLf & "TargetSite --- " & ex.TargetSite.ToString) End Try End Sub
|
|
-
-
davepl


- Joined on 06-26-2008
- United States

- Points 15
|
Re: [4712] Generate an Image of a Web Page
Thanks! For my appliction the web browser control needs to be offscreen (not on a form), so it won't work for me. I did find one thing interesting, though, which is the the interface definition for IViewObjectEx::Draw that ships in microsoft.visualstudio.ole.interop is wrong. It's missing the last parameter (the DWORD value passed to the continuation function) from the definition of Draw. So when you call it, its going to pop extra bytes off the stack before returning, and will crash. Which it did, so I had to create my own interface definition (with the same guid) and that got it working. That interface is below, in case it helps anyone.
I'm still having a problem that its not drawing anything into my DC, and that's where I'm at right now, debugging the Draw() implementation in mshtml to figure out why...
[ Guid("3AF24292-0C96-11CE-A0CF-00AA00600AB8")] [ComConversionLoss] [InterfaceType(1)] public interface IViewObjectExDave { void Draw(uint dwDrawAspect, int lindex, uint pvAspect, DVTARGETDEVICE[] ptd, uint hdcTargetDev, uint hdcDraw, RECTL[] lprcBounds, RECTL[] lprcWBounds, IContinue pContinue, uint x);
// etc, rest of methods
}
|
|
-
-
gregcost


- Joined on 08-05-2003
- United States

- Points 65
|
Re: [4712] Generate an Image of a Web Page
OK, I FINALLY GOT IT TO WORK…..OFFSCREEN with SilverLight and XSL/XML EXCEPT SHOCKWAVE FLASH!
At least I have a way to call Alan's routine when I detect a non-Flash HTML screen and now use IViewObject Draw when I have a Silverlight or xml/xsl css gened screen. AGAIN all this works off Screen!
Unfortunately as far as I can tell IViewObject is incompatible with trying to DirectCast it down to the element as in Alan's code so, while I now have a dual solution (with some upfront HTML parsing) I will keep looking into a single step solution.
After looking at WinDbg and screwing around with memory addresses. I finally got it to write off screen using IViewObject Draw function to a DC and then to a thumbnail. What a pain this was!
I had to use StretchBlt to grab it from the DC to shrink it down to a 100 by 100 thumbnail. I do not like the way StretchBlt renders it. The thumbnail is grainy and not as clear as Alan’s original FromBitmap code. BUT for NOW ENOUGH IS ENOUGH! I’ll screw with that later… ( I now have replace StretchBlt see my next reply)
The Following CODE will write the rendered HTML screen from its memory location (not the form on the Desktop) and post it to a DEVICE COINTEXT. It works WITH SILVERLIGHT and XSL/XML. From the DC I use StretchBlt (will change that) to shrink it to the Picturebox 100 by 100 thumb.
<ComImport(), _ InterfaceType(ComInterfaceType.InterfaceIsIUnknown), _ Guid("00000127-0000-0000-C000-000000000046")> _ Public Interface IViewObject Function Draw(ByVal dwDrawAspect As Int32, _ ByVal lindex As Int32, _ ByVal pvAspect As IntPtr, _ ByVal ptd As IntPtr, _ ByVal hicTargetDev As Int32, _ ByVal hdcDraw As IntPtr, _ ByVal prcBounds As IntPtr, _ ByVal prcWBounds As RectangleF, _ ByVal fnContinue As IntPtr, _ ByVal dwContinue As Int32) As Int32 End Interface
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim ViewObject As IViewObject = DirectCast(Me.WebBrowser1.Document.DomDocument, IViewObject)
Dim PB1 As Graphics = Me.PictureBox1.CreateGraphics Dim AddrOfPB1 As IntPtr = PB1.GetHdc
'create a compatible DC Dim AddrCreateCompatibleDC As IntPtr = CreateCompatibleDC(IntPtr.Zero)
'create a memory bitmap in the DC just created, the size of the window we're capturing Dim AddrCreateCompatibleBitmap As IntPtr = CreateCompatibleBitmap(AddrOfPB1, Me.WebBrowser1.Width, Me.WebBrowser1.Height)
'Prepare DC as a Bitmap using selectObject to configure the DC SelectObject(AddrCreateCompatibleDC, AddrCreateCompatibleBitmap)
'Draw the Rendered DomDocument to the Device Context ViewObject.Draw(1, 1, Nothing, Nothing, 0, AddrCreateCompatibleDC, Nothing, Nothing, Nothing, 0)
'Use StretchBlt to shrink it down to the Theubnail StretchBlt(AddrOfPB1, 0, 0, 100, 100, AddrCreateCompatibleDC, 0, 0, Me.WebBrowser1.Width, Me.WebBrowser1.Height, TernaryRasterOperations.SRCCOPY)
'Dim fullSizeImg As System.Drawing.Image 'fullSizeImg = System.Drawing.Image.FromHbitmap(AddrCreateCompatibleBitmap)
PB1.ReleaseHdc(AddrOfPB1) CType(PB1, IDisposable).Dispose() DeleteDC(AddrCreateCompatibleDC) DeleteObject(AddrCreateCompatibleBitmap)
Catch ex As System.NullReferenceException MsgBox("--- NullReferenceException ---" & " " & _ vbCrLf & "Message --- " & ex.Message & " " & _ vbCrLf & "Source --- " & ex.Source & " " & _ vbCrLf & "StackTrace --- " & ex.StackTrace & " " & _ vbCrLf & "TargetSite --- " & ex.TargetSite.ToString) ' Code reacting to NullReferenceException Catch ex As Exception ' Code reacting to any exception MsgBox(vbCrLf & "Message --- " & ex.Message & " " & _ vbCrLf & "Source --- " & ex.Source & " " & _ vbCrLf & "StackTrace --- " & ex.StackTrace & " " & _ vbCrLf & "TargetSite --- " & ex.TargetSite.ToString) End Try
End Sub
|
|
-
-
gregcost


- Joined on 08-05-2003
- United States

- Points 65
|
Re: [4712] Generate an Image of a Web Page
Ok just replace StretchBlt with. Not sure why this was not working before? other than I was up very late and just couldn't see straight.. Dim fullSizeImg As System.Drawing.Image
fullSizeImg = System.Drawing.Image.FromHbitmap(AddrCreateCompatibleBitmap)
Me.PictureBox1.Image = fullSizeImg.GetThumbnailImage(100, 100, Nothing, IntPtr.Zero)
|
|
-
-
gregcost


- Joined on 08-05-2003
- United States

- Points 65
|
Re: [4712] Generate an Image of a Web Page
Ok, this is the final version – and final comments.
IViewObjectDraw is now my standard. When the HTML text is converted into a rendered image sitting in memory and available to be moved to the desktop form’s screen buffer for display, … for whatever reason IVewObject.Draw will do a better job of picking up all of the pieces at whatever addresses they are stored at giving me an off-screen image (using the screen’s device context) to thumbnail from.
I now use the original IHTMLElement.DrawToDc to pickup the only item (so far) the “Adobe Shockwave embedded player” the rest can be handled by IViewObject.Draw – flash, xsl/css, silverlight, etc. It’s now a simple matter of searching the HTML document text looking for Adobe Shockwave and calling the original IHTMLElement.DrawToDc.
It is kind of a pain to do it this way because I must pre-check for Shcokwave, but the overhead with some reduced instruction tricks is reasonable… Also IViewObject code seems faster
Greg
Public Sub IviewDrawStyleThumb1() Try Dim ViewObject As IViewObject = DirectCast(Myform2.Ax1Form2Browser.Document.DomDocument, IViewObject)
Dim PB1 As Graphics = Myform2.thumbScr1.CreateGraphics Dim AddrOfPB1 As IntPtr = PB1.GetHdc
'create a compatible DC Dim AddrCreateCompatibleDC As IntPtr = CreateCompatibleDC(IntPtr.Zero)
'create a memory bitmap in the DC just created, the size of the window we're capturing Dim AddrCreateCompatibleBitmap As IntPtr = CreateCompatibleBitmap(AddrOfPB1, ThumbCopyFromWT, ThumbCopyFromHT)
'Prepare DC as a Bitmap using selectObject to configure the DC SelectObject(AddrCreateCompatibleDC, AddrCreateCompatibleBitmap)
'Draw the Rendered DomDocument to the Device Context ViewObject.Draw(1, 1, Nothing, Nothing, 0, AddrCreateCompatibleDC, Nothing, Nothing, Nothing, 0)
Dim fullSizeImg1 As System.Drawing.Image fullSizeImg1 = System.Drawing.Image.FromHbitmap(AddrCreateCompatibleBitmap) Myform2.thumbScr1.Image = fullSizeImg1.GetThumbnailImage(ThumbWidth, ThumbSizeHT, Nothing, IntPtr.Zero)
Dim URLfullSizeImg As System.Drawing.Image URLfullSizeImg = System.Drawing.Image.FromHbitmap(AddrCreateCompatibleBitmap) URLHistThumbImage1 = URLfullSizeImg.GetThumbnailImage(URLHistImageWD, URLHistImageHT, Nothing, IntPtr.Zero)
PB1.ReleaseHdc(AddrOfPB1) CType(PB1, IDisposable).Dispose() DeleteDC(AddrCreateCompatibleDC) DeleteObject(AddrCreateCompatibleBitmap)
T1Done = True
Catch ex As System.NullReferenceException MsgBox("--- NullReferenceException ---" & " " & _ vbCrLf & "Message --- " & ex.Message & " " & _ vbCrLf & "Source --- " & ex.Source & " " & _ vbCrLf & "StackTrace --- " & ex.StackTrace & " " & _ vbCrLf & "TargetSite --- " & ex.TargetSite.ToString) ' Code reacting to NullReferenceException Catch ex As Exception ' Code reacting to any exception MsgBox(vbCrLf & "Message --- " & ex.Message & " " & _ vbCrLf & "Source --- " & ex.Source & " " & _ vbCrLf & "StackTrace --- " & ex.StackTrace & " " & _ vbCrLf & "TargetSite --- " & ex.TargetSite.ToString) End Try
End Sub
|
|
|
Search
Code Samples
New Members
|