hi all,
I have just wrote my first app in WPF (actually it is my first windows app). It is an image resizer which converts pictures correctly but it jams when I load large number of images (The window freezes and I cant move it).
I have a list of strings where each item represents location of the image. Then I run the following loop:
foreach (string file in fileCollection)
{
index++;
FileInfo fInfo = new FileInfo(file);
Image tempImg2 = Image.FromFile(fInfo.FullName);
string imgName = fInfo.Name.Substring(0, fInfo.Name.Length - 4);
if (isOriginalSize == true)
{
finalImage = tempImg2;
}
else
{
finalImage = tempImg2.GetThumbnailImage(imageWidth, imageHeight, null, IntPtr.Zero);
}
Bitmap bmp1 = new Bitmap(finalImage);
tempImg2.Dispose();
finalImage.Dispose();
ImageCodecInfo jpgEncoder = GetEncoder(ImageFormat.Jpeg);
System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
EncoderParameters myEncoderParameters = new EncoderParameters(1);
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, imgQualityValue);
myEncoderParameters.Param[0] = myEncoderParameter;
bmp1.Save(@ofd_out.SelectedPath + "\\" + imgName + outputFormat, jpgEncoder, myEncoderParameters);
bmp1.Dispose();
}
|
What can I do to improve performance of my program? Should I use threading or something else?
Thank you,
Marcin
marqsPosted Jan 25, 2010, 9:08 AM
Mahesh ChandPosted Jan 24, 2010, 10:19 AM
Also, you may want to put a try..catch..finally block around your code and put Dispose method in finally to make sure bitmaps are being disposed. If there is an error in your code before Dispose, bitmaps may not being disposed.
Debug .. debug .. I always suggest debug line by line to see how long your code is taking and what it is doing.