我正在编写这种方法来计算图像的平均R,G,B值.以下方法将UIImage作为输入,并返回包含输入图像的R,G,B值的数组.我有一个问题:如何/我在哪里正确发布CGImageRef?
-(NSArray *)getAverageRGBValuesFromImage:(UIImage *)image
{
CGImageRef rawImageRef = [image CGImage];
//This function returns the raw pixel values
const UInt8 *rawPixelData = CFDataGetBytePtr(CGDataProviderCopyData(CGImageGetDataProvider(rawImageRef)));
NSUInteger imageHeight = CGImageGetHeight(rawImageRef);
NSUInteger imageWidth = CGImageGetWidth(rawImageRef);
//Here I sort the R,G,B, values and get the average over the whole image
int i = 0;
unsigned int red = 0;
unsigned int green = 0;
unsigned int blue = 0;
for (int column = 0; column< imageWidth; column++)
{
int r_temp = 0;
int g_temp = 0; …
Run Code Online (Sandbox Code Playgroud) 我已经使用以下方法实现了绘画/绘画:
- (void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event
-(void) touchesMoved: (NSSet *) touches withEvent: (UIEvent *) event
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event
Run Code Online (Sandbox Code Playgroud)
现在的问题是,对于任何绘制的线,我想得到那个特定的线/油漆图像.我不想要整个屏幕的图像,只需要绘制线条/绘图的区域/边界.
原因是我想在该行/绘制的绘图上执行平移手势/删除功能.
用户可以绘制多条线,因此需要分别UIImage
使用所有这些线.
任何逻辑或代码片段都会非常有用
提前致谢
我将一个透明的.png加载到UIImage中.
如何计算真正的边界框.例如,如果真实图像小于.png维度.
谢谢你的帮助