[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

jpeg to bmp to jpeg file size increase??

Posted on 2000-04-09
3
Medium Priority
?
336 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 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this Micro Tutorial viewers will learn the basic shortcuts and functions in InDesign.
In addition to being a great web-based presentation tool, Prezi also makes it easy to save your presentation as a PDF to share with others as well. Learn how in this tutorial. Select the share icon from the top menu in your Prezi editor: Select "D…
Suggested Courses

650 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