?
Solved

Bitmap and TStream ... a Q for Madshi

Posted on 2000-02-16
3
Medium Priority
?
337 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 400 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

777 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