我正在开发简单的图像处理应用,这是我更改class ExampleClass(){
fun example(){
println("I am in the class.")
}
}
object ExampleObject{
fun example(){
println("I am in the object.")
}
}
fun main(args: Array<String>){
val exampleClass = ExampleClass() // A class needs to be instantiated.
exampleClass.example() // Running the instance of the object.
ExampleObject.example() // An object can be thought of as a Singleton and doesn't need any instantiation.
}
亮度的失败尝试:
NSImage
这是- (IBAction)brightnessSlider:(NSSlider*)sender {
ViewController *controller = (ViewController*)[NSApplication sharedApplication].keyWindow.contentViewController;
controller.imageView.image = originalImage;
CIImage* const beginImage = [self fromNSImageToCIImage:originalImage];
filter = [CIFilter filterWithName:@"CIColorControls" keysAndValues: kCIInputImageKey, beginImage, kCIInputBrightnessKey, [sender doubleValue], nil];
self->filteredImage = self->filter.outputImage;
controller.imageView.image = [self fromCIImageToNSImage:filteredImage];
}
和fromNSImageToCIImage
的实现:
fromCIImageToNSImage
这是正确的方法吗?我什至不知道什么是行不通的。谢谢。
已编辑(我重写了代码,发件人的值有问题):
- (NSImage *)fromCIImageToNSImage:(CIImage *)inputImage {
struct CGImage *cg = [context createCGImage:inputImage fromRect:[inputImage extent]];
NSImage *finalImage = [[NSImage alloc] initWithCGImage:cg size:NSZeroSize];
return finalImage;
}
- (CIImage *)fromNSImageToCIImage:(NSImage *)inputImage {
struct CGImage *cg = [inputImage CGImageForProposedRect: nil context: nil hints: nil];
CIImage *temp = [[CIImage alloc] initWithCGImage: cg options: nil];
return temp;
}
使用NSSlider时崩溃-在此行:- (IBAction)brightnessSlider:(NSSlider*)sender {
ViewController *controller = (ViewController*)[NSApplication sharedApplication].keyWindow.contentViewController;
CIImage* const beginImage = [self fromNSImageToCIImage:controller.imageView.image];
CIFilter *brightness = [CIFilter filterWithName:@"CIColorControls" keysAndValues: kCIInputImageKey, beginImage, @"inputBrightness", [sender doubleValue], nil];
CIImage *outputImage = brightness.outputImage;
struct CGImage* cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]];
NSImage *newImage = [[NSImage alloc] initWithCGImage:cgimg size:NSZeroSize];
controller.imageView.image = newImage;
}
并且调试器显示:线程1:EXC_BAD_ACCESS(代码= 1,地址= 0x6fbbba08)
答案 0 :(得分:0)
更改错误行:CIFilter *brightness = [CIFilter filterWithName:@"CIColorControls" keysAndValues: kCIInputImageKey, beginImage, @"inputBrightness", [NSNumber numberWithFloat:[sender floatValue]], nil];
完成了工作。