我在iOS 3.1.3 iPhone上测试我的iPhone应用程序.我使用以下方法选择/捕获图像UIImagePickerController:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setDelegate:self];
[self.navigationController presentModalViewController:imagePicker animated:YES];
[imagePicker release];
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
self.image = [info objectForKey:UIImagePickerControllerOriginalImage];
imageView.image = self.image;
[self.navigationController dismissModalViewControllerAnimated:YES];
submitButton.enabled = YES;
}
Run Code Online (Sandbox Code Playgroud)
然后我在某个时候使用ASI类将它发送到我的Web服务器:
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://example.com/myscript.php"]];
[request setDelegate:self];
[request setStringEncoding:NSUTF8StringEncoding];
[request setShouldContinueWhenAppEntersBackground:YES];
//other post keys/values
[request setFile:UIImageJPEGRepresentation(self.image, 100.0f) withFileName:[NSString stringWithFormat:@"%d.jpg", [[NSDate date] timeIntervalSinceNow]] andContentType:@"image/jpg" forKey:@"imageFile"];
[request startAsynchronous];
Run Code Online (Sandbox Code Playgroud)
问题:当我用iphone拍照同时保持它的风景时,图像会上传到服务器并按照你的预期进行查看.当拍摄手机拍照时,图像会被上传并在旋转90度时被观看.
我的应用程序设置为仅在纵向模式下工作(颠倒和常规).
如何在上传后使图像始终显示正确的方向?
UIImageView中显示的图像看起来是正确的(在拍照后直接显示),但在服务器上查看则另有说明.
我已经研究了足够的工作,但无法修复它.只要我将图像存储为UIImage,从相机拍照后,它就可以了,但只要我将此图像存储为PNG表示,它就会旋转90度.
以下是我的代码和我尝试过的所有事情:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info valueForKey:UIImagePickerControllerMediaType];
if([mediaType isEqualToString:(NSString*)kUTTypeImage])
{
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
delegate.originalPhoto = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSLog(@"Saving photo");
[self saveImage];
NSLog(@"Fixing orientation");
delegate.fixOrientationPhoto = [self fixOrientation:[UIImage imageWithContentsOfFile:[delegate filePath:imageName]]];
NSLog(@"Scaling photo");
delegate.scaledAndRotatedPhoto = [self scaleAndRotateImage:[UIImage imageWithContentsOfFile:[delegate filePath:imageName]]];
}
[picker dismissModalViewControllerAnimated:YES];
[picker release];
}
- (void)saveImage
{
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSData *imageData = UIImagePNGRepresentation(delegate.originalPhoto);
[imageData writeToFile:[delegate filePath:imageName] atomically:YES];
}
Run Code Online (Sandbox Code Playgroud)
这里分别从这里和这里取得fixOrientation和scaleAndRotateImage函数.当我在UIImage上应用它们时,它们工作正常并旋转图像,但如果我将图像保存为PNG表示并应用它们则不起作用.
请执行以上功能后请参考以下图片:

我有一个PNG图像具有不受支持的位图图形上下文像素格式.每当我尝试调整图像大小时,都会CGBitmapContextCreate()以不支持的格式进行扼流
我收到以下错误(格式错误,以方便阅读):
CGBitmapContextCreate: unsupported parameter combination:
8 integer bits/component;
32 bits/pixel;
3-component colorspace;
kCGImageAlphaLast;
1344 bytes/row.
Run Code Online (Sandbox Code Playgroud)
在支持的像素格式列表绝对不支持这种组合.看来我需要重绘图像并将alpha通道信息移动到kCGImageAlphaPremultipliedFirst或kCGImageAlphaPremultipliedLast.
我不知道该怎么做.
PNG文件没有任何异常,并且没有损坏.它在所有其他环境中工作得很好.我偶然遇到这个错误,但显然我的用户可能有类似格式的文件,所以我必须检查我的应用程序的导入图像并纠正这个问题.
我正在开发一个应用程序,我在纵向模式下捕获图像,然后移动到另一个带有图像数据的类,并在UIScrollView上的UIImageView中显示该图像.
现在,如果我正在使用图像表单库,它工作正常,但如果我必须捕获图像,它将以横向模式显示数据.下面是我的两个类的代码.:
第1类:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSData *imgData = UIImagePNGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"]);
[picker dismissModalViewControllerAnimated:YES];
image = [[UIImage alloc] initWithData:imgData];
CGImageRef imgRefCrop = image.CGImage;
UIImage *photo = [UIImage imageWithCGImage:imgRefCrop];
PhotoCropperPage *photoCropper = [[PhotoCropperPage alloc]
initWithPhoto:photo
delegate:self
uiMode:PCPUIModePresentedAsModalViewController
showsInfoButton:YES];
[photoCropper setMinZoomScale:0.3f];
[photoCropper setMaxZoomScale:4.0f];
[self.navigationController pushViewController:photoCropper animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
第2类:
- (void) loadPhoto
{
if (self.photo == nil) {
return;
}
CGFloat w = self.photo.size.width;
CGFloat h = self.photo.size.height;
CGRect imageViewFrame = CGRectMake(0.0f, 0.0f, roundf(w / 2.0f), roundf(h / 2.0f));
self.scrollView.contentSize = …Run Code Online (Sandbox Code Playgroud) iphone ×4
uiimage ×2
alpha ×1
cgimage ×1
cocoa-touch ×1
ios ×1
ios5.1 ×1
objective-c ×1
png ×1
uiimageview ×1