Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

i have a scenario in which i need to use Binding class but this class constructor

accepts three parameter "propertname,DataSource,Datamember"

but i have only single object a byte[] .i need to set this byte[] in Binding class

and show the result of byte[] in control how it is possible.

//code/////

C#
byte[] image;

mmViewer.DataBindings.Add(new Binding("",image,null))
//here i need to set the image

in binding and show the image in viewer.

Regards,

sajit
Posted

Assuming that the byte array is an image (i.e. has been loaded from a bitmap, or a file containing a supported image format) then just convert it to an Image and pass it through:

C#
MemoryStream ms = new MemoryStream(bytes);
Image myImage = Image.FromStream(ms);
mmViewer.DataBindings.Add(new Binding("",myImage,null));
 
Share this answer
 
Comments
Mazen el Senih 25-Mar-12 15:45pm    
Well you could use this way to convert the image back ,as I do all the time :

Image img = (Image)new ImageConverter().ConvertFrom(bytes);

try it out I'm sure it well be much better and easier ! ;)
sajithnet 25-Mar-12 23:56pm    
thanks,Griff
see my byte[] is of vedio type(.avi) so how can i convert to native format
Hello there ..

To bind an object to any bindable control you can use the easy way they both (the bindable control and source object) should have the same object type for the bindable property !
Ex:

I have a class where it has a property named [Picture] , and have a picture box that I would like to bind it to !
so here is an example code to do this mission :

C#
using System.Drawing;
namespace Test{
    class a
    {
        public a() { }

        private Image picture;
        public Image Picture
        {
            get { return picture; }
            set { picture = value; }
        }
    }
}

// this picture box is on another form class and named pictureBox1

a aTest = new a();
this.pictureBox1.DataBindings.Add("Image", a, "Picture");


hope you get the point , if not type a reply and I will post back as soon as possible.

Cheers and good coding journey ! ;)
 
Share this answer
 
Comments
sajithnet 25-Mar-12 23:56pm    
thanks,Mazen el Senih

see my byte[] is of vedio type(.avi) so how can i convert to native format
Mazen el Senih 26-Mar-12 9:45am    
Well I don't get it , you want to bind an object or convert video to array of bytes ?

any way I suggest these articles to understand the binding classes :

good start in here :
http://www.codeproject.com/Articles/24656/A-Detailed-Data-Binding-Tutorial

and a good example here:
http://www.codeproject.com/Articles/153896/Dynamic-Binding-in-C

but if would like more information about video files and dealing with ,let me know ..

hope you find this useful
Cheers sajithnet !
sajithnet 28-Mar-12 0:14am    
thanks this is what i needed ,thankyou very much
Mazen el Senih 28-Mar-12 15:23pm    
anytime .. glad I could help you :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900