The code I have so far:
public static void SaveJpeg(string path, Image img)
ImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg");
Bitmap bmp = new Bitmap(img);
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.WriteOnly, bmp.PixelFormat);
EncoderParameters encoderParams = bmp.GetEncoderParameterList(jpegCodec.Clsid);
img.Save(path, jpegCodec, encoderParams);
What I'm trying to do is to get the EncoderParameters from a JPEG and save that to another JPEG.
I've tried doing this the regular way by doing img.GetEncoderParameterList(jpegCodec.Clsid) which should have worked fine, but I got an error: "Bitmap region is already locked." where I create the object EncoderParameters encoderParams (and assign it).
So I searched here and there, and found that I had to lock and unlock the bits, which is only possible for a bitmap:confused:
Now in the example above I've done it in the bitmap way, but it still comes up with the same error, even with different imagelockmodes.
All I want is to save the JPEG, and with the bmp as encoder, the parameters are probably different (I guess).
Is there a way? :-D
I'm pretty new to .net and imaging, but this is the first problem I've had that I can't solve myself :sigh:
thanks for the response(s) if any! :)