- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个通用应用程序,我正在为 iOS6 编码。
我正在使用 imagePickerController 拍摄照片,然后使用 MFMailComposeViewController 将其作为附件发送。所有这些都在起作用。
我的问题是,当我以纵向模式拍摄照片时,MFMailComposeViewController 以横向模式显示它。此外,当它到达目的地电子邮件地址时,它以横向模式显示。
如果我以横向模式拍摄图片,它会在横向模式下由 MFMailComposeViewController 显示,当它到达目标电子邮件地址时,它以横向模式显示。所以没关系。
我的两个测试设备都有同样的问题;一个 iPhone5 和一个 iPad2。
如何使以人像模式拍摄的照片以人像模式到达电子邮件目的地?
这是我将图像添加到电子邮件的方法:
if ( [MFMailComposeViewController canSendMail] )
{
MFMailComposeViewController * mailVC = [MFMailComposeViewController new];
NSArray * aAddr = [NSArray arrayWithObjects: gAddr, nil];
NSData * imageAsNSData = UIImagePNGRepresentation( gImag );
[mailVC setMailComposeDelegate: self];
[mailVC setToRecipients: aAddr];
[mailVC setSubject: gSubj];
[mailVC addAttachmentData: imageAsNSData
mimeType: @"image/png"
fileName: @"myPhoto.png"];
[mailVC setMessageBody: @"Blah blah"
isHTML: NO];
[self presentViewController: mailVC
animated: YES
completion: nil];
}
else
{
NSLog( @"Device is unable to send email in its current state." );
}
最佳答案
我已经花了很多时间来解决这个问题,现在我很清楚发生了什么以及如何解决它。
再说一遍,我遇到的问题是:
当我使用 imagePickerController 在相机上以纵向模式拍摄图像并将该图像传递给 MFMailComposeViewController 并通过电子邮件发送时,它到达目标电子邮件地址并在横向模式下错误显示。
但是,如果我以横向模式拍摄照片然后发送,它会在横向模式下正确显示在电子邮件的目的地
那么,怎样才能让以人像模式拍摄的照片以人像模式到达电子邮件目的地呢?那是我最初的问题。
这是代码,正如我在原始问题中所展示的那样,除了我现在将图像作为 JPEG 而不是 PNG 发送,但这没有任何区别。
这就是我如何使用 imagePickerController 捕获图像并将其放入名为 gImag 的全局变量中:
gImag = (UIImage *)[info valueForKey: UIImagePickerControllerOriginalImage];
[[self imageView] setImage: gImag]; // send image to screen
[self imagePickerControllerRelease: picker ]; // free the picker object
if ( [MFMailComposeViewController canSendMail] )
{
MFMailComposeViewController * mailVC = [MFMailComposeViewController new];
NSArray * aAddr = [NSArray arrayWithObjects: gAddr, nil];
NSData * imageAsNSData = UIImageJPEGRepresentation( gImag );
[mailVC setMailComposeDelegate: self];
[mailVC setToRecipients: aAddr];
[mailVC setSubject: gSubj];
[mailVC addAttachmentData: imageAsNSData
mimeType: @"image/jpg"
fileName: @"myPhoto.jpg"];
[mailVC setMessageBody: @"Blah blah"
isHTML: NO];
[self presentViewController: mailVC
animated: YES
completion: nil];
}
else NSLog( @"Device is unable to send email in its current state." );
UIImageOrientation orient = image.imageOrientation;
gImag = (PIMG)[info valueForKey: UIImagePickerControllerOriginalImage];
UIImageOrientation orient = gImag.imageOrientation;
CGFloat width = CGImageGetWidth(gImag.CGImage);
CGFloat height = CGImageGetHeight(gImag.CGImage);
[[self imageView] setImage: gImag]; // send image to screen
[self imagePickerControllerRelease: picker ]; // free the picker object
if ( [MFMailComposeViewController canSendMail] )
{
MFMailComposeViewController * mailVC = [MFMailComposeViewController new];
NSArray * aAddr = [NSArray arrayWithObjects: gAddr, nil];
UIImageOrientation orient = gImag.imageOrientation;
CGFloat width = CGImageGetWidth(gImag.CGImage);
CGFloat height = CGImageGetHeight(gImag.CGImage);
NSData * imageAsNSData = UIImageJPEGRepresentation( gImag );
[mailVC setMailComposeDelegate: self];
[mailVC setToRecipients: aAddr];
[mailVC setSubject: gSubj];
[mailVC addAttachmentData: imageAsNSData
mimeType: @"image/jpg"
fileName: @"myPhoto.jpg"];
[mailVC setMessageBody: @"Blah blah"
isHTML: NO];
[self presentViewController: mailVC
animated: YES
completion: nil];
}
else NSLog( @"Device is unable to send email in its current state." );
[[self imageView] setImage: gImag]; // send image to screen
if ( [MFMailComposeViewController canSendMail] )
{
MFMailComposeViewController * mailVC = [MFMailComposeViewController new];
NSArray * aAddr = [NSArray arrayWithObjects: gAddr, nil];
UIImageOrientation orient = gImag.imageOrientation;
CGFloat width = CGImageGetWidth(gImag.CGImage);
CGFloat height = CGImageGetHeight(gImag.CGImage);
UIImage * tmp = [[UIImage alloc] initWithCGImage: gImag.CGImage];
orient = tmp.imageOrientation;
width = CGImageGetWidth(tmp.CGImage);
height = CGImageGetHeight(tmp.CGImage);
NSData * imageAsNSData = UIImageJPEGRepresentation( tmp );
[mailVC setMailComposeDelegate: self];
[mailVC setToRecipients: aAddr];
[mailVC setSubject: gSubj];
[mailVC addAttachmentData: imageAsNSData
mimeType: @"image/jpg"
fileName: @"myPhoto.jpg"];
[mailVC setMessageBody: @"Blah blah"
isHTML: NO];
[self presentViewController: mailVC
animated: YES
completion: nil];
}
else NSLog( @"Device is unable to send email in its current state." );
UIImage * tmp = [UIImage imageWithCGImage: gImag.CGImage
scale: gImag.scale
orientation: gImag.imageOrientation];
gImag = (PIMG)[info valueForKey: UIImagePickerControllerOriginalImage];
[[self imageView] setImage: gImag]; // send image to screen
[self imagePickerControllerRelease: picker ]; // free the picker object
if ( [MFMailComposeViewController canSendMail] )
{
MFMailComposeViewController * mailVC = [MFMailComposeViewController new];
NSArray * aAddr = [NSArray arrayWithObjects: gAddr, nil];
//...lets not touch the original UIImage
UIImage * tmpImag = [UIImage imageWithCGImage: gImag.CGImage
scale: gImag.scale
orientation: gImag.imageOrientation];
//...do physical rotation, if needed
PIMG ImgOut = [gU scaleAndRotateImage: tmpImag];
//...note orientation is UIImageOrientationUp now
NSData * imageAsNSData = UIImageJPEGRepresentation( ImgOut, 0.9f );
[mailVC setMailComposeDelegate: self];
[mailVC setToRecipients: aAddr];
[mailVC setSubject: gSubj];
[mailVC addAttachmentData: imageAsNSData
mimeType: @"image/jpg"
fileName: @"myPhoto.jpg"];
[mailVC setMessageBody: @"Blah blah"
isHTML: NO];
[self presentViewController: mailVC
animated: YES
completion: nil];
}
else NSLog( @"Device is unable to send email in its current state." );
- (UIImage *) scaleAndRotateImage: (UIImage *) imageIn
//...thx: http://blog.logichigh.com/2008/06/05/uiimage-fix/
{
int kMaxResolution = 3264; // Or whatever
CGImageRef imgRef = imageIn.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 = bounds.size.width / ratio;
}
else
{
bounds.size.height = kMaxResolution;
bounds.size.width = bounds.size.height * ratio;
}
}
CGFloat scaleRatio = bounds.size.width / width;
CGSize imageSize = CGSizeMake( CGImageGetWidth(imgRef), CGImageGetHeight(imgRef) );
UIImageOrientation orient = imageIn.imageOrientation;
CGFloat boundHeight;
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 );
}
关于iphone - MFMailComposeViewController 图像方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20204495/
我的应用程序处于横向模式。当我通过当前模型 View 调用 MFMailComposeViewController 时,它进入横向模式。我旋转设备并且 MFMailComposeViewControl
我使用 MFMailComposeViewController 在我的应用程序中发送邮件。但是,当当前邮件撰写 View Controller 时,所有导航按钮都被禁用(选择邮件地址屏幕中的后退按钮除
我使用MFMailComposeViewController向其他人发送邮件。单击按钮时,撰写表将打开,我可以输入收件人地址、主题、邮件正文。但点击发送按钮后,邮件页面没有关闭。 代码: if ([M
我正在尝试向我的应用程序添加电子邮件功能。我可以让 MFMailComposeViewController 正确显示并预填充其主题和正文,但由于某种原因,当用户单击导航栏中的“取消”或“发送”按钮时,
我正在使用 MFMailComposeViewController,一切看起来都很好。该类表明邮件已发送,但我从未在模拟器上设置过电子邮件,也不知道如何设置。那么如果发送了,它发送到哪个电子邮件服务器
if ([MFMailComposeViewController canSendMail]) { MFMailComposeViewController *mailViewController
我尝试在我的应用程序中插入邮件工具......我的应用程序基于cocos2d引擎 工具栏(顶部 ->取消、发送...)可见,但我看不到 mfMailComposerViewController Vie
由于某种原因,发送和取消按钮没有出现,我什至在应用程序启动时将以下代码粘贴到 appdelegate 中的应用程序开头,但仍然无法正常工作。有谁可以帮忙吗,谢谢 mailController = [[
MFMailComposeViewController 只有英文版本吗!? 我正在考虑使用 MFMailComposeViewController 来处理从我的应用程序发送电子邮件的想法,但我需要它符
我根据API出示了MFMailComposeViewController,一般情况下,界面是正常的,但是我们应用程序的一些用户提示右上角的发送按钮是灰色的(它变成禁用)的问题,她不能按发送按钮,当然我
如何在不按 MFMailComposeViewController 中的“发送”或“取消”按钮的情况下关闭键盘?! 感谢您的帮助。 最佳答案 你能试试这个吗? UIWindow* keyWindow
我正在开发一个通用应用程序,我正在为 iOS6 编码。 我正在使用 imagePickerController 拍摄照片,然后使用 MFMailComposeViewController 将其作为附件
首先,我使用的是 XCode 4.0.2。 好的,这是我的问题。我可以为 MFMailComposerViewController 构建 Apple 示例程序并在模拟器中运行它(我知道它不会发送电子邮
我已经设置了MFMailComposeViewController,它在iPhone上正常工作,但是在iPad上崩溃了,并说: *** Terminating app due to uncaught
我正在使用 MFMailComposeViewController在具有以下代码的 View Controller 中: if !MFMailComposeViewController.canSend
目前我有一个 NSArray 的电子邮件,我打开一个 View 来结束所有这些电子邮件的电子邮件: MFMailComposeViewController *mailer = [[MFMailComp
我正在使用 MFMailComposeViewController在我的应用程序中撰写反馈电子邮件。 MFMailComposeViewController显示,但无法关闭。 用于打开MFMailCo
我已经按照 Swift Guide 完成了 MFMailComposeViewController() 的常规设置 https://developer.apple.com/library/prerel
我正在尝试在 Swift 中创建以下扩展: extension MFMailComposeViewController { convenience init(document: D
单击警报按钮时尝试使用 MFMailComposeViewController。但是当我单击警报按钮时, Controller 不会弹出。代码如下。我使用了扩展程序,并且在单击警报按钮时尝试调用 se
我是一名优秀的程序员,十分优秀!