Does someone implement a type converter which converts a byte array into an image and vice versa?
I have these code but it not work
public class ImageToByteConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
// if (sourceType == typeof(byte[]))
switch (sourceType.FullName)
{
case "System.Byte[]":
return true;
default:
return false;
}
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
switch (destinationType.FullName)
{
case "System.Byte[]":
return true;
default:
return false;
}
}
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
if (value == null)
{
return null;
}
else
{
ImageConverter cnv = new ImageConverter();
return cnv.ConvertFrom(value);
}
}
}
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if(value == null) {
return null;
} else {
ImageConverter cnv = new ImageConverter();
return cnv.ConvertTo(value,Type.GetType("System.Byte[]"));
}
}
public override object CreateInstance(ITypeDescriptorContext context, System.Collections.IDictionary propertyValues)
{
return new byte[0];
}