Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: TImage and MS Access



Permlink Replies: 6 - Last Post: May 6, 2017 10:16 PM Last Post By: Alex Belo Threads: [ Previous | Next ]
Sudesh C

Posts: 34
Registered: 9/13/08
TImage and MS Access
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 5, 2017 4:57 AM
Hello:

I am trying to load an image from MS Access Table field into TImage but get
following error
"Bitmap image is not valid."

What may be wrong?

Thanks,
Sudesh
Asger Joergensen

Posts: 370
Registered: 11/18/08
Re: TImage and MS Access
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 5, 2017 5:18 AM   in response to: Sudesh C in response to: Sudesh C
Hi Sudesh

Sudesh C wrote:

Hello:

I am trying to load an image from MS Access Table field into TImage but get
following error
"Bitmap image is not valid."

What may be wrong?

What format is the image in the db ?
What version of builder are you using ?
How does your actual code look ?

Best regards
Asger
Sudesh C

Posts: 34
Registered: 9/13/08
Re: TImage and MS Access [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 5, 2017 8:03 AM   in response to: Asger Joergensen in response to: Asger Joergensen
Hi Asger:

1. bitmap image.
2. XE6
3. code is like below:

TField *myField1 = FDTable1->Fields->FieldByName("ImgField");
TStream *myStream = FDTable1->CreateBlobStream(myField1, bmRead);
Image1->Picture->Bitmap->LoadFromStream(myStream);

Thanks,
Sudesh

"Asger Joergensen" wrote in message news:917511 at forums dot embarcadero dot com...

Hi Sudesh

Sudesh C wrote:

Hello:

I am trying to load an image from MS Access Table field into TImage but
get
following error
"Bitmap image is not valid."

What may be wrong?

What format is the image in the db ?
What version of builder are you using ?
How does your actual code look ?

Best regards
Asger
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: TImage and MS Access [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 5, 2017 10:07 AM   in response to: Sudesh C in response to: Sudesh C
Sudesh wrote:

1. bitmap image.

And you are absolutely sure the image is a real BMP, and not something else,
like JPG or PNG?

3. code is like below

Does myField1->IsNull report true or false? If true, don't call Bitmap->LoadFromStream(),
clear the Picture instead:

TField *myField1 = FDTable1->Fields->FieldByName("ImgField");
if (myField1->IsNull)
{
    Image1->Picture = NULL;
}
else
{
    TStream *myStream = FDTable1->CreateBlobStream(myField1, bmRead);
    try {
        Image1->Picture->Bitmap->LoadFromStream(myStream);
    } __finally {
        delete myStream;
    }
}


That being said, is there a reason why you are using TImage and not TDBImage?
TDBImage handles these kind of details for you.

--
Remy Lebeau (TeamB)
Sudesh C

Posts: 34
Registered: 9/13/08
Re: TImage and MS Access [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 5, 2017 11:20 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
HI Remy:

I had first tried TDBImage and it reported this error. So I was trying with
TImage.

myField1->IsNull is false.

How to confirm if the image is real BMP? That may be the issue. However,
in MS Access, its showing Bitmap Image.

Thanks,
Sudesh

"Remy Lebeau (TeamB)" wrote in message
news:917544 at forums dot embarcadero dot com...

Sudesh wrote:

1. bitmap image.

And you are absolutely sure the image is a real BMP, and not something else,
like JPG or PNG?

3. code is like below

Does myField1->IsNull report true or false? If true, don't call
Bitmap->LoadFromStream(),
clear the Picture instead:

TField *myField1 = FDTable1->Fields->FieldByName("ImgField");
if (myField1->IsNull)
{
    Image1->Picture = NULL;
}
else
{
    TStream *myStream = FDTable1->CreateBlobStream(myField1, bmRead);
    try {
        Image1->Picture->Bitmap->LoadFromStream(myStream);
    } __finally {
        delete myStream;
    }
}


That being said, is there a reason why you are using TImage and not
TDBImage?
TDBImage handles these kind of details for you.

--
Remy Lebeau (TeamB)
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: TImage and MS Access [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 5, 2017 12:26 PM   in response to: Sudesh C in response to: Sudesh C
Sudesh wrote:

How to confirm if the image is real BMP?

Are the first 2 bytes of the blob data $42 $4D?

--
Remy Lebeau (TeamB)
Alex Belo

Posts: 626
Registered: 10/8/06
Re: TImage and MS Access [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 6, 2017 9:54 PM   in response to: Sudesh C in response to: Sudesh C
Sudesh C wrote:

in MS Access, its showing Bitmap Image.

If you save an image with SaveToStream you can rertrieve it with
LoadFromStream, no problem.

Images saved with Access itself can not be retrieved with
LoadFromStream: Access saves pictures as OLE objects so retrieving them
as bitmap or whatever does not work.

Googling returns articles like this (I did not read carefully):

Uploading and Downloading BLOBs to Microsoft Access
https://www.codeproject.com/Articles/16851/Uploading-and-Downloading-BLOBs-to-Microsoft-Acces
Display Microsoft Access “OLE Object” in my application
http://stackoverflow.com/questions/4206081/display-microsoft-access-ole-object-in-my-application

--
Alex

Edited by: Alex Belo on May 7, 2017 11:15 AM
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02