Solved

Problem with TJPEGImage!

Posted on 1998-04-29
2
325 Views
Last Modified: 2012-05-04
Hi!

Why doesn't the code below work? It displays test1.jpg just fine (Image1 is an TImage that is put at the form at design-time), but it refuses to display test2.jpg. Do I have to reset (in some way) or even DESTROY the TJPEGImage between these operations?

procedure TForm1.FormShow(Sender: TObject);
var
  JPEG : TJPEGImage;

begin
  JPEG := TJPEGImage.Create;
  JPEG.LoadFromFile('\Temp\Test1.jpg');
  Image1.Picture.Bitmap.Assign(JPEG);
  //**************
  JPEG.LoadFromFile('\Temp\Test2.jpg');
  Image1.Picture.Bitmap.Assign(JPEG);
  Image1.Repaint;
end;

All help appreciated!
0
Comment
Question by:Dippen
2 Comments
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 70 total points
Comment Utility
Hi

Yes, you MUST free & recreate the jpeg image each time.

E.g.
var
  Jp: TJPegImage;
begin
  Jp := TJPegImage.Create;
  Jp.LoadFromFile('Test1.jpg');
  imgTest.Picture.Bitmap.Assign(Jp);
  Jp.Free;

  // Do stuff...

  Jp := TJPegImage.Create;
  Jp.LoadFromFile('Test2.jpg');
  imgTest.Picture.Bitmap.Assign(Jp);
  Jp.Free;

Cheers,
JB
0
 
LVL 1

Expert Comment

by:acerola
Comment Utility
try
Image1.Picture.Assign(JPEG);
instead of
Image1.Picture.Bitmap.Assign(JPEG);
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now