मेरे कार्यक्रम प्रक्रियाओं batch.I में कुछ छवियों वर्तमान में छवि के exif उन्मुखीकरण टैग पढ़ने की जरूरत के साथ छवि सहेजें, उचित उन्मुखीकरण के लिए यह घुमाने के लिए, कर कुछ प्रसंस्करण और किसी भी EXIF अभिविन्यास टैग के बिना छवि बचाने के लिए, लेकिन उचित रोटेशन के साथ (या उचित अभिविन्यास साथ EXIF टैग के साथ)उचित अभिविन्यास, प्रक्रिया छवि के लिए घुमाएं जाओ EXIF अभिविन्यास टैग, और उचित अभिविन्यास
मैं EXIF पढ़ रहा हूँ और this library का उपयोग कर घूर्णन:।
var bmp = new Bitmap(pathToImageFile);
var exif = new EXIFextractor(ref bmp, "n"); // get source from http://www.codeproject.com/KB/graphics/exifextractor.aspx?fid=207371
if (exif["Orientation"] != null)
{
RotateFlipType flip = OrientationToFlipType(exif["Orientation"].ToString());
if (flip != RotateFlipType.RotateNoneFlipNone) // don't flip of orientation is correct
{
bmp.RotateFlip(flip);
bmp.Save(pathToImageFile, ImageFormat.Jpeg);
}
// Match the orientation code to the correct rotation:
private static RotateFlipType OrientationToFlipType(string orientation)
{
switch (int.Parse(orientation))
{
case 1:
return RotateFlipType.RotateNoneFlipNone;
case 2:
return RotateFlipType.RotateNoneFlipX;
case 3:
return RotateFlipType.Rotate180FlipNone;
case 4:
return RotateFlipType.Rotate180FlipX;
break;
case 5:
return RotateFlipType.Rotate90FlipX;
break;
case 6:
return RotateFlipType.Rotate90FlipNone;
case 7:
return RotateFlipType.Rotate270FlipX;
case 8:
return RotateFlipType.Rotate270FlipNone;
default:
return
}
}
यह काम करता है। लेकिन जब इस छवि को सहेजते हैं, तो एक्सिफ रोटेशन टैग अभी भी मौजूद है जो छवि को गलत अभिविन्यास में बनाता है।
var bmp = new Bitmap(OS.FileName);
var exif = new EXIFextractor(ref bmp, "n");
exif.setTag(0x112, "1");
bmp.save("strippedexifimage");
क्या मैं क्या कर सकते हैं लेकिन जब एक पाश में इस्तेमाल के लिए इस कोड लगभग 50% .is वहाँ एक वैकल्पिक माध्यम से मेरा कार्यक्रम को धीमा कर देती? रोटेशन लगाने के बाद छवि को घुमाने के लिए कोड हो सकता है, क्या वह काम करेगा?
अद्यतन:
@Hans Passant आपका जवाब काम करता है, लेकिन परिणाम यह उत्पादन पुस्तकालय द्वारा उत्पादित लोगों के समान है। जब मैं bitmap.save() का उपयोग करता हूं, दोनों लाइब्रेरी और आपका कोड काम करता है। लेकिन जब मैं उपयोगकर्ता द्वारा चुने गए प्रारूप के आधार पर अपनी छवि को सहेजने के लिए निम्न कोड का उपयोग करता हूं। Imgformat imgformat = "image/png";,imgformat = "image/jpeg";
आदि हो सकता है कुछ छवियों को अभी भी गलत exif अभिविन्यास टैग से बचाया जाता है। यानी: मैं विंडोज एक्सप्लोरर में गलत छवि पूर्वावलोकन देखता हूं, जब मैं एमएस पेंट के साथ छवि खोलता हूं, तो छवि में सही अभिविन्यास होता है। मैं गलत क्या कर रहा हूं? कृपया मदद करे।
private void saveJpeg(string path, Bitmap img, long quality)
{
EncoderParameter qualityParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
ImageCodecInfo Codec = this.getEncoderInfo(imgformat);
if (Codec == null)
return;
EncoderParameters encoderParams = new EncoderParameters(1);
encoderParams.Param[0] = qualityParam;
img.Save(path + ext, Codec, encoderParams);
}
private ImageCodecInfo getEncoderInfo(string mimeType)
{
// Get image codecs for all image formats
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
// Find the correct image codec
for (int i = 0; i < codecs.Length; i++)
if (codecs[i].MimeType == mimeType)
return codecs[i];
return null;
}
ImageMagick पर एक नज़र डालें। मुझे लगता है कि यह सब कुछ आप चाहते हैं। आप इसके लिए कोड लिख सकते हैं .. या बस इसका उपयोग करें। :) – atlaste