使用新的尺寸創建新圖像,例如高度等於寬度和寬度等於高度

[英]Creating a new image with new dimensions like height equals to width and width equals to height


i m getting problem with the rotation of image.I want to create a new image with height equals to width because rotating by 90 degrees.but new image created change dimentions but do not place data in image accurately.

我遇到了圖像旋轉的問題。我想創建一個高度等於寬度的新圖像,因為旋轉了90度。但是創建的新圖像會改變尺寸,但不能准確地將數據放在圖像中。

CGImageRef imageRef = OriginalImage.CGImage; /////////////new height equals to width of origunal image size_t newHeight = CGImageGetWidth(imageRef); size_t newWidth = CGImageGetHeight(imageRef); size_t bitsPerComponent = CGImageGetBitsPerComponent(imageRef); size_t bitsPerPixel = CGImageGetBitsPerPixel(imageRef);

CGImageRef imageRef = OriginalImage.CGImage; /////////////新高度等於原始圖像的寬度size_t newHeight = CGImageGetWidth(imageRef); size_t newWidth = CGImageGetHeight(imageRef); size_t bitsPerComponent = CGImageGetBitsPerComponent(imageRef); size_t bitsPerPixel = CGImageGetBitsPerPixel(imageRef);

CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
CFDataRef argbData = CFDataCreate(NULL,rotatedPixelData,originalImageDataLength);
CGDataProviderRef provider = CGDataProviderCreateWithCFData(argbData);

CGImageRef nimage = CGImageCreate(NewWidth,NewHeight,bitsPerComponent, bitsPerPixel,bytesPerRow,colorspace,bitmapInfo,provider, NULL, true, kCGRenderingIntentDefault);

What should i change in parameters of CGImageCreate?

我應該在CGImageCreate的參數中改變什么?

1 个解决方案

#1


You probably need to calculate a newBytesPerRow.

您可能需要計算newBytesPerRow。

This means that the size of the new image may not be the same
as the original, so recalculate originalImageDataLength too.

這意味着新圖像的大小可能與原始圖像的大小不同,因此也要重新計算originalImageDataLength。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2009/07/08/72f8bab580bf114a0c5a19f821c6085d.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com