Solved

jpeg to bmp to jpeg file size increase??

Posted on 2000-04-09
3
328 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
[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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
In this tutorial viewers will learn how to create blended and gradiated shapes in Illustrator using the blend tool Draw two shapes, one of them in a different color: Select both and create a blend by going to Object > Blend > Make: Blends can also b…
Learn how to set up basic frames and paths in Prezi and understand the open space that Prezi allows you to create presentations in.

707 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