Loading Image from SQL DB Using GdPictureImaging

Discussions about DocuVieware integration in GdPicture.NET.
Post Reply
philip1978
Posts: 13
Joined: Mon Sep 19, 2016 5:45 pm

Loading Image from SQL DB Using GdPictureImaging

Post by philip1978 » Thu Sep 22, 2016 11:39 pm

I am trying to load an image into a Docuvieware Viewer more or less directly from a SQL DB image blob. We have been able to make this work in a Windows Forms desktop application using VB.NET. I figured I could use a similar strategy for our web portal, since the GdPicture12 Namespace appears to be baked into GdPicture12.WEB Namespace.

Here's what I've done so far:

Default.aspx.cs

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GdPicture12;

namespace DocuViewareDemo
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Byte[] img = Global.getImage(4579788);
            GdPictureImaging g = new GdPictureImaging();
            int imageID = g.CreateGdPictureImageFromByteArray(img);
            GdPictureStatus status = DocuVieware1.LoadFromGdPictureImage(imageID);
            g.ReleaseGdPictureImage(imageID);
        }
    }
}
The getImage(int) function goes to the database and returns an array of bytes directly from the database. The data is in a SQL Data Type TBLOB(image). The byte array is definitely populating, because I can track it while debugging, but nothing loads into the viewer.

The imageID ends up being 1, so I know CreateGdPictureImageFromByteArray() is "succeeding." If not it would return 0. Further, LoadFromGdPictureImage() returns OK, so everything seems to be going fine, but nothing loads into the viewer.

Any suggestions or thoughts on how to troubleshoot further?

Thanks in advance!

Cedric
Posts: 269
Joined: Sun Sep 02, 2012 7:30 pm

Re: Loading Image from SQL DB Using GdPictureImaging

Post by Cedric » Fri Sep 23, 2016 1:24 pm

Hi,

That's probably because you are releasing the image from memory right after calling LoadFromGdPictureImage.
Since DocuVieware is able to load from a stream and you have a byte array, here is what I would simply do:

Code: Select all

protected void Page_Load(object sender, EventArgs e)
{
	GdPictureStatus status = DocuVieware1.LoadFromStream(new MemoryStream(Global.getImage(4579788)), true);
}
This way, DocuVieware would be owner of the stream (because of the "true" parameter) so you don't have to worry about disposing it, DocuVieware will when it won't be needed anymore.

philip1978
Posts: 13
Joined: Mon Sep 19, 2016 5:45 pm

Re: Loading Image from SQL DB Using GdPictureImaging

Post by philip1978 » Fri Sep 23, 2016 3:20 pm

For what it's worth, I tried running it without the release method. Still didn't work.

That said, your solution works like a charm, and involves less code. Thanks for the advice!

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests