I have the following code:
private void Process(string path)
{
using (FileStream fs = File.OpenRead(path))
{
JpegBitmapDecoder decoder = new JpegBitmapDecoder(fs,BitmapCreateOptions.PreservePixelFormat,BitmapCacheOption.Default);
BitmapSource bmps = decoder.Frames.First();
double targetScale = 800.0/600.0;
double scaleX = bmps.PixelWidth*targetScale;
double scaleY = bmps.PixelHeight*targetScale;
TransformedBitmap tbmp = new TransformedBitmap();
tbmp.BeginInit();
tbmp.Source = bmps;
tbmp.Transform = new ScaleTransform(scaleX, scaleY);
tbmp.EndInit();
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(tbmp));
using (FileStream fs2 = File.OpenWrite(path+".jpg"))
{
Debug.WriteLine(path+".jpg");
encoder.Save(fs2);
}
}
}
It throws an OverflowException at tbmp.EndInit();
Any idea why?
UPDATE: It might be worth mentioning that this method is called through a ParallelQuery. It doesn't depend on anything that could be in a different thread though.