gpt4 book ai didi

iphone - UIImageWriteToSavedPhotosAlbum 导致 EXC_BAD_ACCESS

转载 作者:行者123 更新时间:2023-12-03 18:45:25 32 4
gpt4 key购买 nike

我开发了一个 CGImage,当程序使用以下命令将其显示在屏幕上时它工作正常:

[output_view.layer performSelectorOnMainThread:@selector(setContents:) withObject: (id) image waitUntilDone:YES];

现在,这样做会使应用程序崩溃:

UIImageWriteToSavedPhotosAlbum([UIImage imageWithCGImage: image)],nil,nil,nil);

我根本不明白。这是崩溃期间的堆栈:

#0  0x33b5db6e in memmove (Line 65)
#1 0x341ddee2 in CGAccessSessionGetBytes
#2 0x31ab4488 in alphaProviderGetBytes
#3 0x341ddf52 in CGAccessSessionGetBytes
#4 0x31abbc80 in writeOne
#5 0x31abbdae in _CGImagePluginWriteJPEG
#6 0x31ab2ddc in CGImageDestinationFinalize
#7 0x3037eda2 in imageDataFromImageWithFormatAndProperties
#8 0x3037effc in imageDataFromImageRef
#9 0x3038ea3c in __-[PLAssetsSaver _saveImage:imageData:properties:completionBlock:]_block_invoke_1
#10 0x33c32680 in _dispatch_call_block_and_release
#11 0x33c32ba0 in _dispatch_worker_thread2
#12 0x33bd7250 in _pthread_wqthread

这是有问题的方法:

-(void)captureOutput: (AVCaptureOutput *) captureOutput didOutputSampleBuffer: (CMSampleBufferRef) sampleBuffer fromConnection: (AVCaptureConnection *) conenction{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// Get a CMSampleBuffer's Core Video image buffer for the media data
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
// Lock the base address of the pixel buffer
CVPixelBufferLockBaseAddress(imageBuffer, 0);
// Get the number of bytes per row for the pixel buffer
UInt8 * image_data = CVPixelBufferGetBaseAddress(imageBuffer);
// Get the number of bytes per row for the pixel buffer
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
// Get the pixel buffer width and height
size_t width = CVPixelBufferGetWidth(imageBuffer);
size_t height = CVPixelBufferGetHeight(imageBuffer);
//Removed part here which modifies the CVPixelBuffer pixels with a particular algorithm.
[bottom_view setNeedsDisplay];
[bottom_view performSelectorOnMainThread:@selector(setBackgroundColor:) withObject: [UIColor colorWithRed:0 green:av/255.0 blue:0 alpha:1] waitUntilDone: YES];
// Create a device-dependent RGB color space
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
// Create a Quartz image from the pixel data
CGDataProviderDirectCallbacks providerCallbacks = { 0, GetBytePointer, ReleaseBytePointer, GetBytesAtPosition, 0 };
CGDataProviderRef d_provider = CGDataProviderCreateDirect(image_data,pixels*4,&providerCallbacks);
CGImageRef image = CGImageCreate (width,height,8,32,bytesPerRow,colorSpace,kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst,d_provider,NULL,true,kCGRenderingIntentDefault);
//Draw image
if (needs_photo) {
UIImageWriteToSavedPhotosAlbum([UIImage imageWithCGImage: image],nil,nil,nil);
needs_photo = NO;
}
if (recording) {
[writer_input appendSampleBuffer:sampleBuffer];
}
[output_view.layer performSelectorOnMainThread:@selector(setContents:) withObject: (id) image waitUntilDone:YES];
// Unlock the pixel buffer
CVPixelBufferUnlockBaseAddress(imageBuffer,0);
// Free up the context and color space
CGColorSpaceRelease(colorSpace);
CGImageRelease(image);
CGDataProviderRelease(d_provider);
[pool drain];
}

感谢您对解决此问题的任何帮助。

最佳答案

请尝试这个:

UIImageWriteToSavedPhotosAlbum(image, self, @selector(imageSavedToPhotosAlbum: didFinishSavingWithError: contextInfo:), context);

它会解决你的问题。如果您仍然遇到同样的问题,请告诉我。我想解决您的问题。

关于iphone - UIImageWriteToSavedPhotosAlbum 导致 EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4419510/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com