मुझे आईओएस 9 एसडीके के साथ फसल से संबंधित कुछ मुद्दों का सामना करना पड़ रहा है।आईओएस 9 - क्रॉपिंग के साथ मुद्दे CVImageBuffer
मेरे पास एक छवि का आकार बदलने के लिए निम्न कोड है (बीच में फसल करके 4: 3 से 16: 9 में कनवर्ट करना)। यह आईओएस 8 एसडीके तक ठीक काम करता था। आईओएस 9 के साथ, नीचे क्षेत्र खाली है।
(CMSampleBufferRef)resizeImage:(CMSampleBufferRef) sampleBuffer {
{
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(imageBuffer,0);
int target_width = CVPixelBufferGetWidth(imageBuffer);
int target_height = CVPixelBufferGetHeight(imageBuffer);
int height = CVPixelBufferGetHeight(imageBuffer);
int width = CVPixelBufferGetWidth(imageBuffer);
int x=0, y=0;
// Convert 16:9 to 4:3
if (((target_width*3)/target_height) == 4)
{
target_height = ((target_width*9)/16);
target_height = ((target_height + 15)/16) * 16;
y = (height - target_height)/2;
}
else
if ((target_width == 352) && (target_height == 288))
{
target_height = ((target_width*9)/16);
target_height = ((target_height + 15)/16) * 16;
y = (height - target_height)/2;
}
else
if (((target_height*3)/target_width) == 4)
{
target_width = ((target_height*9)/16);
target_width = ((target_width + 15)/16) * 16;
x = ((width - target_width)/2);
}
else
if ((target_width == 288) && (target_height == 352))
{
target_width = ((target_height*9)/16);
target_width = ((target_width + 15)/16) * 16;
x = ((width - target_width)/2);
}
CGRect cropRect;
NSLog(@"resizeImage x %d, y %d, target_width %d, target_height %d", x, y, target_width, target_height);
cropRect = CGRectMake(x, y, target_width, target_height);
CFDictionaryRef empty; // empty value for attr value.
CFMutableDictionaryRef attrs;
empty = CFDictionaryCreate(kCFAllocatorDefault, // our empty IOSurface properties dictionary
NULL,
NULL,
0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
attrs = CFDictionaryCreateMutable(kCFAllocatorDefault,
1,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(attrs,
kCVPixelBufferIOSurfacePropertiesKey,
empty);
OSStatus status;
CIImage *ciImage = [CIImage imageWithCVPixelBuffer:imageBuffer]; //options: [NSDictionary dictionaryWithObjectsAndKeys:[NSNull null], kCIImageColorSpace, nil]];
CVPixelBufferRef pixelBuffer;
status = CVPixelBufferCreate(kCFAllocatorSystemDefault, target_width, target_height, kCVPixelFormatType_420YpCbCr8BiPlanarFullRange, attrs, &pixelBuffer);
if (status != 0)
{
NSLog(@"CVPixelBufferCreate error %d", (int)status);
}
[ciContext render:ciImage toCVPixelBuffer:pixelBuffer bounds:cropRect colorSpace:nil];
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
CVPixelBufferUnlockBaseAddress(imageBuffer,0);
CMSampleTimingInfo sampleTime = {
.duration = CMSampleBufferGetDuration(sampleBuffer),
.presentationTimeStamp = CMSampleBufferGetPresentationTimeStamp(sampleBuffer),
.decodeTimeStamp = CMSampleBufferGetDecodeTimeStamp(sampleBuffer)
};
CMVideoFormatDescriptionRef videoInfo = NULL;
status = CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer, &videoInfo);
if (status != 0)
{
NSLog(@"CMVideoFormatDescriptionCreateForImageBuffer error %d", (int)status);
}
CMSampleBufferRef oBuf;
status = CMSampleBufferCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer, true, NULL, NULL, videoInfo, &sampleTime, &oBuf);
if (status != 0)
{
NSLog(@"CMSampleBufferCreateForImageBuffer error %d", (int)status);
}
CFRelease(pixelBuffer);
ciImage = nil;
pixelBuffer = nil;
return oBuf;
}
}
इस बारे में कोई विचार या सुझाव? मैंने फसल आयताकार बदलने की कोशिश की लेकिन बिना किसी प्रभाव के।
धन्यवाद
यदि मैं x और y को शून्य में रखता हूं i.e. x = 0 y = 0, यह काम करता है लेकिन यह मध्य से फसल नहीं करता है, बल्कि इसके बजाय फ्रेम के शीर्ष को हटा देता है। – manishg