相关疑难解决方法(0)

Objective-c - 在图像中获得最少使用和最常用的颜色

我试图获得最少使用的颜色,以及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)

itunes objective-c uicolor ios

25
推荐指数
2
解决办法
1万
查看次数

获取Swift中UIImage的平均颜色

我最近试图将代码从这里转换为Swift.但是,无论图像如何,我都会保持白色.这是我的代码:

// Playground - noun: a place where people can play

import UIKit

extension UIImage {
    func averageColor() -> UIColor {
        var colorSpace = CGColorSpaceCreateDeviceRGB()
        var rgba: [CGFloat] = [0,0,0,0]
        var context = CGBitmapContextCreate(&rgba, 1, 1, 8, 4, colorSpace, CGBitmapInfo.fromRaw(CGImageAlphaInfo.PremultipliedLast.toRaw())!)
        rgba

        CGContextDrawImage(context, CGRectMake(0, 0, 1, 1), self.CGImage)

        if rgba[3] > 0 {
            var alpha = rgba[3] / 255
            var multiplier = alpha / 255
            return UIColor(red: rgba[0] * multiplier, green: rgba[1] * multiplier, blue: rgba[2] * multiplier, alpha: …
Run Code Online (Sandbox Code Playgroud)

uiimage ios swift

11
推荐指数
4
解决办法
1万
查看次数

标签 统计

ios ×2

itunes ×1

objective-c ×1

swift ×1

uicolor ×1

uiimage ×1