Business object mapper and images


Author
Message
GRocchi
GRocchi
StrataFrame Beginner (48 reputation)StrataFrame Beginner (48 reputation)StrataFrame Beginner (48 reputation)StrataFrame Beginner (48 reputation)StrataFrame Beginner (48 reputation)StrataFrame Beginner (48 reputation)StrataFrame Beginner (48 reputation)StrataFrame Beginner (48 reputation)StrataFrame Beginner (48 reputation)
Group: Forum Members
Posts: 18, Visits: 56
I have an image in my database, I setup the business object mapper with CustomObject Type = System.Drawing.Bitmap and the flag serialize to true, null value option= don't allow null. I rebuild and get the following working code:
Set(ByVal value As System.Drawing.Bitmap)
Dim loStream As New MemoryStream()
Me.BinaryFormatter.Serialize(loStream, value)
Me.CurrentRow.Item("Immagine") = loStream.ToArray()
End Set

When I change the option null value option= return alternate on null/Set null on alternate(reference type) the code generated is the following:

Set(ByVal value As System.Drawing.Bitmap)

Dim loStream As New MemoryStream()

if value IsNot Nothing Then

Me.CurrentRow.Item("Immagine") = loStream.ToArray()

Else

Me.CurrentRow.Item("Immagine") = DBNull.Value

End If

End Set

It seems that the row

Me.BinaryFormatter.Serialize(loStream, value)   

gets missing. In fact I added it manually and all works fine.

Is there a better way to achieve this? Is this by design?

Thanks in advance


Gianpaolo Rocchi

Replies
Ross L Rooker, Sr.(1)
Ross L Rooker, Sr.(1)
StrataFrame User (236 reputation)StrataFrame User (236 reputation)StrataFrame User (236 reputation)StrataFrame User (236 reputation)StrataFrame User (236 reputation)StrataFrame User (236 reputation)StrataFrame User (236 reputation)StrataFrame User (236 reputation)StrataFrame User (236 reputation)
Group: StrataFrame Users
Posts: 50, Visits: 163



BusinessFieldDisplayInEditor below gives me: The type or namespace 'BusinessFieldDisplayInEditor' could not be found. Are you missing a using directive or a assembly reference?

Here are my using statements:

using MicroFour.StrataFrame.Business;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Runtime.Serialization;
using System.Text;
using System.Drawing;

What I am trying to do is:

I have a column in this table called GI_PICTURE which is an IMAGE type. I borrowed Trent's code above in this threaded (converted to C#) to do this.

Yet looking at this code I am not sure how this will read the image to display on a form and then save a jpg, etc selected by the user back to the database. Any ideas on how to do this?

What do I set in the BO Mapper on this column?




[Browsable(false), BusinessFieldDisplayInEditor(), Description("GIpicture"), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public System.Drawing.Image cct_SignatureAsImage
{
   
 get
    {
  //-- Establish Locals
  Bitmap r = default(Bitmap);
       
  //-- See if there is an image to return
  if (GI_PICTURE.Length == 0)
        {
   //-- Create a new image appropriatly sized

   //r = new Bitmap(Preferences.POSPreferences.SignatureImageWidth, Preferences.POSPreferences.SignatureImageHeight);
            r = new Bitmap(200,200);

   //-- Just clear the image to a white canvas
   Graphics g = Graphics.FromImage(r);
   g.Clear(Color.White);

   //-- Clean Up
   g.Dispose();
  }
        else
        {
   //-- Create a memory stream to house the image
   System.IO.MemoryStream mem = new System.IO.MemoryStream();

   //-- Write the signature bytes to a memory stream
            mem.Write(GI_PICTURE, 0, GI_PICTURE.Length);
   mem.Seek(0, System.IO.SeekOrigin.Begin);
   r = new Bitmap(mem);

   //-- Clean Up
   mem.Dispose();
  }

  //-- Return the results
  return r;
 }
}
Edited 11 Years Ago by Ross L Rooker, Sr.(1)
Santosh Patil
Santosh Patil
StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)
Group: Forum Members
Posts: 1, Visits: 28
Column type is  'System.Drawing.Bitmap' you have to set.  And for null value   'System.Drawing.Bitmap(1, 1)'.

 public System.Drawing.Bitmap Col006
        {
            get
            {
                object loValue;
                loValue = this.CurrentRow["Col006"];
                if (loValue == DBNull.Value)
                {
                    return new System.Drawing.Bitmap(1, 1);
                }
                else
                {
                    try
                    {
                        return (System.Drawing.Bitmap)this.BinaryFormatter.Deserialize(new MemoryStream((Byte[])loValue));
                    }
                    catch
                    {
                        return new System.Drawing.Bitmap(1, 1);
                    }
                }
            }
            set
            {
                MemoryStream loStream = new MemoryStream();
                this.BinaryFormatter.Serialize(loStream, value);
                this.CurrentRow["Col006"] = loStream.ToArray();
            }
        }

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search