Graphics

 View Only
  • 1.  Problem with GetCurrentFrame

    Posted 10-13-2012 21:00
    I'm trying to see if I can grab the contents of the current frame on a frame buffer via the API. However, the call to xpOutputFrameBuffer.GetCurrentFrame keeps returning false.

    Is this call limited to physical frame buffers like Matrox and Blackmagic cards, or should it also work with virtual outputs (which is what I'm using)?

    I'm on XPression Developer 4.0 build 2025. Here's a snippet of code... in C#:

    [CODE]

    private xpEngine engine;

    private xpOutputFrameBuffer frameBuffer;

    // in constructor {

    this.engine = new XPression.xpEngine();

    this.engine.GetOutputFrameBuffer(0, out this.frameBuffer);

    // }

    private void button1_Click(object sender, EventArgs e)

    {

    xpImage frame;

    if (this.frameBuffer.GetCurrentFrame(1280, 720, out frame))

    {

    // handle and manipulate current frame

    // this block of code never runs!

    }

    else

    {

    engine.DebugMessage("Unable to retrieve current frame", MessageType.mt_Error);

    // logs this error message every time!

    }

    }

    [/CODE]

    Any suggestions?


  • 2.  RE: Problem with GetCurrentFrame

    Posted 10-15-2012 03:19
    I'm pretty sure this is limited to hardware frame buffers. Maybe you could use xpScene.GetRenderedFrame() which will render a frame from a given xpScene into an xpImage object.

    #XPression


  • 3.  RE: Problem with GetCurrentFrame

    Posted 10-16-2012 02:40
    Any thoughts on how to actually extract a byte array out of an xpImage for use as a Bitmap? No matter what I try, I keep running into an error: Unable to cast object of type 'System.Byte
  • ' to type 'System.Byte[]'

  • Here's some more code:



    [CODE]

    xpScene scene;

    xpImage frame;

    engine.GetSceneByName("MyScene", out scene);

    scene.GetRenderedFrame(scene.DefaultPreviewFrame, scene.Width, scene.Height, out frame);

    byte[] buffer = new byte[frame.Size];

    Array.Copy((byte[])frame.Adapter, (byte[])buffer, frame.Size); // This is where it fails

    MemoryStream memoryStream = new MemoryStream();

    memoryStream.Write(buffer, 0, frame.Size);

    memoryStream.Position = 0L;

    Bitmap image = (Bitmap)Image.FromStream((Stream)memoryStream);



    [/CODE]

    In the debugger, frame.Adapter [I]looks[/I] like an array of bytes, but with a lower bound of 1 instead of 0. I can't even seem to iterate over frame.Adapter with a simple for loop without getting this error.

    The following also fails while trying to copy the byte array (in an attempt to normalize it to a zero-indexed array):



    [CODE]

    ((byte[])frame.Adapter).CopyTo(buffer, 1);



    [/CODE]

    Suggestions?

    #XPression


  • 4.  RE: Problem with GetCurrentFrame

    Posted 10-18-2012 02:28
    Hi Jarrod,

    There is another COM / .NET library called xpTools that contains two methods. One will convert the xpImage to an IPicture and the other can write the xpImage to disk in either TGA/PNG format. Depending on what you need to do one of those two methods should help you out.

    #XPression


  • 5.  RE: Problem with GetCurrentFrame

    Posted 10-18-2012 04:00
    Okay, it's late at night and I'll have to re-check this when I'm more sane in the morning, but tentatively, this code solved my problem:



    [CODE]

    xpEngine engine = new XPression.xpEngine();

    xpTools tools = new xpToolsLib.xpTools();

    engine.GetOutputFrameBuffer(0, out this.frameBuffer);

    private void button1_Click(object sender, EventArgs e)

    {

    xpScene scene;

    xpImage frame;

    engine.GetSceneByName("MyScene", out scene);

    scene.GetRenderedFrame(scene.DefaultPreviewFrame, pictureBox1.Width, pictureBox1.Height, out frame);

    IPicture picture = tools.ImageToPicture(frame);

    pictureBox1.Image = Bitmap.FromHbitmap(new IntPtr(picture.Handle));

    }



    [/CODE]

    I had tried tinkering with the xpTools first thing, but as there wasn't any real documentation, all I could glean was what JetBrains' dotPeek would tell me, which was not enough! Interestingly, dotPeek reported the xpToolsLib dll as having a method called xpImageToBitmap which returns a Bitmap, but as evidenced from the code above, it does not return a Bitmap, but rather an IPicture.

    I'm a little new to Visual Studio (and Windows development), so there may be something funny going on with the assemblies I've referenced in my project.

    Thanks, Brian, for all your help.

    #XPression