Im den folgenden Code mit der Ausrichtung der Bilder zu fixieren abhängig von EXIF-DatenOut of Memory Exception bei der Verarbeitung von großer Anzahl von Bildern
Image FixImageOrientation(Image srce)
{
const int ExifOrientationId = 0x112;
// Read orientation tag
if (!srce.PropertyIdList.Contains(ExifOrientationId)) return srce;
var prop = srce.GetPropertyItem(ExifOrientationId);
var orient = BitConverter.ToInt16(prop.Value, 0);
// Force value to 1
prop.Value = BitConverter.GetBytes((short)1);
srce.SetPropertyItem(prop);
// MessageBox.Show(orient.ToString());
// Rotate/flip image according to <orient>
switch (orient)
{
case 1:
srce.RotateFlip(RotateFlipType.RotateNoneFlipNone);
return srce;
case 2:
srce.RotateFlip(RotateFlipType.RotateNoneFlipX);
return srce;
case 3:
srce.RotateFlip(RotateFlipType.Rotate180FlipNone);
return srce;
case 4:
srce.RotateFlip(RotateFlipType.Rotate180FlipX);
return srce;
case 5:
srce.RotateFlip(RotateFlipType.Rotate90FlipX);
return srce;
case 6:
srce.RotateFlip(RotateFlipType.Rotate90FlipNone);
return srce;
case 7:
srce.RotateFlip(RotateFlipType.Rotate270FlipX);
return srce;
case 8:
srce.RotateFlip(RotateFlipType.Rotate270FlipNone);
return srce;
default:
srce.RotateFlip(RotateFlipType.RotateNoneFlipNone);
return srce;
}
}
ich einen großen Stapel von Bildern wie diese
for (x= 0; x<list.Count; x++)
{
filepath= list.ElementAt(x);
Bitmap image = new Bitmap(FixImageOrientation(Bitmap.FromFile(filepath)));
//Do long processing and at the end i do image.dispose();
image.dispose();
}
verarbeiten Aber
bei der Verarbeitung einer großen Stapel von Bildern i Out of Memory Exception bei
Bitmap image = new Bitmap(FixImageOrientation(Bitmap.FromFile(filepath)));
Warum bekomme ich das .. Ich habe dieses Bild am Ende der Schleife, denke ich.
Sie erstellen 2 Bilder und Entsorgung nur eine 'Bitmap.FromFile (filepath)' und 'neue Bitmap ('. –
Ghetto Art und Weise, offene Fenster Aufgabe verwalten, wenn Sie Ihr Programm ausführen. Wenn Sie sehen, der Speicher steigt schnell, Sie haben irgendwo ein Speicherleck, –