我有一个UIImage(Cocoa Touch).从那以后,我很高兴得到一个CGImage或其他你想要的东西.我想写这个函数:
- (int)getRGBAFromImage:(UIImage *)image atX:(int)xx andY:(int)yy {
// [...]
// What do I want to read about to help
// me fill in this bit, here?
// [...]
int result = (red << 24) | (green << 16) | (blue << 8) | alpha;
return result;
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
我试图获得最少使用的颜色,以及MP3文件的专辑插图中用于音乐播放应用程序的最常用颜色.我需要颜色来做一个像新的itunes 11的效果.菜单的背景颜色是最常用的颜色,最少使用的颜色是歌曲标签和艺术家名称的颜色.我在用
`- (UIColor*) getPixelColorAtLocation:(CGPoint)point {
UIColor* color = nil;
CGImageRef inImage = self.image.CGImage;
// Create off screen bitmap context to draw the image into. Format ARGB is 4 bytes for each pixel: Alpa, Red, Green, Blue
CGContextRef cgctx = [self createARGBBitmapContextFromImage:inImage];
if (cgctx == NULL) { return nil; /* error */ }
size_t w = CGImageGetWidth(inImage);
size_t h = CGImageGetHeight(inImage);
CGRect rect = {{0,0},{w,h}};
// Draw the image to the bitmap context. Once we draw, the memory
// allocated …Run Code Online (Sandbox Code Playgroud) 这是我想修剪的图像的一个例子.我想摆脱图像周围的边框(在这种情况下是顶部和底部黑条).

我在Github上找到了一个库:CKImageAdditions,但它似乎不起作用.当我传入UIColor(RGB颜色)时,它只返回相同的图像.
我可以找到许多示例和类别类来修剪UIImage,任何透明像素作为边框,但在这种情况下我需要修剪黑色.我已经对我的图像中的颜色进行了采样,它们的颜色值确实是255,但它似乎与上面的库所寻找的不匹配.
有没有人有他们使用的图书馆或任何见解?我搜索和搜索了CKImageAdditions,这是我唯一可以找到广告用颜色修剪的东西(虽然不幸的是在我的情况下不起作用).