Adding Images to Database through PictureEdit


Author
Message
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
I threw a PictureEdit control on a Parts Maintenance form.  When navigating through the parts, the PictureEdit shows the stored image.  That's great...a simple binding maneuver.  If I choose to plant a new image into the PictureEdit control, it accepts it (via drag/drop, copy/paste, or load).  Wonderful.  I am happy with the part, so I click Save.  The image reverts back to the original image.  Apparently, I do not have something set correctly within the BO or on the control to allow for the image to be written back to the server.

Any ideas?

Thanks!
Bill

Replies
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Ok...after 1)  Adding reference to System.Drawing in the BO project; 2)  Setting the custom type for the image field to System.Drawing.Bitmap; 3)  Checking the serialize checkbox for the field; and 4) Building the BO with the partial build option; I get this new patch of code for my image field:

public System.Drawing.Bitmap sketch
{
    get
   
{
       
object loValue;
        loValue =
this.CurrentRow["sketch"];
       
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["sketch"] = loStream.ToArray();
    }
}

I see now how the byte[] type is converted to a bitmap type.  Cool.  Smooooth  I am now following the code through to test the PictureEdit control on my form.  I have to tie up a few loose ends, first, though.


Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
No errors.  Just a plain, white box on all records.  Still not working.  I like the null replacement feature, though. 

Got more work to do on this. 

Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
I wiped out all customizations on the image field (SQL Server 2000).

I removed the PictureEdit control from the form.

...here's where it gets embarassing...

I added the SF PictureEdit control.  Everything works beautifully!  Just like I expected it to.

The problem stemmed from me having a newer version of the controls and I was too lazy when I first created the window to download the older version (DevEx 6.3.3).  In order to get the images to show up (not store), I used a BusinessBindingSource on the newer versioned PictureEdit control.  While it worked to show an image properly, it would not save it.

So, lesson learned.  Don't use a hammer and chisel to get the food out of your teeth, use a toothpick! Tongue

Bill

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