diff --git a/CefSharp.Core/CefSharp.Core.vcxproj b/CefSharp.Core/CefSharp.Core.vcxproj
index 5a28c9ece..776af7086 100644
--- a/CefSharp.Core/CefSharp.Core.vcxproj
+++ b/CefSharp.Core/CefSharp.Core.vcxproj
@@ -225,6 +225,7 @@
+
@@ -251,6 +252,7 @@
+
diff --git a/CefSharp.Core/CefSharp.Core.vcxproj.filters b/CefSharp.Core/CefSharp.Core.vcxproj.filters
index fb7be235c..d949f6195 100644
--- a/CefSharp.Core/CefSharp.Core.vcxproj.filters
+++ b/CefSharp.Core/CefSharp.Core.vcxproj.filters
@@ -53,6 +53,9 @@
Source Files
+
+ Source Files
+
@@ -130,6 +133,9 @@
Header Files
+
+ Header Files
+
diff --git a/CefSharp.Core/NativeMethodWrapper.cpp b/CefSharp.Core/NativeMethodWrapper.cpp
new file mode 100644
index 000000000..bd82975d2
--- /dev/null
+++ b/CefSharp.Core/NativeMethodWrapper.cpp
@@ -0,0 +1,18 @@
+// Copyright © 2010-2014 The CefSharp Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+
+#pragma once
+
+#include "Stdafx.h"
+#include "NativeMethodWrapper.h"
+
+using namespace System;
+
+namespace CefSharp
+{
+ void NativeMethodWrapper::CopyMemoryUsingHandle(IntPtr^ dest, IntPtr^ src, int numberOfBytes)
+ {
+ CopyMemory(dest->ToPointer(), src->ToPointer(), numberOfBytes);
+ }
+}
diff --git a/CefSharp.Core/NativeMethodWrapper.h b/CefSharp.Core/NativeMethodWrapper.h
new file mode 100644
index 000000000..ea6abbd44
--- /dev/null
+++ b/CefSharp.Core/NativeMethodWrapper.h
@@ -0,0 +1,18 @@
+// Copyright © 2010-2014 The CefSharp Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+
+#pragma once
+
+#include "Stdafx.h"
+
+using namespace System;
+
+namespace CefSharp
+{
+ public ref class NativeMethodWrapper sealed
+ {
+ public:
+ static void CopyMemoryUsingHandle(IntPtr^ dest, IntPtr^ src, int numberOfBytes);
+ };
+}
\ No newline at end of file
diff --git a/CefSharp.OffScreen/ChromiumWebBrowser.cs b/CefSharp.OffScreen/ChromiumWebBrowser.cs
index 8836afca3..c22251ba3 100644
--- a/CefSharp.OffScreen/ChromiumWebBrowser.cs
+++ b/CefSharp.OffScreen/ChromiumWebBrowser.cs
@@ -7,11 +7,8 @@ using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Threading.Tasks;
-using System.Windows;
-using System.Windows.Interop;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
using CefSharp.Internals;
+using PixelFormat = System.Drawing.Imaging.PixelFormat;
namespace CefSharp.OffScreen
{
@@ -360,11 +357,16 @@ namespace CefSharp.OffScreen
bitmap = null;
}
- var stride = bitmapInfo.Width*bitmapInfo.BytesPerPixel;
+ var pixels = bitmapInfo.Width * bitmapInfo.Height;
+ var numberOfBytes = pixels * bitmapInfo.BytesPerPixel;
- bitmap = BitmapSourceToBitmap2(Imaging.CreateBitmapSourceFromMemorySection(bitmapInfo.FileMappingHandle,
- bitmapInfo.Width, bitmapInfo.Height, PixelFormats.Bgra32, stride, 0));
+ bitmap = new Bitmap(bitmapInfo.Width, bitmapInfo.Height, PixelFormat.Format32bppPArgb);
+ var data = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.WriteOnly, PixelFormat.Format32bppPArgb);
+ NativeMethodWrapper.CopyMemoryUsingHandle(data.Scan0, bitmapInfo.BackBufferHandle, numberOfBytes);
+
+ bitmap.UnlockBits(data);
+
var handler = NewScreenshot;
if (handler != null)
{
@@ -373,30 +375,6 @@ namespace CefSharp.OffScreen
}
}
- ///
- /// http://stackoverflow.com/a/5709472/450141
- ///
- /// BitmapSource
- /// Bitmap
- private static Bitmap BitmapSourceToBitmap2(BitmapSource srs)
- {
- var bmp = new Bitmap(
- srs.PixelWidth,
- srs.PixelHeight,
- System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
- var data = bmp.LockBits(
- new Rectangle(System.Drawing.Point.Empty, bmp.Size),
- ImageLockMode.WriteOnly,
- System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
- srs.CopyPixels(
- Int32Rect.Empty,
- data.Scan0,
- data.Height * data.Stride,
- data.Stride);
- bmp.UnlockBits(data);
- return bmp;
- }
-
void IRenderWebBrowser.SetCursor(IntPtr cursor)
{
}
diff --git a/CefSharp.OffScreen/GdiBitmapInfo.cs b/CefSharp.OffScreen/GdiBitmapInfo.cs
index a697abeaf..a6d49e7f7 100644
--- a/CefSharp.OffScreen/GdiBitmapInfo.cs
+++ b/CefSharp.OffScreen/GdiBitmapInfo.cs
@@ -2,18 +2,17 @@
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
-using System.Drawing;
using CefSharp.Internals;
namespace CefSharp.OffScreen
{
public class GdiBitmapInfo : BitmapInfo
{
- public Bitmap Bitmap { get; set; }
+ public bool IsCleared { get; set; }
public override void ClearBitmap()
{
- Bitmap = null;
+ IsCleared = true;
}
}
}