Hi there.
I am trying to load and save a jpeg file losslessly, however I get an exception when I try to save the file.
The code bellow works fine, however, it will break if I replace the EncoderParameter with the one in the commended line.
Any help will be appreciated?
using (Image b = Image.FromFile("somefile.jpg")) {
using (Graphics g = Graphics.FromImage(b)) { g.DrawString("some text", new Font("Arial", 10), Brushes.Yellow, b.Size.Width, b.Size.Height); String newName = "newfile.jpg";
ImageCodecInfo encoderInfo = GetEncoderInfo("image/jpeg");
EncoderParameters encParams = new EncoderParameters(1); encParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L); //encParams.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Transformation,(long)EncoderValue.TransformRotate90); b.Save(newName, encoderInfo, encParams); } }
|
Pencho IlchevPosted Jan 2, 2010, 2:35 AM
What I was trying to do is to draw some text on a jpeg/exif image (a timestamp) and to save the file while avoiding re-compression.
It seems that it is not possible to pass transformation parameters when saving modified bitmap data. However, GDI doesn't complain if any of the image properties (incl. any of the exif properties) are modified.
Kind of a work-around is passing Quality parameter and value 100 when saving the file. However, the image will get re-encoded and the file size will decrease.
Hope this will help others who bump into the issue.
Best,
Pencho
Pencho IlchevPosted Jan 2, 2010, 1:22 AM
The exception I get is "Parameter is not valid". Unfortunately, changing the extension of the file from jpg to jpeg doesn't help.
Any other suggestions?
manoj kumarPosted Dec 30, 2009, 3:27 AM
if you want save jpeg file save..you give parameter file only jpeg..other give the error parameter is not found...
here change code
using(Image b = Image.FromFile("somefile.jpeg"))
and
string newName = "newfile.Jpeg";
try it ....
Hope full for you...