struggling to get image in picturebox ... please help !!!!!

  • Thread starter Thread starter sandy_pt_in
  • Start date Start date
S

sandy_pt_in

Hi plz plz plz help me .... i am struggling to get image in
picturebox. I am writing code in C# to display image in a
picturebox.To do this I am calling function from VC++ dll which is
provided by the third party.
function call in dll is somthing like this
DrawImage(Hdc,Rect); // function in VC++ dll

Here I have created RECT structrue in C# which is similar to VC++ RECT
and passing that as a second argument in DrawImage funciton.But
problem is creating
device context !!! As pictureBox in a C# does not have hdc I wrote
following code to get Device Context

objFusion.m_hdc= GetDC(pictureBox1.Handle);

//where objFusion is obj which calls DrawImage function from the dll

it didnot didnot work... can you please help on this?? probably can
you give me some sample code or line where i can get this information.
 
The PictureBox is not a placeholder for graphics that you might want to
draw. It displays pictures.

You should create an image of the correct size and then draw into that
before putting it into the picture box.

Use Graphics.GetHdc and Graphics.ReleaseHdc to obtain and release the GDI DC
from the image.

Something like this...

Bitmap bm=new Bitmap(xSize, ySize);
Graphics g=Graphics.FromImage(bm);
IntPtr hDC=g.GetHdc();
Rect r=new Rect(......); //however you wrote your rect...
DrawImage(hCD,r); //calls your C++ DLL...
g.ReleaseDC(hDC);
g.Dispose();
pictureBox1.Image=bm;

--
Bob Powell [MVP]
Visual C#, System.Drawing

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml
 
Hi bob thanks for replying... I tried as you told but still things are
not working I am sending you my code snippet... we are programming for
Video system .Program should not continously read video framed from
DVR and it should display in picturebox. To read video frames from DVR
(digital video recorder) and draw it on the form we are using the VC++
dll file i mentioned.I am sneidng my code here

here objFusion is written to call some other function of dll here
all...
DrawLiveImage Funcion gets image from dvr and draw it on the form...to
this function we are passing hdc, rect, conneciton handle and camera
number.

This function i am writing in WndProc of form...so that each time i
get new frame message i can display it in the picture box... i hope
you got clear idea now.


objFusion.m_Rect = pictureBox1.ClientRectangle; //Initialize
client rectangle area;
Bitmap bm = new Bitmap(pictureBox1.Height,pictureBox1.Width);
gfx = Graphics.FromImage(bm);
objFusion.m_hdc = gfx.GetHdc();
Int32 a = DrawLiveImage(objFusion.ConHandle,3,objFusion.m_hdc,ref
rect);
if(a !=0)
{
MessageBox.Show(a.ToString());
}

gfx.ReleaseHdc(objFusion.m_hdc);
gfx.Dispose();
bm.Save("C:\\quality1.jpg");

pictureBox1.Image = bm;
 
I would strongly recommend that you look as DirectX as being the vehicle of
choice for your video app.

You can easily steal the area of a panel or something and forget about that
accursed picturebox control. DirectX 9 will be much simpler and more in line
with the performance requirements of your application.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml
 
Thanks Bob my applicatoin with picturebox is working fine.. But video
is running in slow motion... :)... If you think that this problem
could be solved with directx we can go for it...Can you suggest me
some links or books where i could get information about using DirectX
in C#.I went through your site.I liked the way you explained concepts
of GDI+.Have you written any of such articals that i can read....I am
very new to grpahics design and .net...such aritcals will be helpful
 
Back
Top