| 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)
{
}
}
|