![[Cocoa]_[初级]_[使用NSAffineTransfrom 对NSImage图片进行旋转],第1张 [Cocoa]_[初级]_[使用NSAffineTransfrom 对NSImage图片进行旋转],第1张](/aiimages/%5BCocoa%5D_%5B%E5%88%9D%E7%BA%A7%5D_%5B%E4%BD%BF%E7%94%A8NSAffineTransfrom+%E5%AF%B9NSImage%E5%9B%BE%E7%89%87%E8%BF%9B%E8%A1%8C%E6%97%8B%E8%BD%AC%5D.png)
-(NSImage *)roateSourceImage:(NSImage *) sourceImage Bydegrees:(CGfloat)degrees{ NSautoreleasePool *pool = [NSautoreleasePool new]; NSRect imageBounds = {NSZeroPoint,[sourceImage size]}; NSBezIErPath* boundsPath = [NSBezIErPath bezIErPathWithRect:imageBounds]; NSAffinetransform* transform = [NSAffinetransform transform]; [transform rotateBydegrees:degrees]; [boundsPath transformUsingAffinetransform:transform]; NSRect rotatedBounds = {NSZeroPoint,[boundsPath bounds].size}; NSImage* rotatedImage = [[NSImage alloc] initWithSize:rotatedBounds.size]; // center the image within the rotated bounds imageBounds.origin.x = NSMIDX(rotatedBounds) - (NSWIDth (imageBounds) / 2); imageBounds.origin.y = NSMIDY(rotatedBounds) - (NSHeight (imageBounds) / 2); // set up the rotation transform transform = [NSAffinetransform transform]; [transform translateXBy:+(NSWIDth(rotatedBounds) / 2) yBy:+ (NSHeight(rotatedBounds) / 2)]; [transform rotateBydegrees:degrees]; [transform translateXBy:-(NSWIDth(rotatedBounds) / 2) yBy:- (NSHeight(rotatedBounds) / 2)]; // draw the original image,rotated,into the new image [rotatedImage lockFocus]; [transform set] ; [sourceImage drawInRect:imageBounds fromrect:NSZeroRect operation:NSCompositecopy fraction:1.0]; [rotatedImage unlockFocus] ; [pool drain]; return rotatedImage ;} 总结 以上是内存溢出为你收集整理的[Cocoa]_[初级]_[使用NSAffineTransfrom 对NSImage图片进行旋转]全部内容,希望文章能够帮你解决[Cocoa]_[初级]_[使用NSAffineTransfrom 对NSImage图片进行旋转]所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)