견적 양식을 나타내는 클래스가 있습니다. 사진을 찍은 다음 앱에서 첨부 파일로 추가하는 버튼을 추가했습니다. 내 imageView에서는 사진이 세로 방향으로 표시되지만 이메일 첨부 파일에서는 90 ° 회전되어 가로 방향으로 표시됩니다. 이 문제를 어떻게 해결할 수 있습니까?카메라에서 전자 메일 첨부 파일이 세로 방향으로 계속 회전합니다.
2
A
답변
2
또한 동일한 문제를 직면하지만,이 코드는 사진을 촬영할 때 iOS의 카메라로 촬영 된 것이
- (UIImage*)imageWithImage:(UIImage*)sourceImage scaledToSizeWithSameAspectRatio:(CGSize)targetSize
{
CGSize imageSize = sourceImage.size;
CGFloat width = imageSize.width;
CGFloat height = imageSize.height;
CGFloat targetWidth = targetSize.width;
CGFloat targetHeight = targetSize.height;
CGFloat scaleFactor = 0.0;
CGFloat scaledWidth = targetWidth;
CGFloat scaledHeight = targetHeight;
CGPoint thumbnailPoint = CGPointMake(0.0,0.0);
if (CGSizeEqualToSize(imageSize, targetSize) == NO) {
CGFloat widthFactor = targetWidth/width;
CGFloat heightFactor = targetHeight/height;
if (widthFactor > heightFactor) {
scaleFactor = widthFactor; // scale to fit height
}
else {
scaleFactor = heightFactor; // scale to fit width
}
scaledWidth = width * scaleFactor;
scaledHeight = height * scaleFactor;
// center the image
if (widthFactor > heightFactor) {
thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
}
else if (widthFactor < heightFactor) {
thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
}
}
CGImageRef imageRef = [sourceImage CGImage];
CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
CGColorSpaceRef colorSpaceInfo = CGImageGetColorSpace(imageRef);
if (bitmapInfo == kCGImageAlphaNone) {
bitmapInfo = kCGImageAlphaNoneSkipLast;
}
CGContextRef bitmap;
if (sourceImage.imageOrientation == UIImageOrientationUp || sourceImage.imageOrientation == UIImageOrientationDown) {
bitmap = CGBitmapContextCreate(NULL, targetWidth, targetHeight, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, bitmapInfo);
} else {
bitmap = CGBitmapContextCreate(NULL, targetHeight, targetWidth, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, bitmapInfo);
}
// In the right or left cases, we need to switch scaledWidth and scaledHeight,
// and also the thumbnail point
if (sourceImage.imageOrientation == UIImageOrientationLeft) {
thumbnailPoint = CGPointMake(thumbnailPoint.y, thumbnailPoint.x);
CGFloat oldScaledWidth = scaledWidth;
scaledWidth = scaledHeight;
scaledHeight = oldScaledWidth;
CGContextRotateCTM (bitmap, radians(90));
CGContextTranslateCTM (bitmap, 0, -targetHeight);
} else if (sourceImage.imageOrientation == UIImageOrientationRight) {
thumbnailPoint = CGPointMake(thumbnailPoint.y, thumbnailPoint.x);
CGFloat oldScaledWidth = scaledWidth;
scaledWidth = scaledHeight;
scaledHeight = oldScaledWidth;
CGContextRotateCTM (bitmap, radians(-90));
CGContextTranslateCTM (bitmap, -targetWidth, 0);
} else if (sourceImage.imageOrientation == UIImageOrientationUp) {
// NOTHING
} else if (sourceImage.imageOrientation == UIImageOrientationDown) {
CGContextTranslateCTM (bitmap, targetWidth, targetHeight);
CGContextRotateCTM (bitmap, radians(-180.));
}
CGContextDrawImage(bitmap, CGRectMake(thumbnailPoint.x, thumbnailPoint.y, scaledWidth, scaledHeight), imageRef);
CGImageRef ref = CGBitmapContextCreateImage(bitmap);
UIImage* newImage = [UIImage imageWithCGImage:ref];
CGContextRelease(bitmap);
CGImageRelease(ref);
NSLog(@"sourceImage:%i",sourceImage.imageOrientation);
NSLog(@"newImage:%i",newImage.imageOrientation);
return newImage;
}
+0
도움을 주셔서 감사합니다,하지만 그것은 나를 위해 밖으로 작동하지 않습니다. 내 이미지는 첨부 파일에서 여전히 가로 방향임을 나타냅니다. 변수 중 하나를 변경해야합니까? – fmi
+0
원본 이미지의 크기를 변경할 수 있습니다. –
관련 문제
- 1. 전자 메일 첨부 파일이 누락되었습니다.
- 2. PHP 전자 메일 첨부 파일이 통과되지 않음
- 3. Python : 전자 메일 본문에 첨부 파일이 표시됩니다.
- 4. Python 전자 메일 첨부 파일이 비어 있습니다.
- 5. 전자 메일 첨부 파일 링크
- 6. 전자 메일 첨부 파일
- 7. cdonts 첨부 전자 메일
- 8. 첨부 파일이있는 전자 메일 구현
- 9. Python - 첨부 파일이 포함 된 IMAP 전자 메일 (imaplib, smtplib)
- 10. 배달 전자 메일 첨부 이미지 첨부
- 11. PHP 메일() 첨부 파일이 손상되었습니다
- 12. 전자 메일 첨부 파일로 MemoryStream이있는 EPPlus - 파일이 비어 있습니다.
- 13. 전자 메일 용 FPDF 생성 첨부 파일이 이상한 문자로 구성됩니다.
- 14. 전자 메일 첨부 파일이 Glassfish에 포함되어 있지 않음
- 15. python smtplib을 사용하여 전자 메일 첨부 파일이 비정상적으로 작동합니다.
- 16. 클래식 ASP - 첨부 파일이 포함 된 전자 메일 양식 - 도와주세요
- 17. HTML/텍스트 PHP를 사용하는 첨부 파일이 포함 된 전자 메일
- 18. 첨부 파일이 포함 된 새 전자 메일 창 열기
- 19. SMTP를 사용하는 여러 첨부 파일이 포함 된 일괄 전자 메일
- 20. C# Outlook으로 전자 메일 보내기 - 보낼 편지함에 첨부 파일이 없습니다.
- 21. Java Mail - 전자 메일 클라이언트에 첨부 파일이 표시되지 않습니까?
- 22. 전자 메일 첨부 파일 저장
- 23. 첨부 파일이있는 전자 메일 보내기
- 24. Tomcat에서 Java 메일 첨부 파일이 작동하지 않습니다.
- 25. PHP 메일 첨부 파일이 인코딩 된 형식의 메일 본문에 표시됩니다.
- 26. SQL에서 ASPNet 전자 메일 첨부 파일
- 27. cakephp의 동적 전자 메일 첨부 파일
- 28. Android에서 전자 메일 첨부 파일로 PDF 보내기
- 29. 자바를 사용하여 전자 메일 첨부 파일 다운로드
- 30. 전자 메일 첨부 파일 메타 데이터 저장
이미지는 장치의 방위에 기초하여 imageOrientation 속성 집합을 해결한다. 많은 앱이이 속성을 지원하지 않으므로 이미지가 회전 된 것처럼 보입니다. 이미지를 촬영 한 후 이미지를 회전하여이 문제를 해결하십시오. UIImagePickerController로 찍은 이미지를 회전/방향 지정하기 위해 SO를 검색하십시오. 여기에이 주제에 대한 많은 도움이 있습니다. – XJones
앱에서 사용할 수있는 유일한보기는 세로이므로 다른 항목이 표시된다는 것에 놀랐습니다. 귀하의 기준에 따라 검색하겠습니다 ... 감사합니다 – fmi
앱의 방향은 중요하지 않습니다. 'UIImagePickerController'를 사용하여 사진을 찍을 때, 사진을 찍을 때 장치를 잡는 방법에 따라'imageOrientation'이 설정됩니다. – XJones