Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 图像大小调整错误:CGBitmapContextCreate:不支持的参数_Iphone_Objective C - Fatal编程技术网

Iphone 图像大小调整错误:CGBitmapContextCreate:不支持的参数

Iphone 图像大小调整错误:CGBitmapContextCreate:不支持的参数,iphone,objective-c,Iphone,Objective C,我正在使用以下代码(来自一篇博客文章)来调整图像的大小 if (inImage.size.width <= inImage.size.height) { // Portrait ratio = inImage.size.height / inImage.size.width; resizedRect = CGRectMake(0, 0, width, width * ratio); } else { // Landscape ratio = inIm

我正在使用以下代码(来自一篇博客文章)来调整图像的大小

if (inImage.size.width <= inImage.size.height) {
    // Portrait
    ratio = inImage.size.height / inImage.size.width;
    resizedRect = CGRectMake(0, 0, width, width * ratio);
}
else {
    // Landscape
    ratio = inImage.size.width / inImage.size.height;
    resizedRect = CGRectMake(0, 0, height * ratio, height);
}

CGImageRef          imageRef = [inImage CGImage];
CGImageAlphaInfo    alphaInfo = CGImageGetAlphaInfo(imageRef);

if (alphaInfo == kCGImageAlphaNone)
    alphaInfo = kCGImageAlphaNoneSkipLast;

CGContextRef bitmap = CGBitmapContextCreate(
                                            NULL,
                                            resizedRect.size.width,     // width
                                            resizedRect.size.height,        // height
                                            CGImageGetBitsPerComponent(imageRef),   // really needs to always be 8
                                            4 * resizedRect.size.width, // rowbytes
                                            CGImageGetColorSpace(imageRef),
                                            alphaInfo
                                            );

您在哪里编写的
thumbRect
,是指
resizedRect
<代码>thumbRect不会以其他方式出现

我怀疑问题在于
resizedRect.size.width
是非整数的。注意,它是浮点型的

CGBitmapContextCreate
的width和bytesPerRow参数声明为整数。当您传递一个浮点值时,比如这里,它会被截断

假设您的resizedRect.size.width为1.25。然后,将通过1表示宽度,通过floor(1.25*4)==5表示每行字节数。这是不一致的。对于每行字节的宽度,您总是希望传递四次


顺便说一下,您也可以将bytesPerRow保留为0。然后,系统选择最好的bytesPerRow(通常大于宽度的4倍-它会垫出以对齐)

是(复制粘贴错误格式化为问题)是,我同意resizedRect.size.width可能是浮点。你能再解释一点吗,我只需要四舍五入到整数吗?请更新你的回答,我只是将值的3个用法转换为int,它对问题进行了排序。(int)resizedRect.size.width etcI已将bytesPerRow设置为0,但当大小为浮点值时仍会出现错误。CGContextConcatCTM:无效上下文0x0 CGContextSetInterpolationQuality:无效上下文0x0 CGContextDrawImage:无效上下文0x0 CGBitmapContextCreateImage:无效上下文0x0
Source   50x50   69x69
430x320  /      X
240x320  /      /
272x320  /      /
480x419  /      X
426x320  X      X
480x256  X      X