For Programmers: Free Programming Magazines  


Home > Archive > C# > August 2004 > binding images









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author binding images
miguel.ossa

2004-08-21, 4:02 am

Hello,

How must I do to bind a picture with a picture box?

When I tried it, I get an invalid typecast exception.

Binding ImageBinding;
ImageBinding = new Binding("Image", dsRadiografias, "RADIOGRAFIAS.rad_imagen");
ImageBinding.Format += new ConvertEventHandler(this.PictureFormat);
picRadiografia.DataBindings.Add(ImageBinding);

I was trying with this conversion routine, with no good results:

void PictureFormat(Object sender, ConvertEventArgs e)
{
try
{
Byte[] img = (Byte[]) e.Value;
// Perform the conversion
MemoryStream ms = new MemoryStream();
int offset = 0; // should be 0
ms.Write(img, offset, img.Length - offset);
Bitmap bmp = new Bitmap(ms);
ms.Close();

// Writes the new value back
e.Value = bmp;
}
catch(Exception)
{
}
}
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com