Solved

jpeg to bmp to jpeg file size increase??

Posted on 2000-04-09
3
317 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 50 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi selector screen 2 79
Delphi 2 59
How to define IfThen functions in one common unit? 4 54
control image tags in a string ? 12 131
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Learn how to download your full Prezi presentation for offline presenting. Prezi doesn’t have to be viewed and shared in a web browser, even with a free account you can download your full presentation to share with others. Be sure to download any vi…
Learn how to use the remote presentation tool in Prezi to allow you to harness the power of this cloud based presentation platform. You can show your presentation with a remote audience using this free tool.

772 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