Solved

Bitmap from a RES file.

Posted on 1999-01-07
1
148 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Connection between libmysql.dll and MySQL Versions 7 113
How to debug For loops? 3 57
Moving (cutting/pasting) controls in a TTabbedNotebook... 7 44
RESTRequest Parameter 4 43
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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