当我通过调用此例程创建CIImage时,我在标题中得到malloc错误。当我直接调用initWithBitmapData(不在createCIUimageFromData例程中)时,它工作正常。
我已经看到了iOS中可能存在的可能相关错误的引用,但我无法确定,我当然怀疑我的代码比Apple更多!
我的猜测在某种程度上是我的额外重定向搞砸了,但是拥有单独的例程比在任何我需要的地方嵌入代码更清晰。
谢谢。
失败:
- (CIImage *) createCIimageFromData : (unsigned char *)pData width : (int32_t)width height : (int32_t)height
{
/*
Once we have the raw data, we convert it into a CIImage.
The following code does the required work.
*/
NSLog(@"entering createciimage\n");
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceGray();
NSData *_pixelsData = [NSData dataWithBytesNoCopy:pData length:(sizeof(unsigned char)*width*height) freeWhenDone:YES ];
CIImage *_dataCIImage = [[CIImage alloc] initWithBitmapData:_pixelsData bytesPerRow:(width*sizeof(unsigned char)) size:CGSizeMake(width,height) format:kCIFormatR8 colorSpace:colorSpaceRef];
CGColorSpaceRelease(colorSpaceRef);
/*
newImage is the final image
Do remember to release the allocated parts.
*/
NSLog(@"done ciimage\n");
return _dataCIImage;
}
使用:
void prepData(unsigned char *pData, // source-destination
int strideSrc, // stride
int width,
int height,
double amount,
int deltaLimit,
id owner)
{
//[owner createCIimageFromData:pData width:width height:height]; // <-- commented out
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceGray();
NSData *_pixelsData = [NSData dataWithBytesNoCopy:pData length:(sizeof(unsigned char)*width*height) freeWhenDone:YES ];
CIImage *_dataCIImage = [[CIImage alloc] initWithBitmapData:_pixelsData bytesPerRow:(width*sizeof(unsigned char)) size:CGSizeMake(width,height) format:kCIFormatR8 colorSpace:colorSpaceRef];
CGColorSpaceRelease(colorSpaceRef);
// . . .
}
答案 0 :(得分:1)
显然,var data = [ {
x: [0, 1, 1, 0],
y: [0, 0, 1, 1],
z: [0, 0, 1, 1],
type: 'contour',
colorscale: 'Jet',
showscale: false,
autocontour: true
}];
var layout = {
margin: {
b: 0,
l: 0,
r: 0,
t: 0
},
height: 600,
width: 600,
title: '',
xaxis: {
ticks: '',
showticklabels: false
},
yaxis: {
ticks: '',
showticklabels: false
}
};
Plotly.newPlot('graph', data, layout, {displayModeBar: false});
对象尝试释放数据时会导致问题。要避免此问题,请使用NSData
,然后在完成freeWhenDone:NO
后释放数据。