Solved

jpeg to bmp to jpeg file size increase??

Posted on 2000-04-09
3
315 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I've been using this technique since Adobe CS2, and it should work with any version of Illustrator that includes the appearance panel. In this tutorial we'll create a button using the appearance panel in Adobe Illustrator, and then save it as a r…
Keep your audience engaged and get the most out of your next presentation with these quick Prezi tips.
In this second Micro Tutorial in the series,  viewers will learn more basic shortcuts and functions of Illustrator. In this tutorial you will learn about the eyedropper tool, zoom , ellipses and more.
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.

744 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

17 Experts available now in Live!

Get 1:1 Help Now