<tfoot id='BIxrY'></tfoot>

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

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

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

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

        将 zlib 压缩的 base 64 字符串覆盖到 Uiimage 中的问题

        Issue in Coverting zlib compressed base 64 string to Uiimage(将 zlib 压缩的 base 64 字符串覆盖到 Uiimage 中的问题)
        • <legend id='VfAlX'><style id='VfAlX'><dir id='VfAlX'><q id='VfAlX'></q></dir></style></legend>
            • <bdo id='VfAlX'></bdo><ul id='VfAlX'></ul>
              <i id='VfAlX'><tr id='VfAlX'><dt id='VfAlX'><q id='VfAlX'><span id='VfAlX'><b id='VfAlX'><form id='VfAlX'><ins id='VfAlX'></ins><ul id='VfAlX'></ul><sub id='VfAlX'></sub></form><legend id='VfAlX'></legend><bdo id='VfAlX'><pre id='VfAlX'><center id='VfAlX'></center></pre></bdo></b><th id='VfAlX'></th></span></q></dt></tr></i><div id='VfAlX'><tfoot id='VfAlX'></tfoot><dl id='VfAlX'><fieldset id='VfAlX'></fieldset></dl></div>

                <tbody id='VfAlX'></tbody>

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

                <tfoot id='VfAlX'></tfoot>
                  本文介绍了将 zlib 压缩的 base 64 字符串覆盖到 Uiimage 中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我当前的一个项目中,我必须解析 base 64 字符串,该字符串由 flex(Adobe Flash) 应用程序编码和存储.通过与 flex 开发团队讨论,我发现他们以位图格式存储图像字符串,所以我认为它是像素表示.

                  In one my current project, I have to parse base 64 string, which is encoded and stored by flex(Adobe Flash) application. By discussing with flex dev team I found that they storing image string in bitmap format so I assumed it is a pixel representation.

                  所以,我的第一个问题是,在上述情况下,我可以使用 base64 解码类直接将原始数据转换为 UIimage 还是必须使用 CGBitmapContext ?

                  但是,目前我已经实现了下面提到的转换代码.

                  However, currently I have implemented below mentioned code for conversion.

                  `//转换为Base64数据

                  ` //Convert to Base64 data

                  NSData *decodedData = [QSStrings decodeBase64WithString:_settingSerializedImage.currentValue];
                  
                  
                  NSError *error = nil;
                  NSData *unCompressedData = [decodedData bbs_dataByInflatingWithError:&error];
                  
                  
                  
                  NSData *dataImage = [NSMutableData new];
                  NSUInteger bytePosition = 0;
                  uint8_t * bytes =  malloc(5);
                  [unCompressedData getBytes:&bytes range:NSMakeRange(unCompressedData.length-3, 3)];
                  
                  bytes = OSSwapBigToHostInt16(bytes);
                  int width = (int)bytes;
                  
                  [unCompressedData getBytes:&bytes range:NSMakeRange(unCompressedData.length-5, 5)];
                  
                  bytes = OSSwapBigToHostInt16(bytes);dataImage = [unCompressedData subdataWithRange:NSMakeRange(0, (unCompressedData.length -5))];
                  
                  NSUInteger length = [dataImage length];
                  unsigned char *bytesData = malloc( length * sizeof(unsigned char) ); [dataImage getBytes:bytesData length:length];UIImage *imgScreenShot = [ScreenshotPortlet convertBitmapRGBA8ToUIImage:bytesData withWidth:width withHeight:height];`
                  

                  以下是使用核心图形转换图像中原始数据的方法

                  below is the method for converting raw data in image using core graphics

                  + (UIImage *) convertBitmapRGBA8ToUIImage:(unsigned char *) buffer
                                              withWidth:(int) width
                                             withHeight:(int) height {
                  
                   char* rgba = (char*)malloc(width*height*4);
                  for(int i=0; i < width*height; ++i) {
                      rgba[4*i] = buffer[4*i];
                      rgba[4*i+1] = buffer[4*i+1];
                      rgba[4*i+2] = buffer[4*i+2];
                      rgba[4*i+3] = buffer[4*i+3];
                  }
                  //
                  
                  
                  size_t bufferLength = width * height * 4;
                  CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, rgba, bufferLength, NULL);
                  size_t bitsPerComponent = 8;
                  size_t bitsPerPixel = 32;
                  size_t bytesPerRow = 4 * width;
                  
                  CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
                    if(colorSpaceRef == NULL) {
                      NSLog(@"Error allocating color space");
                      CGDataProviderRelease(provider);
                      return nil;
                  }
                  
                  CGBitmapInfo bitmapInfo = kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedFirst;
                  
                  CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
                  CGImageRef iref = CGImageCreate(width,
                                                  height,
                                                  bitsPerComponent,
                                                  bitsPerPixel,
                                                  bytesPerRow,
                                                  colorSpaceRef,
                                                  bitmapInfo,
                                                  provider,
                                                  NULL,
                                                  YES,
                                                  renderingIntent);
                  
                  uint32_t* pixels = (uint32_t*)malloc(bufferLength);
                  
                  if(pixels == NULL) {
                      NSLog(@"Error: Memory not allocated for bitmap");
                      CGDataProviderRelease(provider);
                      CGColorSpaceRelease(colorSpaceRef);
                      CGImageRelease(iref);
                      return nil;
                  }
                  
                  CGContextRef context = CGBitmapContextCreate(pixels,
                                                               width,
                                                               height,
                                                               bitsPerComponent,
                                                               bytesPerRow,
                                                               colorSpaceRef,
                                                               bitmapInfo);
                  
                  if(context == NULL) {
                      NSLog(@"Error context not created");
                      free(pixels);
                  }
                  
                  UIImage *image = nil;
                  if(context) {
                  
                      CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, width, height), iref);
                  
                      CGImageRef imageRef = CGBitmapContextCreateImage(context);
                  
                      image = [UIImage imageWithCGImage:imageRef];
                  
                      CGImageRelease(imageRef);
                      CGContextRelease(context);
                  }
                  
                  CGColorSpaceRelease(colorSpaceRef);
                  CGImageRelease(iref);
                  CGDataProviderRelease(provider);
                  
                  
                  if(pixels) {
                      free(pixels);
                  }   
                  return image;
                  

                  }

                  这是我得到的输出,一个扭曲的图像:

                  那么任何人都可以建议我更好的解决方案或告诉我是否在正确的方向上?谢谢,提前:)

                  So can anyone suggest me better solution or tell if I'm on right direction in it or not? Thanks, in advance :)

                  参考这里你可以找到原始的base 64字符串

                  For reference here you can find original base 64 string

                  推荐答案

                  图片转base64string:

                  - (NSString *)imageToNSString:(UIImage *)image
                  {
                      NSData *data = UIImagePNGRepresentation(image);
                  
                      return [data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
                  }
                  

                  将base64string转换为图像:

                  - (UIImage *)stringToUIImage:(NSString *)string
                  {
                      NSData *data = [[NSData alloc]initWithBase64EncodedString:string options:NSDataBase64DecodingIgnoreUnknownCharacters];
                  
                      return [UIImage imageWithData:data];
                  }
                  

                  这篇关于将 zlib 压缩的 base 64 字符串覆盖到 Uiimage 中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 将文本复制到剪贴板)

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

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

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