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)

        时间:2024-04-14

        <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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用 Zbar 裁剪扫描的条码? 下一篇:更改 UIImageView 模式 iPhone/iPad

                  相关文章

                  <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>