I have a problem when getting a blob (which is a bitmap image) from a database table. The blob is saved in a Byte[] and it seems ok when I debug the applicaiton, the array has values (as weel as other properties), but how do I convert the array to a System.Drawing.Bitmap? I guess this is more of a C# question, but any help (example code) is appreciated.
Mapping documents (partial):
Code:
namespace HibTest
{
public class TemplateMapping
{
public TemplateMapping(){
}
public virtual int TemplateId {
set { templateId = value; }
get { return templateId; }
}
public virtual Byte[] BitmapNormal {
set {bitmapNormal = value;}
get {return bitmapNormal;}
}
private int templateId;
private Byte[] bitmapNormal;
};
}
This is what I'm trying to do:Code between sessionFactory.openSession() and session.close():
Code:
TemplateMapping foo = (TemplateMapping)
session.Load(typeof(TemplateMapping), 100);
System.IO.Stream stream = new System.IO.MemoryStream(foo.BitmapNormal, true);
stream.Write(foo.BitmapNormal, 0, foo.BitmapNormal.Length);
Bitmap boo = new Bitmap(stream);
Full stack trace of any exception that occurs:(translated from Swedish)
Code:
System.Runtime.InteropServices.ExternalException: A common error in GDI+.
at System.Drawing.Bitmap..ctor(Stream stream)
at HibTest.Program.Main(String[] args) i C:\slask\HibTest\HibTest\Program.cs:rad 37
Name and version of the database you are using:
Firebird version 2.x
Best regards