2009-06-25 12 views
8

मैं आईआईएम पर पोर्ट्रेट मोड में एक फोटो लेने और वेब पर सहेजने के लिए UIImagePickerController का उपयोग कर रहा हूं। फोटो फोन पर चित्र में दिखाई देता है, लेकिन वेब पर 90 डिग्री घुमाता है।वेब पर अपलोड किए जाने पर आईफोन कैमरा छवियों को घुमाया जाता है

अगर मैं फोटो डाउनलोड करता हूं और इसे पूर्वावलोकन (मैक) या फ़ोटोशॉप (मैक या पीसी) में देखता हूं तो यह फिर से चित्र में होता है। विंडोज पिक्चर व्यूअर (पीसी) में यह परिदृश्य में घुमाया गया है।

क्या मुझे अपलोड करने से पहले छवि डेटा में घूर्णन परिवर्तन लागू करने की आवश्यकता है? क्या मुझे फ़ोटोशॉप में और पूर्वावलोकन में घूमने वाले मेटा-डेटा को भी हटाने की आवश्यकता होगी?

उत्तर

7

समस्या यह थी कि तस्वीर में छवि रोटेशन जोड़ा गया था क्योंकि अधिकांश ब्राउज़रों द्वारा EXIF ​​डेटा का उपयोग नहीं किया जाता था। दो समाधान हैं:

  1. सर्वर पक्ष पर रोटेशन लागू करें। मैं रूबी प्लगइन पेपरक्लिप (थॉटबॉट द्वारा) का उपयोग कर रहा था और मॉडल में हैश_टैच_फाइल कमांड में ऑटो-ओरिएंट कन्वर्ट विकल्प को शामिल करना था:

    has_attached_file: फोटो,: convert_options => {: all => '-auto -ऑरिएंट '}

  2. आईफोन ऐप के भीतर फोटो घुमाएं। यह एक और stackoverflow सवाल में हल किया गया था; scaleAndRotate method को कॉल करने से रोटेशन मेटा-डेटा को छवि परिवर्तन के साथ बदल दिया जाता है, धन्यवाद @ स्क्वीगी।

+0

# 2 अच्छी तरह से काम करता है – byron

0

एक बार जब आप सर्वर से छवि अपलोड करने से पहले फोटो लेने के लिए सिर्फ एक विधि में अपने लिया छवि गुजरती हैं और अपने निश्चित रूप से आप

लिए काम करता है
#pragma mark Rotate 
- (UIImage *)scaleAndRotateImage:(UIImage *)image { 
    int kMaxResolution = 640; // Or whatever 

    CGImageRef imgRef = image.CGImage; 

    CGFloat width = CGImageGetWidth(imgRef); 
    CGFloat height = CGImageGetHeight(imgRef); 


    CGAffineTransform transform = CGAffineTransformIdentity; 
    CGRect bounds = CGRectMake(0, 0, width, height); 
    if (width > kMaxResolution || height > kMaxResolution) { 
     CGFloat ratio = width/height; 
     if (ratio > 1) { 
      bounds.size.width = kMaxResolution; 
      bounds.size.height = roundf(bounds.size.width/ratio); 
     } 
     else { 
      bounds.size.height = kMaxResolution; 
      bounds.size.width = roundf(bounds.size.height * ratio); 
     } 
    } 

    CGFloat scaleRatio = bounds.size.width/width; 
    CGSize imageSize = CGSizeMake(CGImageGetWidth(imgRef), CGImageGetHeight(imgRef)); 
    CGFloat boundHeight; 
    UIImageOrientation orient = image.imageOrientation; 
    switch(orient) { 

     case UIImageOrientationUp: //EXIF = 1 
      transform = CGAffineTransformIdentity; 
      break; 

     case UIImageOrientationUpMirrored: //EXIF = 2 
      transform = CGAffineTransformMakeTranslation(imageSize.width, 0.0); 
      transform = CGAffineTransformScale(transform, -1.0, 1.0); 
      break; 

     case UIImageOrientationDown: //EXIF = 3 
      transform = CGAffineTransformMakeTranslation(imageSize.width, imageSize.height); 
      transform = CGAffineTransformRotate(transform, M_PI); 
      break; 

     case UIImageOrientationDownMirrored: //EXIF = 4 
      transform = CGAffineTransformMakeTranslation(0.0, imageSize.height); 
      transform = CGAffineTransformScale(transform, 1.0, -1.0); 
      break; 

     case UIImageOrientationLeftMirrored: //EXIF = 5 
      boundHeight = bounds.size.height; 
      bounds.size.height = bounds.size.width; 
      bounds.size.width = boundHeight; 
      transform = CGAffineTransformMakeTranslation(imageSize.height, imageSize.width); 
      transform = CGAffineTransformScale(transform, -1.0, 1.0); 
      transform = CGAffineTransformRotate(transform, 3.0 * M_PI/2.0); 
      break; 

     case UIImageOrientationLeft: //EXIF = 6 
      boundHeight = bounds.size.height; 
      bounds.size.height = bounds.size.width; 
      bounds.size.width = boundHeight; 
      transform = CGAffineTransformMakeTranslation(0.0, imageSize.width); 
      transform = CGAffineTransformRotate(transform, 3.0 * M_PI/2.0); 
      break; 

     case UIImageOrientationRightMirrored: //EXIF = 7 
      boundHeight = bounds.size.height; 
      bounds.size.height = bounds.size.width; 
      bounds.size.width = boundHeight; 
      transform = CGAffineTransformMakeScale(-1.0, 1.0); 
      transform = CGAffineTransformRotate(transform, M_PI/2.0); 
      break; 

     case UIImageOrientationRight: //EXIF = 8 
      boundHeight = bounds.size.height; 
      bounds.size.height = bounds.size.width; 
      bounds.size.width = boundHeight; 
      transform = CGAffineTransformMakeTranslation(imageSize.height, 0.0); 
      transform = CGAffineTransformRotate(transform, M_PI/2.0); 
      break; 

     default: 
      [NSException raise:NSInternalInconsistencyException format:@"Invalid image orientation"]; 

    } 

    UIGraphicsBeginImageContext(bounds.size); 

    CGContextRef context = UIGraphicsGetCurrentContext(); 

    if (orient == UIImageOrientationRight || orient == UIImageOrientationLeft) { 
     CGContextScaleCTM(context, -scaleRatio, scaleRatio); 
     CGContextTranslateCTM(context, -height, 0); 
    } 
    else { 
     CGContextScaleCTM(context, scaleRatio, -scaleRatio); 
     CGContextTranslateCTM(context, 0, -height); 
    } 

    CGContextConcatCTM(context, transform); 

    CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, width, height), imgRef); 
    UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    return imageCopy; 
} 
+0

मेरा मानना ​​है कि आपकी टिप्पणियां गलत हैं। जैसे UIImageOrientationUp: // EXIF ​​= 0 – jonypz

-1

एमएस विंडोज़ में सही अभिविन्यास में छवि सहेजी गई है, तो EXIF ​​रोटेशन मेटाडेटा को मैन्युअल रूप से ओवरराइड करने का एक आसान तरीका यहां है। विंडोज एक्सप्लोरर में, छवि फ़ाइल पर राइट-क्लिक करें और "घड़ी की दिशा घुमाएं" का चयन करें। छवि को चारों तरफ घुमाने के लिए यह 4 बार करें, और फिर छवि के सभी सिस्टम के लिए सही अभिविन्यास होगा। फिर आप छवि को अपने वेब सर्वर पर अपलोड कर सकते हैं।

संबंधित मुद्दे