Hi All,
I am working on a sample application where in I am capturing the RGB data of the images of the content rendered on to a form.
This application takes care of resizing the webbrowser setup to appropriate width and height whenever resolution or color depth changes in the system.
I am using IViewObject.Draw funtion to capture the content and LockBits to get the scan pointer. Sample snippet is as below.
[ComImport, Guid("0000010D-0000-0000-C000-000000000046"), InterfaceType((short)1), ComConversionLoss]
public interface IViewObject
{
void Draw([MarshalAs(UnmanagedType.U4)] UInt32 dwDrawAspect,
int lindex,
IntPtr pvAspect,
[In] IntPtr ptd,
IntPtr hdcTargetDev,
IntPtr hdcDraw,
[MarshalAs(UnmanagedType.Struct)] ref _RECTL lprcBounds,
[In] IntPtr lprcWBounds,
IntPtr pfnContinue,
[MarshalAs(UnmanagedType.U4)] UInt32 dwContinue);
}
.....
Object docObj;
IViewObject iView = null;
IntPtr srcPtr;
BitmapData srcData = null;
bitmap = new Bitmap(width, height, pixelFrmt);
srcArea = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
docObj = (Object)webBrowser.Document.DomDocument;
iView = docObj as IViewObject;
iView.Draw(1, -1, (IntPtr)0, (IntPtr)0, (IntPtr)0,
(IntPtr)hdc, ref bounds, (IntPtr)0, (IntPtr)0, 0);
srcData = bitmap.LockBits(srcArea, ImageLockMode.ReadOnly, pixelFrmt);
srcPtr = srcData.Scan0;
This is working fine most of the time. But on changin the resolution or color depth, on few occasions the iView.Draw gives the following exception
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
StackTrace:
at IViewObject.Draw(UInt32 dwDrawAspect, Int32 lindex, IntPtr pvAspect, IntPtr ptd, IntPtr hdcTargetDev, IntPtr hdcDraw, _RECTL& lprcBounds, IntPtr lprcWBounds, IntPtr pfnContinue, UInt32 dwContinue)
I am not able to understand the reason for this. I treid google but didn't get any useful pointers for this issue.
Any help in understanding this issue is really appreciated.
Thanks in advance.
[edit]Code block added, "Treat my content as plain text..." option disabled - OriginalGriff[/edit]