开发者

resize image with aspect ratio

开发者 https://www.devze.com 2023-03-16 05:10 出处:网络
I try to resize image with aspect ratio, like done in the following links Resizing UIimages pulled from the Camera also ROTATES the UIimage?

I try to resize image with aspect ratio, like done in the following links

Resizing UIimages pulled from the Camera also ROTATES the UIimage?

https://stackoverflow.com/questions/1282830/uiimagepickercontroller-uiimage-memory-and-more

This works fine on the simulator. But on my iPhone-4 I get a black block on the开发者_开发百科 right side of the picture. (a 4th of the picture is black). It only happens for pictures which have imageOrientation right...so far. ImageOrientation up doesn't give any problems.

Somehow I have the feeling that CGBitmapContextCreate is giving the problem. I already removed CGImageGetBytesPerRow, because this doesn't work as I have read. At the moment I have the following code:

if (sourceImage.imageOrientation == UIImageOrientationUp || sourceImage.imageOrientation == UIImageOrientationDown) {
bitmap = CGBitmapContextCreate(NULL, targetWidth, targetHeight, 8, 4*targetWidth, colorSpaceInfo, bitmapInfo);
} else {
bitmap = CGBitmapContextCreate(NULL, targetHeight, targetWidth, 8, 4*targetHeight, colorSpaceInfo, bitmapInfo);
}

What could case these problems?


I would use the category files on this site to resize UIImages:

http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/

0

精彩评论

暂无评论...
验证码 换一张
取 消