1. <small id='HoNNo'></small><noframes id='HoNNo'>

      <tfoot id='HoNNo'></tfoot>
    2. <legend id='HoNNo'><style id='HoNNo'><dir id='HoNNo'><q id='HoNNo'></q></dir></style></legend>

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

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

        kCAFilterNearest 放大过滤器 (UIImageView)

        kCAFilterNearest maginifcation filter (UIImageView)(kCAFilterNearest 放大过滤器 (UIImageView))

        <tfoot id='7kW0v'></tfoot>
        • <bdo id='7kW0v'></bdo><ul id='7kW0v'></ul>

            <small id='7kW0v'></small><noframes id='7kW0v'>

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

                • <legend id='7kW0v'><style id='7kW0v'><dir id='7kW0v'><q id='7kW0v'></q></dir></style></legend>

                    <tbody id='7kW0v'></tbody>
                  本文介绍了kCAFilterNearest 放大过滤器 (UIImageView)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I am using QREncoder library found here: https://github.com/jverkoey/ObjQREncoder

                  Basically, i looked at the example code by this author, and when he creates the QRCode it comes out perfectly with no pixelation. The image itself that the library provides is 33 x 33 pixels, but he uses kCAFilterNearest to magnify and make it very clear (no pixilation). Here is his code:

                      UIImage* image = [QREncoder encode:@"http://www.google.com/"];
                  
                      UIImageView* imageView = [[UIImageView alloc] initWithImage:image];
                    CGFloat qrSize = self.view.bounds.size.width - kPadding * 2;
                      imageView.frame = CGRectMake(kPadding, (self.view.bounds.size.height - qrSize) / 2,
                      qrSize, qrSize);
                      [imageView layer].magnificationFilter = kCAFilterNearest;
                  
                      [self.view addSubview:imageView];
                  

                  I have a UIImageView in a xib, and I am setting it's image like this:

                  [[template imageVQRCode] setImage:[QREncoder encode:ticketNum]];
                  [[[template imageVQRCode] layer] setMagnificationFilter:kCAFilterNearest];
                  

                  but the qrcode is really blurry. In the example, it comes out crystal clear. What am i doing wrong? Thanks!

                  UPDATE:I found out that the problem isn't with scaling or anything to do with kCAFFilterNearest. It has to do with generating the PNG image from the view. Here's how it looks on the deive vs how it looks like when i save the UIView to the PNG representation (Notice the QRCodes quality):

                  UPDATE 2: This is how I am generating the PNG file from UIView:

                     UIGraphicsBeginImageContextWithOptions([[template view] bounds].size, YES, 0.0);
                      [[[template view] layer] renderInContext:UIGraphicsGetCurrentContext()];
                      UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
                      UIGraphicsEndImageContext();
                      [UIImagePNGRepresentation(viewImage) writeToFile:plistPath atomically:YES];
                  

                  解决方案

                  I have used below function for editing image.

                  - (UIImage *)resizedImage:(CGSize)newSize interpolationQuality:(CGInterpolationQuality)quality
                  {
                      BOOL drawTransposed;
                  
                      switch (self.imageOrientation) {
                          case UIImageOrientationLeft:
                          case UIImageOrientationLeftMirrored:
                          case UIImageOrientationRight:
                          case UIImageOrientationRightMirrored:
                              drawTransposed = YES;
                              break;
                  
                          default:
                              drawTransposed = NO;
                      }
                  
                      return [self resizedImage:newSize
                                      transform:[self transformForOrientation:newSize]
                                 drawTransposed:drawTransposed
                           interpolationQuality:quality];
                  
                  }
                  
                  - (UIImage *)resizedImage:(CGSize)newSize
                                  transform:(CGAffineTransform)transform
                             drawTransposed:(BOOL)transpose
                       interpolationQuality:(CGInterpolationQuality)quality
                  {
                  
                      CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height));
                      CGRect transposedRect = CGRectMake(0, 0, newRect.size.height, newRect.size.width);
                      CGImageRef imageRef = self.CGImage;
                  
                      // Build a context that's the same dimensions as the new size
                      CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
                      if((bitmapInfo == kCGImageAlphaLast) || (bitmapInfo == kCGImageAlphaNone))
                          bitmapInfo = kCGImageAlphaNoneSkipLast;
                  
                      CGContextRef bitmap = CGBitmapContextCreate(NULL,
                                                                  newRect.size.width,
                                                                  newRect.size.height,
                                                                  CGImageGetBitsPerComponent(imageRef),
                                                                  0,
                                                                  CGImageGetColorSpace(imageRef),
                                                                  bitmapInfo);
                  
                      // Rotate and/or flip the image if required by its orientation
                      CGContextConcatCTM(bitmap, transform);
                  
                      // Set the quality level to use when rescaling
                      CGContextSetInterpolationQuality(bitmap, quality);
                  
                      // Draw into the context; this scales the image
                      CGContextDrawImage(bitmap, transpose ? transposedRect : newRect, imageRef);
                  
                      // Get the resized image from the context and a UIImage
                      CGImageRef newImageRef = CGBitmapContextCreateImage(bitmap);
                      UIImage *newImage = [UIImage imageWithCGImage:newImageRef];
                  
                      // Clean up
                      CGContextRelease(bitmap);
                      CGImageRelease(newImageRef);
                  
                      return newImage;
                  
                  }
                  
                  
                  UIImageWriteToSavedPhotosAlbum([image resizedImage:CGSizeMake(300, 300) interpolationQuality:kCGInterpolationNone], nil, nil, nil);
                  

                  Please find below image and let me know if you need any help.

                  这篇关于kCAFilterNearest 放大过滤器 (UIImageView)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  what#39;s property copy means in Cocoa#39;s Framework?(like UITabBar#39;s items property)(Cocoa 框架中的属性副本是什么意思?(如 UITabBar 的 items 属性))
                  Difference between retain and copy?(保留和复制的区别?)
                  Can`t copy file from bundle to documents directory in iOS(无法将文件从捆绑包复制到 iOS 中的文档目录)
                  Automatically copy property values from one object to another of a different type but the same protocol (Objective-C)(自动将属性值从一个对象复制到另一个类型不同但协议相同的对象 (Objective-C))
                  What is the difference between quot;copyquot; and quot;retainquot;?(“复制和“复制有什么区别?和“保留?)
                  Copy text to clipboard with iOS(使用 iOS 将文本复制到剪贴板)
                    <tbody id='tCaar'></tbody>
                  <legend id='tCaar'><style id='tCaar'><dir id='tCaar'><q id='tCaar'></q></dir></style></legend>

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

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