Solved

Bitmap from a RES file.

Posted on 1999-01-07
1
151 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month7 days, 9 hours left to enroll

632 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