###前提・実現したいこと
iOSアプリにてUIImageのカラースペースを変更を行いました。
カラースペースの変換は行えたのですが、下記のコードを実行すると上下が逆さまの画像が出来上がります。
※画像を回転すれば良いのですが根本的な解決ではないので…
###発生している問題・エラーメッセージ
画像が上下逆となってしまいます。
###該当のソースコード
Objective
1- (UIImage *)convertImageToGrayScale:(UIImage *)image 2{ 3 // Create image rectangle with current image width/height 4 CGRect imageRect = CGRectMake(0, 0, 733, 550);//733, 550 5 6 // DeviceRGB color space 7// CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray(); 8 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 9 10 // Create bitmap content with current image size and DeviceRGB colorspace 11 CGContextRef context = CGBitmapContextCreate(nil, 733, 550, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast); 12 13 // Draw image into current context, with specified rectangle 14 // using previously defined context (with DeviceRGB colorspace) 15 CGContextDrawImage(context, imageRect, [image CGImage]); 16 17 // Create bitmap image info from pixel data in current context 18 CGImageRef imageRef = CGBitmapContextCreateImage(context); 19 20 // Create a new UIImage object 21 UIImage *newImage = [UIImage imageWithCGImage:imageRef]; 22 23 // Release colorspace, context and bitmap information 24 CGColorSpaceRelease(colorSpace); 25 CGContextRelease(context); 26 CFRelease(imageRef); 27 28 // Return the new grayscale image 29 return newImage; 30}
###試したこと 上記のソースコードでuiimageを作成しました。 ###補足情報(言語/FW/ツール等のバージョンなど) 言語: Objective-C 開発環境: Xcode 8.1 OS: iOS10.2 些細な情報でも構いませんので、情報をいただけると幸いです。 ご協力よろしくお願いいたします。
あなたの回答
tips
プレビュー