🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.graphics
17 messages
17 total messages Started by Ian Boyd Mon, 28 Jul 2008 20:52
LoadImage(LR_LOADFROMFILE) fails with no error.
#200
Author: Ian Boyd
Date: Mon, 28 Jul 2008 20:52
9 lines
1156 bytes
Calling:
    LoadImage(0, 'c:\samplebmp.bmp', IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

returns no handle (0), and GetLastError returns 0.


The file exists.
The file is a bmp.
What more does it want?
Re: LoadImage(LR_LOADFROMFILE) fails with no error.
#201
Author: Ian Boyd
Date: Mon, 28 Jul 2008 21:01
21 lines
1765 bytes
"Ian Boyd" <ian.borlandnews010@avatopia.com> wrote in message 
news:488e31a1@newsgroups.borland.com...
> Calling:
>    LoadImage(0, 'c:\samplebmp.bmp', IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
>
> returns no handle (0), and GetLastError returns 0.

And with regards to the 3 applicable flags (LR_LOADFROMFILE, 
LR_CREATEDIBSECTION, LR_DEFAULTSIZE) here's the error code for each 
combination of flags:

LR_LOADFROMFILE: 0
LR_LOADFROMFILE|LR_CREATEDIBSECTION: 0
LR_LOADFROMFILE|LR_DEFAULTSIZE: 0
LR_LOADFROMFILE|LR_CREATEDIBSECTION|LR_DEFAULTSIZE: 0

In other words no valid combination of those 3 flags makes it work.

Playing with the "desired size" (which only is supposed to apply to icons 
and cursors anyway) doesn't help.
Re: LoadImage(LR_LOADFROMFILE) fails with no error.
#203
Author: GrandmasterB
Date: Mon, 28 Jul 2008 22:29
5 lines
1204 bytes
"Ian Boyd" <ian.borlandnews010@avatopia.com> wrote in message 
news:488e31a1@newsgroups.borland.com...
>    LoadImage(0, 'c:\samplebmp.bmp', IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

I think you need to specify the size of the bitmap, not just 0,0.
Re: LoadImage(LR_LOADFROMFILE) fails with no error.
#204
Author: Remy Lebeau (TeamB)
Date: Mon, 28 Jul 2008 22:43
11 lines
1308 bytes
"GrandmasterB" <Fizzle@shizzle.com> wrote in message 
news:488e3acb$1@newsgroups.borland.com...

> I think you need to specify the size of the bitmap, not just 0,0.

When the LR_DEFAULTSIZE flag is not specified, LoadImage() uses the actual 
image size when the specified size is 0,0.


Gambit 
Re: LoadImage(LR_LOADFROMFILE) fails with no error.
#205
Author: Remy Lebeau (TeamB)
Date: Mon, 28 Jul 2008 22:45
11 lines
1218 bytes
"Ian Boyd" <ian.borlandnews010@avatopia.com> wrote in message 
news:488e31a1@newsgroups.borland.com...

> What more does it want?

HOWTO: How To Use LoadImage() to Read a BMP File
http://support.microsoft.com/kb/158898


Gambit 
Re: LoadImage(LR_LOADFROMFILE) fails with no error.
#207
Author: Ian Boyd
Date: Tue, 29 Jul 2008 13:42
58 lines
2589 bytes
> HOWTO: How To Use LoadImage() to Read a BMP File
> http://support.microsoft.com/kb/158898

i saw that:

   *phBitmap = (HBITMAP)LoadImage( NULL, szFileName, IMAGE_BITMAP, 0, 0,
               LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE );
   if( *phBitmap == NULL )
     return FALSE;

Can you see anything i'm missing? i would convert that C into:

    hBmp := LoadImage(0 , PChar(szFileName), IMAGE_BITMAP, 0, 0,
            LR_CREATEDIBSECTION or LR_DEFAULTSIZE or LR_LOADFROMFILE );
    if (hBmp = 0 ) then
    begin
        Result := False;
        Exit;
    end;

and my actual code is:

var
    hCurrentBmp: HBITMAP;
    hr: HRESULT;
begin
    szFilename := 'c:\samplebmp.bmp';

    hCurrentBmp := LoadImage(0, PChar(szFilename), IMAGE_BITMAP, 0, 0,
            LR_LOADFROMFILE or
            LR_CREATEDIBSECTION or
            LR_DEFAULTSIZE
    );
     if hCurrentBmp = 0 then
    begin
        hr := GetLastError;
        MessageDlg('Error '+IntToStr(hr)+' loading bitmap "'+szFilename+'": 
'+SysErrorMessage(hr), mtError, [mbOk], 0);
        Exit;
    end;

Anyone have any ideas what i'm doing wrong?


Changing:
    szFilename := 'c:\FileNotFound.bmp';
gives
    Error 2 loading bitmap "c:\FileNotFound.bmp": The system cannot find the 
file specified

Changing
    szFilename := 'c:\\samplebmp.bmp';
gives
    Error 0 loading bitmap "c:\\samplebmp.bmp": The operation completed 
successfully


i'll put the bitmap in the attachments group as well. 
Re: LoadImage(LR_LOADFROMFILE) fails with no error.
#206
Author: Ian Boyd
Date: Tue, 29 Jul 2008 13:45
4 lines
1153 bytes
> HOWTO: How To Use LoadImage() to Read a BMP File
> http://support.microsoft.com/kb/158898

Is that not what i did? 
Re: LoadImage(LR_LOADFROMFILE) fails with no error.
#212
Author: Remy Lebeau (TeamB)
Date: Tue, 29 Jul 2008 16:23
10 lines
1242 bytes
"Ian Boyd" <ian.borlandnews010@avatopia.com> wrote in message 
news:488f1ede$1@newsgroups.borland.com...

> Is that not what i did?

You were not specifying the same flags the article does.


Gambit 
Re: LoadImage(LR_LOADFROMFILE) fails with no error.
#211
Author: Pieter Zijlstra
Date: Tue, 29 Jul 2008 16:34
58 lines
2664 bytes
Ian Boyd wrote:

> > HOWTO: How To Use LoadImage() to Read a BMP File
> > http://support.microsoft.com/kb/158898
> 
> and my actual code is:
> 
> var
>    hCurrentBmp: HBITMAP;
>    hr: HRESULT;
> begin
>    szFilename := 'c:\samplebmp.bmp';
> 
>    hCurrentBmp := LoadImage(0, PChar(szFilename), IMAGE_BITMAP, 0, 0,
>            LR_LOADFROMFILE or
>            LR_CREATEDIBSECTION or
>            LR_DEFAULTSIZE
>    );
>     if hCurrentBmp = 0 then
>    begin
>        hr := GetLastError;
>       MessageDlg('Error '+IntToStr(hr)+' loading bitmap
> "'+szFilename+'": '+SysErrorMessage(hr), mtError, [mbOk], 0);
> Exit;    end;
> 
> Anyone have any ideas what i'm doing wrong?

No, not really and it works for me with D5 and D2007 on XPsp3 using the
bitmap you provided in the attachments group.

Just to be sure you have the correct values for the const and not some
strange value from any other unit.

IMAGE_BITMAP = 0
LR_LOADFROMFILE = 16 
LR_CREATEDIBSECTION = 8192
LR_DEFAULTSIZE = 64

You have szFilename defined as string(?)


BTW the example and/or documentation does not seem to be very
consistent when the image is a bitmap.

<q>
LR_DEFAULTSIZE
Uses the width or height specified by the system metric values for
cursors or icons, if the cxDesired or cyDesired values are set to zero.
If this flag is not specified and cxDesired and cyDesired are set to
zero, the function uses the actual resource size. If the resource
contains multiple images, the function uses the size of the first image.
</q>

For me it also works without the LR_DEFAULTSIZE what is what you want
when you like to get it using the actual resource size.
 
-- 
Pieter
Re: LoadImage(LR_LOADFROMFILE) fails with no error.
#216
Author: Ian Boyd
Date: Tue, 29 Jul 2008 19:46
7 lines
1380 bytes
>> Is that not what i did?
>
> You were not specifying the same flags the article does.

My immediate followup showed the results for every combination of flags.

After i posted it i figured someone would ask about that. 
Re: LoadImage(LR_LOADFROMFILE) fails with no error.
#214
Author: Ian Boyd
Date: Tue, 29 Jul 2008 19:57
28 lines
1763 bytes
> Just to be sure you have the correct values for the const and not some
> strange value from any other unit.
>
> IMAGE_BITMAP = 0
> LR_LOADFROMFILE = 16
> LR_CREATEDIBSECTION = 8192
> LR_DEFAULTSIZE = 64

 hCurrentBmp := LoadImage(
   0,
   'c:\samplebmp.bmp', //PChar(szFilename),
   0, //IMAGE_BITMAP
   0, 0, //desired width, height
   16 //LR_LOADFROMFILE
   or
   8192 //LR_CREATEDIBSECTION
  );


> You have szFilename defined as string(?)
i did, yes. The above code removes the string completely.


i hate it when i do nothing wrong and things don't work.


i attached a project, source, binary, bitmap to the post in attachments. 
Tell me it fails on your computer, because it fails on other computers here. 
Re: LoadImage(LR_LOADFROMFILE) fails with no error.
#220
Author: Pieter Zijlstra
Date: Tue, 29 Jul 2008 20:19
24 lines
1774 bytes
Ian Boyd wrote:

> i hate it when i do nothing wrong and things don't work.

Still some hair left ?-) 
 
> i attached a project, source, binary, bitmap to the post in
> attachments. Tell me it fails on your computer, because it fails on
> other computers here.

The good news it fails here too!

It is not your code it is the bitmap itself which has a strange value
in it. If I do a binary compare of the separate uploaded (as bitmap
attachment) there is one byte of compared to the bitmap included in rar
file.

The first bitmap was probably "auto-magically" corrected by MSOE when
you posted it. That's why that one worked for me.
I guess you can try it yourself again by downloading your first
uploaded bitmap from attachments, it should work for you too then.

-- 
Pieter
Re: LoadImage(LR_LOADFROMFILE) fails with no error.
#219
Author: GrandmasterB
Date: Tue, 29 Jul 2008 21:10
26 lines
1929 bytes
"Ian Boyd" <ian.borlandnews010@avatopia.com> wrote in message 
news:488f73a9$1@newsgroups.borland.com...
>>> Is that not what i did?
>> You were not specifying the same flags the article does.
> My immediate followup showed the results for every combination of flags.

This works for me in D7:

var
   h: HBITMAP;
   bmp: TBitmap;
begin

   h := LoadImage( 0, 'c:\temp\test2.bmp', IMAGE_BITMAP, 0, 0, 
LR_LOADFROMFILE or LR_DEFAULTSIZE);

   if h > 0 then
   begin
      bmp := TBitmap.Create;
      bmp.Handle := h;
      Image1.Canvas.Draw( 0, 0, bmp);
      bmp.Free;
   end;
end;

Are you sure you have the right file name? 
Re: LoadImage(LR_LOADFROMFILE) fails with no error.
#231
Author: Ian Boyd
Date: Wed, 30 Jul 2008 14:28
10 lines
1559 bytes
> The first bitmap was probably "auto-magically" corrected by MSOE when
> you posted it. That's why that one worked for me.

i thought of that and tried it, it still failed.

> I guess you can try it yourself again by downloading your first
> uploaded bitmap from attachments, it should work for you too then.

Perhaps you could zip up the version you through your client and post it 
back to attachments? 
Re: LoadImage(LR_LOADFROMFILE) fails with no error.
#232
Author: Ian Boyd
Date: Wed, 30 Jul 2008 14:29
5 lines
1244 bytes
> Are you sure you have the right file name?

i put binary, bitmap and sample code in .attachments.

It fails for others (Pieter Zijlstra) too. 
Re: LoadImage(LR_LOADFROMFILE) fails with no error.
#235
Author: Pieter Zijlstra
Date: Wed, 30 Jul 2008 17:33
24 lines
1763 bytes
Ian Boyd wrote:

> Perhaps you could zip up the version you through your client and post
> it back to attachments?

I tried it with both clients (XanaNews and MSOE) and both give a usable
bitmap.

The two different bitmaps on retrieved from the NG directly (_OK) and
the other as found in your rar file (_BAD).

The difference is one byte in the biSizeImage (DWORD) part.
_OK  $88  => $1388 = 5000
_BAD $B0  => $13B0 = 5040

I think LoadImage is checking this value against the other parameters
biWidth (50), biHeight(25) and number of bytes per pixel (4) and fails
if the outcome <> biSizeImage (5000).

BTW both images can be loaded by using Delphi's
  Image2.Picture.LoadFromFile(...);

-- 
Pieter
Re: LoadImage(LR_LOADFROMFILE) fails with no error.
#234
Author: Pieter Zijlstra
Date: Wed, 30 Jul 2008 17:36
9 lines
1298 bytes
Pieter Zijlstra wrote:

> The two different bitmaps, one retrieved from the NG directly (_OK)
> and the other as found in your rar file (_BAD)...

... are posted as a zip-file to b.p.attachments

-- 
Pieter
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads