hi, every body.
i have succesfull implement the image type converter to convert image type or varbinary type from sql server and vice versa, here is the code, you have any question how to use, please comment
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Drawing;
using System.IO;
namespace NTSoft.Helper.LLBLGen.TypeConverters
{
[Description("Converter with as core type Image, for mapping a field with a .NET type Image onto a byte[] database field")]
public class ImageToByteConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
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 (Image)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 (byte[])cnv.ConvertTo(value, Type.GetType("System.Byte[]"));
}
}
public override object CreateInstance(ITypeDescriptorContext context, System.Collections.IDictionary propertyValues)
{
return new Bitmap(10,10);
//return new byte[0];
// return new byte[1] {0};
//return new byte[]{};
}
}
}