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
175 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
  • 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
 

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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 33

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 33

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Add visuals to your Prezi to keep your audience engaged. Learn how to embed images, edit them, and more in this video micro tutorial. Select "Insert" from the top menu in your Prezi editor: Select "Image": A toolbar will pop in from the right …

747 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

11 Experts available now in Live!

Get 1:1 Help Now