Creating bitmap with IVirtualView

Forum for reporting problems
Post Reply
JM_
Posts: 6
Joined: Tue Aug 27, 2013 7:10 am

Creating bitmap with IVirtualView

Post by JM_ »

Hi
I came across an issue I was hoping to get help with.
I am trying to take a screen capture of KC via the IVirtualView interface with mixed results.
I was able to piece together the following code
{
IVirtualView ivv = (IVirtualView)axPartPicCADFront.GetView();
IBitmap ibmp = null;
PairInt pi;
pi.x = 0;
pi.y = 0;

ivv.Create(ref pi, ref ibmp);
ivv.Render();

IBlob blob = null;
ibmp.GetBitmapData(ref blob);


byte[] byt = new byte[blob.GetSize()];
Array arr = Array.CreateInstance(typeof(byte), blob.GetSize());
blob.CopyTo(ref arr);
Array.Copy(arr, byt, blob.GetSize());

Bitmap bmp = new Bitmap(new MemoryStream(byt));

Graphics g_bmp = Graphics.FromImage(bmp);

IntPtr sourceDC = g_bmp.GetHdc();

IntPtr sourceCDC = CreateCompatibleDC(sourceDC);

IntPtr sourceHB = bmp.GetHbitmap();

IntPtr oldSource = SelectObject(sourceCDC, sourceHB);

//blt from our buffer to the bitmap

BitBlt(dc1, axPartPicCADFront.Parent.Left, axPartPicCADFront.Parent.Top, bmp.Width, bmp.Height, sourceCDC, 0, 0, 13369376);

SelectObject(sourceCDC, oldSource);

DeleteObject(sourceCDC);

DeleteObject(sourceHB);
}

The code executes correctly and I get the expected bitmap.
However, after the code executes the drawing of KC is broken. If the window is resized so that the KC needs to resize the model, the model either stops drawing or clips part of the drawing.
If you significantly shrink the window then restore it, large peicies of the model will not be shown.
After the code is called if I try to rotate or zoom the model an exception is thrown.

I also noticed IVirtualView.Destroy() is missing from the KC .Net control, could this be a related issue?

Thank You

nickz
Site Admin
Posts: 236
Joined: Fri Jul 26, 2013 3:58 am

Re: Creating bitmap with IVirtualView

Post by nickz »

Hi JM_
You seems to be using native windows calls. I think they are causing problems. They are probably locking the DC and the KC window mixes up contexts.

It works in my test if you replace the code below Bitmap bmp = new ...
with:
Graphics gr = pictBox.CreateGraphics();
gr.DrawImage(bmp, 0, 0);

The pictBox is a Picture Box added to display the captured image

It is a good point about the Destroy(). It is implemented but is missing from the declaration. We have posted the 4.3.3738 update which fixes that. The update also has a new C# version of Capture sample which demonstrates this

Nick

Post Reply