views:

131

answers:

4

I have uploaded an image with an jpg extension and added text on photo using Graphics.DrawString in .NET web application. Then if I apply other editing tools like rotating the image, the text added gets blurry.

What is the reason and a solution for this problem?

A: 

IMHO, your are getting this blurring because of jpeg-compression. You should avoid lossy compression methods if you want to edit image. Try to use PNG instead of JPEG to check my guess.

Andrey Shvydky
A: 

Your image is already compressed going in. When you process the image, make sure you aren't saving it as a JPEG again on the way out as you compound the compression. Every time you re-compress a JPEG it looks exponentially worse and usually gets bigger despite the loss in visual quality.

FerretallicA
The text is not compressed when it's added (because it's generated by GDI) so the "re-compression" problem doesn't apply.
AUSteve
The input image is already compressed. When you add text to that, the "re-compression" still applies to the image as a whole. In virtually all instances he text boundaries will be intersecting artefacting from the previous compression run(s) and still be subject to the same caveats upon subsequent recompression.
FerretallicA
+1  A: 

You can always use something like IMageMagick .NET component to get better control over your compression when you save too.

+2  A: 

When adding text to a raster-based image format like JPEG (as opposed to vector-based formats like SVG) then the text is no longer a separate object, it's just coloured pixels like the photo. Any transformations on raster images will almost certainly cause "blurriness".

To reduce the affects you could add the text last so it is not affected by the other operations.

I'm not sure what the GDI.net default level is but you could play with the level of JPEG compression. Low compression is not as lossy but produces large file sizes. You should be able to get away with 5-10% compression without losing too much detail while significantly reducing the file size, but that depends on the images and how fussy you need to be.

AUSteve