Solved

Bitmap and TStream ... a Q for Madshi

Posted on 2000-02-16
3
335 Views
Last Modified: 2013-12-03
Madshi,
referencing another question that you provided and answer for
 
Date: Sunday, February 06 2000 - 10:32PM PST
Delphi : Q.10291114

From: baudewyns
Title: "Icon and TStream

 How can I , or if it is possible to adapt the
Icon and TStream program to a Bitmap and TStream? Obviously, at least to me, there was no adaptation that is a substitute for  
 the program line    >>>> DrawIcon(Canvas.Handle, 0, 0, mbp.handle);
since DrawIcon must be a primitive and  DrawBitmap is not.

Delphi3




0
Comment
Question by:delphi3
[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
3 Comments
 
LVL 3

Expert Comment

by:bryan7
ID: 2528687
listenning
0
 
LVL 3

Accepted Solution

by:
philipleighs earned 100 total points
ID: 2529747
Do you mean a Windows Bitmap (HBITMAP) or a Delphi bitmap (TBitmap)?

If TBitmap, then how about:

Canvas.Draw(0, 0, MyBitmap);
0
 
LVL 4

Author Comment

by:delphi3
ID: 2530109
philipleighs.
Congratulations. A super bit of work. Here is the completed work, with your sparkle line in place.

Thanks a lot,

Delphi3



unit BmpToAndFromStreamUnit1;
interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
// use mbp for ico and TBitmap for TIcon  and Btest.dat for test.dat

procedure SaveToStream(str1: string; mbp: TBitmap; str2: string);
var
  i1: integer;
  ms: TMemoryStream;
begin
  with TFileStream.Create('C:\WINDOWS\Desktop\To.From Stream\Btest.dat', fmCreate) do
  try
    i1 := Length(str1);
    Write(i1, 4);
    Write(pointer(str1)^, i1);
    ms := TMemoryStream.Create;
    try
      mbp.SaveToStream(ms);
      i1 := ms.Size;
      Write(i1, 4);
      Write(ms.Memory^, ms.Size);
    finally ms.Free end;
    i1 := Length(str2);
    Write(i1, 4);
    Write(pointer(str2)^, i1);
  finally Free end;
end;

function LoadFromStream(var str1, str2: string): TBitmap;
var
  i1: integer;
  ms: TMemoryStream;
begin
  with TFileStream.Create('C:\WINDOWS\Desktop\To.From Stream\Btest.dat', fmOpenRead) do
  try
    Read(i1, 4);
    SetLength(str1, i1);
    Read(pointer(str1)^, i1);
    ms := TMemoryStream.Create;
    try
      Read(i1, 4);
      ms.Size := i1;
      Read(ms.Memory^, i1);
      result := TBitmap.Create;
      result.LoadFromStream(ms);
    finally ms.Free end;
    Read(i1, 4);
    SetLength(str2, i1);
    Read(pointer(str2)^, i1);
  finally Free end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  s1, s2: string;
  mbp: TBitmap;
begin
  mbp := TBitmap.Create;
  mbp.LoadFromFile('C:\WINDOWS\Desktop\To.From Stream\testB.bmp'); // give in a valid bmp file here
  SaveToStream('Btest1', mbp, 'Btest2');
  mbp.Free;
  mbp := LoadFromStream(s1, s2);
  Canvas.Draw(0,0, mbp);
  mbp.Free;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Application.Terminate;
end;

end.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

739 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