Solved

Bitmap from a RES file.

Posted on 1999-01-07
1
147 Views
Last Modified: 2010-04-04
I tried to load a BMP from a resource file.
I used LOADBITMAP to assign its return value to Tbitmap.Handle and then assigned it to SpeedButton1.Glyph. But, it dosen't work. Help me.

Robyn.
0
Comment
Question by:robyn112
1 Comment
 
LVL 8

Accepted Solution

by:
ZifNab earned 50 total points
ID: 1355149
hi robyn112,

here you got a method (not written by me)

{If 256 color bitmaps are in the resource file, assigning the handle
doesn't assign the palette. Thus, the 256 color bitmaps will end up
dithered. I use the following function to load bitmaps from resource
files}

function LoadBitmapFromResource(inst: THandle;
                                resnum: Word;
                                outBmp: TBitmap): Boolean;
var
  HResInfo: THandle;
  BMF: TBitmapFileHeader;
  MemHandle: THandle;
  Stream: TMemoryStream;
  ResPtr: PByte;
  ResSize: Longint;
begin
  result := false;
  BMF.bfType := $4D42;
  HResInfo := FindResource(inst,MakeIntResource(resnum),RT_Bitmap);
  if hResInfo = 0 then
    exit;
  ResSize := SizeofResource(inst, HResInfo);
  MemHandle := LoadResource(inst, HResinfo);
  if MemHandle = 0 then
    exit;
  try
    ResPtr := LockResource(MemHandle);
    Stream := TMemoryStream.Create;
    try
      Stream.SetSize(ResSize + SizeOf(BMF));
      Stream.Write(BMF, SizeOf(BMF));
      Stream.Write(ResPtr^, ResSize);
      Stream.Seek(0, 0);
      outBmp.LoadFromStream(Stream);  // speedbtn1.glyph.Loadfromstream
      result := true;
    finally
      Stream.Free;
    end;
  finally
    FreeResource(MemHandle);
  end;
end;

{coded by Marc Batchelor}

Regards, Zif.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
code issue 8 132
Convert a string into a TDateTime 5 61
Performance of SQL statement 37 112
How do I add a client SSL certificate to a SOAP client in Rad Studio Delphi? 2 75
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question