Ios 带有内存映射原始数据的UIImage(CGImage)

Ios 带有内存映射原始数据的UIImage(CGImage),ios,uiimage,memory-mapped-files,cgimage,Ios,Uiimage,Memory Mapped Files,Cgimage,是否有办法在iOS中存储和加载原始图像数据,以节省解压时间和内存,并减少应用程序的脏内存占用 保罗·哈达德一直都是,我知道这项技术是用于治疗癌症的 我的用例如果是用户提供的全屏壁纸,则始终显示在背景中。目前我将其保存到PNG,并在应用程序启动时加载。这会浪费内存和CPU来解压缩图像。我想保存图像,然后将其加载为内存映射文件。有没有办法在CoreGraphics/UIKit land中实现这一点?我用它来实时保存视频缓冲区的片段 -(void)captureOutput:(AVCaptureOu

是否有办法在iOS中存储和加载原始图像数据,以节省解压时间和内存,并减少应用程序的脏内存占用

保罗·哈达德一直都是,我知道这项技术是用于治疗癌症的


我的用例如果是用户提供的全屏壁纸,则始终显示在背景中。目前我将其保存到PNG,并在应用程序启动时加载。这会浪费内存和CPU来解压缩图像。我想保存图像,然后将其加载为内存映射文件。有没有办法在CoreGraphics/UIKit land中实现这一点?

我用它来实时保存视频缓冲区的片段

 -(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer  fromConnection:(AVCaptureConnection *)connection
{

  CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
  CVPixelBufferLockBaseAddress(imageBuffer,0);
  bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
  void *baseAddress = CVPixelBufferGetBaseAddress(imageBuffer);

  size_t sliceSize = bytesPerRow*sliceWidth*sizeof(char);
  int slicePos= bytesPerRow*sliceStart*sizeof(char);
  NSData *rawFrame = [NSData dataWithBytes:(void*)baseAddress+slicePos length:sliceSize];

  inputPath = [NSString stringWithFormat:@"%@%@%d", NSTemporaryDirectory(), @"slice",step];
  [[NSData dataWithData:rawFrame] writeToFile:inputPath atomically:NO];
}
然后我带着你的名字读了回来

-(void)readSlice
{
  //read slice i
  NSString *filePath = [NSString stringWithFormat:@"%@%@%d", NSTemporaryDirectory(), @"slice",i];            
  char* imgD= (char*)malloc(sliceSize);
  [[NSData dataWithContentsOfFile:filePath] getBytes:imgD];
  CGContextRef context = CGBitmapContextCreate(imgD, sliceHeight,sliceWidth, 8, bytesPerRad, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
  CGImageRef quartzImage = CGBitmapContextCreateImage(context);
  CGContextRelease(context);
  free(imgD);
  //do something with quartzImage
}

我用它来实时保存视频缓冲区的片段

 -(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer  fromConnection:(AVCaptureConnection *)connection
{

  CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
  CVPixelBufferLockBaseAddress(imageBuffer,0);
  bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
  void *baseAddress = CVPixelBufferGetBaseAddress(imageBuffer);

  size_t sliceSize = bytesPerRow*sliceWidth*sizeof(char);
  int slicePos= bytesPerRow*sliceStart*sizeof(char);
  NSData *rawFrame = [NSData dataWithBytes:(void*)baseAddress+slicePos length:sliceSize];

  inputPath = [NSString stringWithFormat:@"%@%@%d", NSTemporaryDirectory(), @"slice",step];
  [[NSData dataWithData:rawFrame] writeToFile:inputPath atomically:NO];
}
然后我带着你的名字读了回来

-(void)readSlice
{
  //read slice i
  NSString *filePath = [NSString stringWithFormat:@"%@%@%d", NSTemporaryDirectory(), @"slice",i];            
  char* imgD= (char*)malloc(sliceSize);
  [[NSData dataWithContentsOfFile:filePath] getBytes:imgD];
  CGContextRef context = CGBitmapContextCreate(imgD, sliceHeight,sliceWidth, 8, bytesPerRad, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
  CGImageRef quartzImage = CGBitmapContextCreateImage(context);
  CGContextRelease(context);
  free(imgD);
  //do something with quartzImage
}

这与我的问题只有一点关系。你能谈谈记忆映射的部分吗?这和我的问题只有一点关系。你能说出内存映射部分的地址吗?