Solved

How can I add a visual banner to the bottom a jpeg without re-compressing the jpeg and loosing quality?

Posted on 2004-10-05
19
187 Views
Last Modified: 2013-11-19
I am wanting to put a banner on existing jpegs which shows a caption visually. I guess one tactic would be to create a bitmap and write the caption on it. Then convert this bitmap to a jpeg using the same parameters and quantization table as the original jpeg and join them together. But how can I do this?
0
Comment
Question by:esmondbridgeman
[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
  • 5
  • 4
  • 3
  • +3
19 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 12234927
like

var
  jpg : TJpegImage;
  bmp : TBitmap;
begin
  jpg := TJpegImage.Create;
  bmp := TBitmap.Create;
  try
    jpg.LoadFromFile('PathFileNameHere');
    bmp.assign(jpg);
    bmp.Canvas.Font.Name := 'WhatFontYouWantHere';
    bmp.Canvas.Font.Color := clYourTColor;
    bmp.Canvas.TextOut(xCoord,yCoord,'YourText');
    jpg.assign(bmp);
    jpg.savetofile('PathFileNameHere');
  finally
    jpg.free;
    bmp.free;
  end;
end;

just from head

meikl ;-)

   
0
 

Author Comment

by:esmondbridgeman
ID: 12234992
Problem with this is that the jpeg data needs to be re-compressed and that is what I'm trying to avoid as I don't want to loose any quality in the original jpeg.

Esmond
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 12235007
??
if you will have your banner on your jpg permanent,
then you have to recompress/create a new jpg

if you need it just to visualize it in your own app,
then you could show the created bmp from above instead


meikl ;-)
0
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!

 

Author Comment

by:esmondbridgeman
ID: 12235053
The image is being created to email to someone and so it wont be seen inside my app. I have seen this done in a program called 'Jpeg Wizard' so it looks like it can be done but I'm wanting to incorporate it inside my delphi app.

Esmond
0
 
LVL 3

Expert Comment

by:gandalf_the_white
ID: 12235220
i dont think you will need the jpg datas

if you take an existing jpg and convert it to a bitmap you will have the quality loss in
the bitmap. if you would apply the same settings a second time on the bitmap you
would get the quality loss two times and i think you would notice that.

that means you only need to convert the jpg to a bitmap, copy your
caption into it and then convert it back into a jpg with the best quality.

you need the unit jpeg in you uses clause.

procedure ConvertToBitmap;
var TempBmp:TBitmap;
     TempImage:TImage;
    TempJpgImage:TJPEGImage;
begin
  TempImage := TImage.create(nil);
  TempImage.picture.loadfromfile( PathToYourJPGFile);

  TempBmp := TBitmap.create;

  // convert any graphic to bitmap
  tempBmp.Assign(tempImage.Picture.Graphic);

end;

the same is for jpgs just in the other direction


0
 
LVL 3

Expert Comment

by:gandalf_the_white
ID: 12235232
sorry meikl
i had opened this explorer a long time ago and it took me some time to write the comment
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 12235296
doesn't matter, gandalf, happens sometimes to me too  ;-)

about 'Jpeg Wizard'

this is a pegasus-software, where pegasus includes a new technology
(if it is real), so i guess pegasus will offer its new technology

about (if it is real)
usual a jpegimage is a compressed binary format, so i don't think that pegasus do its modifications wíthout de-/recompressing the initial file

meikl ;-)
0
 
LVL 3

Expert Comment

by:gandalf_the_white
ID: 12235713
> The image is being created to email to someone and so it wont be seen inside my app.
??
do you mean that you want to encode your caption inside the jpg without that it is visible to the viewer ?
0
 

Author Comment

by:esmondbridgeman
ID: 12235960
at the moment I'm adding a caption in the file header using the iptc standard but I want to make sure people read this as it contains copyright info (I'm working on this for a photo library). It seems that adding a visible banner to the actual image is the best way to ensure that whoever receives the image also sees the caption info etc.
0
 
LVL 3

Expert Comment

by:gandalf_the_white
ID: 12236175
then you only need to copy the caption into the jpg
like meikl and i suggested
0
 

Author Comment

by:esmondbridgeman
ID: 12236244
so it looks like its not possible to avoid re-compressing the image. Had another look at the pegasus-software and they do seem to sell a dellphi component which does it but at $4000 its a bit out of my price range. Thanks for the suggestions,

esmond
0
 
LVL 3

Expert Comment

by:gandalf_the_white
ID: 12236653
have you tried to paint directly in the canvas of the tjpgimage ?
stretchdraw is a canvas property so it should be possible to
paint directly into the jpg canvas.
but may youll suffer the compression loss, so maybe you should set the
compressionquality to 100

0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12236988
There's a new, losless JPG format, btw. JPG2000 I guess. Or something... Basically, it offers a lossless compression, just like the GIF format. I think it's related to the PNG format. However, I'm not sure if older applications can decompress these JPG files. (And the jpg unit doesn't support it...)
0
 
LVL 34

Expert Comment

by:Slick812
ID: 12242618
just a note
it is possible to get to the JPEG compressed image data and manipulate it ( I guess to draw on it, , but that seems Unlikely to me) however, you could add a Section of added jpeg image to the bottom or top (like a banner at the bottom), but  this is a "NEW" programming development I beleive, and not very much availible, , , and if availible, it is expensive (or so I gather), if you don't want to pay lots to get this tech, then you may just use the standard Jpeg methods of Delphi, and although there is Some image quality lost, much of the bitmap quality is lost on the very first JPEG compression of the bitmap, subsequent decompression and recompression (to about the same compression ratio) may not take much noticable quality from the image. . .

you can test this out, just decompress a Jpeg and recompress it (to about the same ratio) 20 times and see if there is great difference from the first compression
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12244105
Slick, decompressing and then compressing a JPG will result in a lot more loss of detail. However, you could specify a loss percentage of 0% instead of the default 15% in which case you would still have most of the details.
Problem is, every time you compress the JPG, the method will remove a small amount of the details. No matter if the image had been decompressed before. But if you set the percentage of loss to 0, it won't lose too much. Which property was this again, that you had to set for the TJPeGImage class?
0
 
LVL 34

Expert Comment

by:Slick812
ID: 12245465
I really tried to say that there will be image loss in any JPEG compression. I was only trying to imply that a recompression will not lose as much detail as the first compression (assuming you use the same compression ratio). . I have done some testing of the loss of detail (bitmap pixel information) with repeated decompression and recompression  of jpeg images, I did most of the testing at the TJPEGImage CompressionQuality of 80, the first  compression does scatter the bitmap detail into the jpeg average "Block" compression (which you can see in high magification in a bitmap editor), but the next compressions only lose a very small amount of detail (compared to the first), I guess because the jpeg "Block" averages already exist and it seems that the jpeg compression methods just stack the same average Blocks again for the next compression, so I could not see much diference after 20 cycles (yes there is a small diference). .  

If you are trying to preserve image quality, you should start with the Bitmap image not a Jpg, but  if the jpg is all you can get. . .
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 13442923
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

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…
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…
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.
In this Micro Tutorial viewers will learn how to remove an unwanted object using Photoshop’s feature known as content-aware fill.
Suggested Courses

739 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