How to use Image type?

Posts   
 
    
chungpn
User
Posts: 39
Joined: 23-Mar-2011
# Posted on: 25-Jul-2011 09:31:14   

What can I do to generate a field like this:

    public virtual System.Drawing.Image Photo
    {
        get { return (System.Drawing.Image)GetValue((int)TblTestFieldIndex.Photo, true); }
        set { SetValue((int)TblTestFieldIndex.Photo, value); }
    }

the Photo field is varbinary type in sql server. Do i need a type converter?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Jul-2011 09:45:20   

I suppose varbinary is mapped to a byte[], correct? So the answer would be, yes you need a type converter, if you need to change that to other type.

chungpn
User
Posts: 39
Joined: 23-Mar-2011
# Posted on: 25-Jul-2011 09:57:39   

if field Photo is mapped to a byte[], it generate code:

public virtual System.Byte[] Photo { get { return (System.Byte[])GetValue((int)TblTestFieldIndex.Photo, true); } set { SetValue((int)TblTestFieldIndex.Photo, value); } } I want it is mapto Image and code generate like this

public virtual System.Drawing.Image Photo { get { return (System.Drawing.Image)GetValue((int)TblTestFieldIndex.Photo, true); } set { SetValue((int)TblTestFieldIndex.Photo, value); } }

Thank you.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Jul-2011 10:56:35   

Use a Type Converter.

chungpn
User
Posts: 39
Joined: 23-Mar-2011
# Posted on: 25-Jul-2011 12:10:48   

Could you please give more details how to do that?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Jul-2011 16:12:29   

Please follow the docs on how to create a type converter. (Implementing a TypeConverter in the SDK documentation). And there you should convert from byte[] to Image and vica versa, for reading and saving.

chungpn
User
Posts: 39
Joined: 23-Mar-2011
# Posted on: 26-Jul-2011 03:06:14   

Thank you Walaa