我收到'kCGImageAlphaPremultipliedLast'的未解决的标识符错误.斯威夫特找不到它.这可以在Swift中使用吗?
var gc = CGBitmapContextCreate(&pixelData, width: width, height: height, bitsPerComponent: 8, bytesPerRow: width*4, imageCS, bitmapInfo: kCGImageAlphaPremultipliedLast);
Run Code Online (Sandbox Code Playgroud) 我正在开发一个将彩色图像更改为灰色图像的应用程序.但是,有些图片如何出错.我不知道代码有什么问题.也许我输入的参数是错误请帮忙.
UIImage *c = [UIImage imageNamed:@"downRed.png"];
CGImageRef cRef = CGImageRetain(c.CGImage);
NSData* pixelData = (NSData*) CGDataProviderCopyData(CGImageGetDataProvider(cRef));
size_t w = CGImageGetWidth(cRef);
size_t h = CGImageGetHeight(cRef);
unsigned char* pixelBytes = (unsigned char *)[pixelData bytes];
unsigned char* greyPixelData = (unsigned char*) malloc(w*h);
for (int y = 0; y < h; y++) {
for(int x = 0; x < w; x++){
int iter = 4*(w*y+x);
int red = pixe lBytes[iter];
int green = pixelBytes[iter+1];
int blue = pixelBytes[iter+2];
greyPixelData[w*y+x] = (unsigned char)(red*0.3 + green*0.59+ blue*0.11); …Run Code Online (Sandbox Code Playgroud) 我最初在Obj-C中编写了这个App(GitHub),但是需要将它转换为Swift.在转换时,我一直无法获得创建位图的上下文.
错误信息:
Whiteboard[2833] <Error>: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 24 bits/pixel; 3-component color space; kCGImageAlphaNone; 1500 bytes/row.
Run Code Online (Sandbox Code Playgroud)
本来我有这个:
self.cacheContext = CGBitmapContextCreate (self.cacheBitmap, size.width, size.height, 8, bitmapBytesPerRow, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipFirst);
Run Code Online (Sandbox Code Playgroud)
现在我有:
self.cacheContext = CGBitmapContextCreate(self.cacheBitmap!, UInt(size.width), UInt(size.height), 8, bitmapBytesPerRow, CGColorSpaceCreateDeviceRGB(), CGBitmapInfo.ByteOrder32Little);
Run Code Online (Sandbox Code Playgroud)
我相信这个问题与CGBitmapInfo.ByteOrder32Little我有关,但我不知道该通过什么.有没有办法通过kCGImageAlphaNoneSkipFirst的CGBitmapInfo?
完整来源:
//
// WhiteBoard.swift
// Whiteboard
//
import Foundation
import UIKit
class WhiteBoard: UIView {
var hue: CGFloat
var cacheBitmap: UnsafeMutablePointer<Void>?
var cacheContext: CGContextRef?
override init(frame: CGRect) {
self.hue = 0.0; …Run Code Online (Sandbox Code Playgroud)