<small id='B4R4U'></small><noframes id='B4R4U'>

      <bdo id='B4R4U'></bdo><ul id='B4R4U'></ul>
    1. <tfoot id='B4R4U'></tfoot>

    2. <i id='B4R4U'><tr id='B4R4U'><dt id='B4R4U'><q id='B4R4U'><span id='B4R4U'><b id='B4R4U'><form id='B4R4U'><ins id='B4R4U'></ins><ul id='B4R4U'></ul><sub id='B4R4U'></sub></form><legend id='B4R4U'></legend><bdo id='B4R4U'><pre id='B4R4U'><center id='B4R4U'></center></pre></bdo></b><th id='B4R4U'></th></span></q></dt></tr></i><div id='B4R4U'><tfoot id='B4R4U'></tfoot><dl id='B4R4U'><fieldset id='B4R4U'></fieldset></dl></div>

    3. <legend id='B4R4U'><style id='B4R4U'><dir id='B4R4U'><q id='B4R4U'></q></dir></style></legend>

    4. 在 UIImageView 中旋转图像

      时间:2024-04-14
      • <legend id='c9HLm'><style id='c9HLm'><dir id='c9HLm'><q id='c9HLm'></q></dir></style></legend>

          <bdo id='c9HLm'></bdo><ul id='c9HLm'></ul>

          <small id='c9HLm'></small><noframes id='c9HLm'>

            <tbody id='c9HLm'></tbody>
          1. <i id='c9HLm'><tr id='c9HLm'><dt id='c9HLm'><q id='c9HLm'><span id='c9HLm'><b id='c9HLm'><form id='c9HLm'><ins id='c9HLm'></ins><ul id='c9HLm'></ul><sub id='c9HLm'></sub></form><legend id='c9HLm'></legend><bdo id='c9HLm'><pre id='c9HLm'><center id='c9HLm'></center></pre></bdo></b><th id='c9HLm'></th></span></q></dt></tr></i><div id='c9HLm'><tfoot id='c9HLm'></tfoot><dl id='c9HLm'><fieldset id='c9HLm'></fieldset></dl></div>

            • <tfoot id='c9HLm'></tfoot>

                本文介绍了在 UIImageView 中旋转图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                是否可以只旋转 UIImageView 中的图像?我正在寻找有关它的信息,但我只找到了如何旋转 UIImageVeiw 的信息.

                Is it possible to rotate only image in UIImageView? I'm looking for information about it, but i only found information how rotate UIImageVeiw.

                推荐答案

                您可以使用以下代码旋转图像.请注意,这使用了一个 CGImageRef,您可以通过

                You can rotate the image with the following code. Note, this uses a CGImageRef which you can get from a UIImage via

                CGImageRef imageRef = [self CGImageRotatedByAngle:[image CGImage] angle:30];
                

                获得旋转后的图像后,您可以将 ImageView 的图像设置为新的旋转图像,如下所示:

                Once you get the rotated image, you can set the ImageView's image to your new rotated image like this:

                UIImage* img = [UIImage imageWithCGImage: imageRef];
                myImageView.image = img;
                

                这是一个旋转 imageRef 的方法:

                here is a method that will rotate the imageRef:

                - (CGImageRef)CGImageRotatedByAngle:(CGImageRef)imgRef angle:(CGFloat)angle
                {
                
                    CGFloat angleInRadians = angle * (M_PI / 180);
                    CGFloat width = CGImageGetWidth(imgRef);
                    CGFloat height = CGImageGetHeight(imgRef);
                
                    CGRect imgRect = CGRectMake(0, 0, width, height);
                    CGAffineTransform transform = CGAffineTransformMakeRotation(angleInRadians);
                    CGRect rotatedRect = CGRectApplyAffineTransform(imgRect, transform);
                
                    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
                
                    CGContextRef bmContext = CGBitmapContextCreate(NULL,
                                                                   rotatedRect.size.width,
                                                                   rotatedRect.size.height,
                                                                   8,
                                                                   0,
                                                                   colorSpace,
                                                                   kCGImageAlphaPremultipliedFirst);
                    CGContextSetAllowsAntialiasing(bmContext, YES);
                    CGContextSetShouldAntialias(bmContext, YES);
                    CGContextSetInterpolationQuality(bmContext, kCGInterpolationHigh);
                    CGColorSpaceRelease(colorSpace);
                    CGContextTranslateCTM(bmContext,
                                          +(rotatedRect.size.width/2),
                                          +(rotatedRect.size.height/2));
                    CGContextRotateCTM(bmContext, angleInRadians);
                    CGContextTranslateCTM(bmContext,
                                          -(rotatedRect.size.width/2),
                                          -(rotatedRect.size.height/2));
                    CGContextDrawImage(bmContext, CGRectMake(0, 0,
                                                             rotatedRect.size.width,
                                                             rotatedRect.size.height),
                                       imgRef);
                
                
                
                    CGImageRef rotatedImage = CGBitmapContextCreateImage(bmContext);
                    CFRelease(bmContext);
                    [(id)rotatedImage autorelease];
                
                    return rotatedImage;
                }
                

                这篇关于在 UIImageView 中旋转图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:创建 UIImageView 时上下文无效 下一篇:iOS CAKeyFrameAnimation 缩放动画结束时闪烁

                相关文章

                1. <i id='b0kQS'><tr id='b0kQS'><dt id='b0kQS'><q id='b0kQS'><span id='b0kQS'><b id='b0kQS'><form id='b0kQS'><ins id='b0kQS'></ins><ul id='b0kQS'></ul><sub id='b0kQS'></sub></form><legend id='b0kQS'></legend><bdo id='b0kQS'><pre id='b0kQS'><center id='b0kQS'></center></pre></bdo></b><th id='b0kQS'></th></span></q></dt></tr></i><div id='b0kQS'><tfoot id='b0kQS'></tfoot><dl id='b0kQS'><fieldset id='b0kQS'></fieldset></dl></div>

                  <small id='b0kQS'></small><noframes id='b0kQS'>

                  <legend id='b0kQS'><style id='b0kQS'><dir id='b0kQS'><q id='b0kQS'></q></dir></style></legend>
                  1. <tfoot id='b0kQS'></tfoot>

                    • <bdo id='b0kQS'></bdo><ul id='b0kQS'></ul>