• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

UIImageで取得できる画像とUIImage.CGImageで取得できる画像が上下逆転してしまいます。原因はUIKitとCoreGraphicsで、座標系のY軸が反転しているからだそうです(takiuchiさん談)。

下記を参考にしました:
http://blog.logichigh.com/2008/06/05/uiimage-fix/

UIImage.CGImageをrorateする

   1    UIImage *sampleImage = [UIImage imageNamed:@"image.png"];	
   2    CGRect rect = CGRectMake(0,0, sampleImage.size.width, sampleImage.size.height);
   3   
   4   //create the context
   5    UIGraphicsBeginImageContext(rect.size);
   6    CGContextRef i_context = UIGraphicsGetCurrentContext();
   7  	
   8    CGContextDrawImage(i_context, rect, sampleImage.CGImage);
   9    CGAffineTransform transform = CGAffineTransformRotate(transform, M_PI);
  10    CGContextConcatCTM(i_context, transform);
  11    UIImage *rotatedImage = UIGraphicsGetImageFromCurrentImageContext();
  12    CGImageRef sampleImageRef = [rotatedImage CGImage];
  13  
  14    //release the context
  15    UIGraphicsEndImageContext();
  16    CGContextRelease(i_context);

ちなみに、Quartz 2Dなどは昔の名前らしく、今は、CoreGraphicsと呼ばれています。最近はCoreImage, CoreGraphics, CoreAnimationのようにCoreシリーズで統一しているようです。

posted by Png satoko on Wed 21 Jan 2009 at 15:28 with 1 comment

Comments:

Png satoko over 15 years ago.

CGContextScaleCTM で sx=1.0, sy=-1.0 にするっていう方法もいいかもというアドバイス頂きました。

or Preview
Social Bookmarks
  • Delicious
  • B_entry1233
  • Clip_16_12_w
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ