Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

jpg to bitmap?

Status
Not open for further replies.

jbpelletier

Programmer
Sep 8, 2001
232
CA
hi

im loading a bmp fileinto a tbitmap then i do some canvas manipulation like this :
//filename is 'file1.bmp';

my_bitmap:=Tbitmap.create;
my_bitmap.LoadFromFile(filename);
//canvas manipulation
my_bitmap.free;

i would like to be able to do the canvas manipulation
either if the file is a jpg or a bmp.

any idea on how i could load the jpg as a bitmap? or easily convert it to bmp.

tanx
jb

 
A quick google search using the terms: delphi "jpg to bmp" returned the following website which may be of use to you:

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
i will try that code asp.

previously
i should have mention that my real problem is not to assign a jpeg into a tbimap, but to have acces to the canvas once its done. The canvas still empty! when the bitmap isn't.

tanx
jb

 
Could you clarify what you mean by "the canvas is still empty" and what sort of "canvas manipulation" you are attempting?

The canvas is a drawing surface that provides the ability to draw onto the bitmap image. It is not the image itself.

Bob
 
hi,
all my canvas manipulation are either "canvas.copyrect" with various "option". ex: using and OR, XOR etc..
or canvas.draw.

my problem is that, if i assign a jpg image in a Tbipmap..
i have acces to each of the piture proprieties as width,height etc..
but i dont have an acess to the canvas..
ex: a copyrect will provide no result if i use the Tbitmap as source.

jb
 
I can use the bitmap canvas in a CopyRect using the following code. Just open Delphi and add a button and a TImage to the form, then insert this code in Unit1. You will need to insert a file path to a .jpg on your hard disk.

Code:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses
  JPEG;

procedure TForm1.Button1Click(Sender: TObject);
var
  Jpg: TJPEGImage;
  Bmp: TBitmap;
  R: TRect;
begin
  Jpg := TJPEGImage.Create;
  try
    Jpg.LoadFromFile('???');   //Insert path to a .jpg file
    Bmp := TBitmap.Create;
    try
      Bmp.Assign(Jpg);
      R := Rect(0, 0, Bmp.Width, Bmp.Height);
      Image1.Canvas.CopyRect(R, Bmp.Canvas, R);
    finally
      Bmp.Free;
    end;
  finally
    Jpg.Free;
  end;
end;

end.

Have you by any chance been trying to use the following or something similar?

Code:
Image1.Picture.Bitmap.Canvas.CopyRect(R, Bmp.Canvas, R);

This produces the effects you describe. Instead you must access the TImage canvas directly (see code in Unit1 above).

Bob
 
yes
i figured that if i load a jpg at design time delphi "convert it" to a "bitmap" .. well at least i can use the canvas.. but at design time.. i can't

so far the only way i found is to save the jpg as a bmp in the c:\temp directory then reload it as a bmp.. and delete de temp file..

but im trying to avoid that...

jb
 
jb

Could you include some of the code you have tried that does not work. It is much easier to understand and solve the problems if real code is included.

Bob
 
you may also want to describe what kind of manipulation you are trying to do? change the image? are you trying to include some kind of image editor?

Leslie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top