by joe.pesch
27. December 2013 08:14
This method uses ExifExtractor code referenced below from CodeProject.com.
public static Bitmap AutoRotateImage(Bitmap bmp)
{
// Get source from: http://www.codeproject.com/KB/graphics/exifextractor.aspx?fid=207371
var exif = new EXIFextractor(ref bmp, "n");
switch (int.Parse(exif["Orientation"].ToString()))
{
case 1:
bmp.RotateFlip(RotateFlipType.RotateNoneFlipNone);
break;
case 2:
bmp.RotateFlip(RotateFlipType.RotateNoneFlipX);
break;
case 3:
bmp.RotateFlip(RotateFlipType.Rotate180FlipNone);
break;
case 4:
bmp.RotateFlip(RotateFlipType.Rotate180FlipX);
break;
case 5:
bmp.RotateFlip(RotateFlipType.Rotate90FlipX);
break;
case 6:
bmp.RotateFlip(RotateFlipType.Rotate90FlipNone);
break;
case 7:
bmp.RotateFlip(RotateFlipType.Rotate270FlipX);
break;
case 8:
bmp.RotateFlip(RotateFlipType.Rotate270FlipNone);
break;
default:
bmp.RotateFlip(RotateFlipType.RotateNoneFlipNone);
break;
}
return bmp;
}
93fdfe2b-4f4d-4c65-8ef8-f74c5cc5ab7d|2|4.5|96d5b379-7e1d-4dac-a6ba-1e50db561b04
Tags:
C#
by joe.pesch
1. December 2013 14:12
When running inside a foreach() statement this error will occur unless you convert the Entity objects into a List.
// Original code that errors:
myFlickr = FlickrAuthentication();
using (FlickrPicsModel.FlickrPicsEntities dbx = new FlickrPicsModel.FlickrPicsEntities())
{
foreach (FlickrPicsModel.Pic pic in dbx.Pics.Where(t => t.ProcessDate.Value >= MinDate &&
t.FlickrPhotoId == null))
{
pic.FlickrPhotoId = myFlickr.UploadPicture(string.Concat(pic.FilePath, @"\", pic.FileName)
, pic.FlickrTags, pic.FlickrTags, pic.FlickrTags + ",CS-" + pic.CheckSum.ToString());
dbx.SaveChanges();
}
}
// New code converting to IList:
myFlickr = FlickrAuthentication();
using (FlickrPicsModel.FlickrPicsEntities dbx = new FlickrPicsModel.FlickrPicsEntities())
{
foreach (FlickrPicsModel.Pic pic in dbx.Pics.Where(t => t.ProcessDate.Value >= MinDate &&
t.FlickrPhotoId == null).ToList())
{
pic.FlickrPhotoId = myFlickr.UploadPicture(string.Concat(pic.FilePath, @"\", pic.FileName)
, pic.FlickrTags, pic.FlickrTags, pic.FlickrTags + ",CS-" + pic.CheckSum.ToString());
dbx.SaveChanges();
}
}
Error Message: New transaction is not allowed because there are other threads running in the session.
87349f12-2c2e-4088-b2dc-182cf0eebeb4|0|.0|96d5b379-7e1d-4dac-a6ba-1e50db561b04
Tags: