开发者

Is there a way to use AwesomiumSharp to create a System.Drawing.Image in memory?

Background is, I'm using XNA, and I render 开发者_JS百科Awesomium to an Image, which I then make a Texture2D from.

The code to render Awesomium to an Image via a file looks something like this:

webView.Render().SaveToPNG("awesomium.png", true);
var image = Image.FromFile("awesomium.png", true);

Which works fine, but it's dog slow (as you can imagine).

Is there a way to use Awesomium to render to a System.Drawing.Image without writing out to the filesystem?


In the end I found my answer in awesomiumdotnet. I guess the official wrapper isn't always the most complete :/

public static class Rbex
{
    public static Bitmap ToBitmap(this RenderBuffer buffer)
    {
        const int depth = 4; 
        const PixelFormat pf = PixelFormat.Format32bppArgb;

        // Create bitmap
        Bitmap bitmap = new Bitmap(buffer.GetWidth(), buffer.GetHeight(), pf);

        BitmapData data = bitmap.LockBits(new Rectangle(0,0, buffer.GetWidth(), buffer.GetHeight()), ImageLockMode.WriteOnly, bitmap.PixelFormat);

        buffer.CopyTo(data.Scan0, buffer.GetWidth() * depth, depth, false);
        bitmap.UnlockBits(data);

        return bitmap;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜