?
Solved

jpeg to bmp to jpeg file size increase??

Posted on 2000-04-09
3
Medium Priority
?
338 Views
Last Modified: 2013-11-19
I need to be able to draw onto a jpeg image and save the new image as a jpeg. Im using the code below to draw onto a bitmap BUT when I then save this bitmap to a jpeg the file sizes increases from 9K to 16K any ideas how to fix this. (I save it without drawing onto the bitmap and the size still increased)


var
   J : TJPegImage;
   JPEG : TJPEGImage;

begin
  JPEG := TJPEGImage.Create;
  J := TJPegImage.Create;

  try
    J.LoadFromFile('c:\test.JPG');
    image2.picture.bitmap.assign(J);
    image2.Canvas.MoveTo(10,10);
    image2.Canvas.lineTo(100,100);

    JPEG.CompressionQuality := j.CompressionQuality;
    JPEG.Performance := j.Performance;
    JPEG.ProgressiveEncoding := j.ProgressiveEncoding;
    JPEG.PixelFormat := j.PixelFormat;

    JPEG.Assign(TBitmap(image2.Picture.Bitmap));
    JPEG.SaveToFile('c:\test2.jpg');

  finally
   JPEG.free;
   J.Free;
  end;

  image3.Picture.LoadFromFile('c:\test2.jpg');
0
Comment
Question by:julianpointer
3 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2698825
JPEG is a lossy format, that is the image you get when you decompress a JPEG is NOT identical to the original. It will look like it, but it aint the same :-)

JPEG introduces large numbers of small (unnoticable) artifacts which can work against the JPEG algorithm when it is compressed again which can tend to increase the file size.

Another cause might be that your screen colour depth is less than 24 bit. JPEG was designed to deal with real world images in full colour. It does not perform so well when compressing images with lower colour depth (which you will be doing if your screen is not running with 24 bit colour)

Cheers,

Raymond.
0
 
LVL 4

Expert Comment

by:Radler
ID: 2705753
Hi julianpointer,

Placing at diferent order

JPEG.Assign(TBitmap(image2.Picture.Bitmap));
JPEG.CompressionQuality := j.CompressionQuality;
JPEG.Performance := j.Performance;
JPEG.ProgressiveEncoding := j.ProgressiveEncoding;
JPEG.PixelFormat := j.PixelFormat;
JPEG.SaveToFile('c:\test2.jpg');

Changes anything ?

T++, Radler.
0
 
LVL 1

Accepted Solution

by:
saulite earned 150 total points
ID: 2796121
At first, Radler is true, you must use Assign, before setting properties.
The second mistake: you don't need to set Perfomance property. This property is used only for SHOWING IMAGE, not for savin.
The third(main) mistake: you must use the method Compress, before saving to file:

.....
JPEG.PixelFormat:=j.PixelFormat;
JPEG.Compress;
JPEG.SaveToFile('C:\test2.jpg);
.....
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Suggested Courses
Course of the Month17 days, 2 hours left to enroll

864 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