
myNSImageVIEw.image = UIGraphicsGetimageFromCurrentimageContext();
但是这个函数只存在于cocoa-touch而不存在于cocoa框架中,关于在Cocoa中可以找到类似函数的地方的任何提示?
谢谢.
更新
一些额外的完整性代码.
- (voID)mouseDragged:(NSEvent *)event{ NSInteger wIDth = canvasVIEw.frame.size.wIDth; NSInteger height = canvasVIEw.frame.size.height; NSGraphicsContext * graphicsContext = [NSGraphicsContext currentContext]; CGContextRef contextRef = (CGContextRef) [graphicsContext graphicsPort]; CGContextRef imageContextRef = CGBitmapContextCreate(0,wIDth,height,8,wIDth*4,[NScolorSpace genericRGBcolorSpace].CGcolorSpace,kCGImageAlphaPremultiplIEdFirst); NSPoint currentPoint = [event locationInWindow]; CGContextSetRGBstrokecolor(contextRef,49.0/255.0,147.0/255.0,239.0/255.0,1.0); CGContextSetlinewidth(contextRef,1.0); CGContextBeginPath(contextRef); CGContextMovetoPoint(contextRef,lastPoint.x,lastPoint.y); CGContextAddlinetoPoint(contextRef,currentPoint.x,currentPoint.y); CGContextDrawPath(contextRef,kCGPathstroke); CGImageRef imageRef = CGBitmapContextCreateImage(imageContextRef); NSImage* image = [[NSImage alloc] initWithCGImage:imageRef size:NSMakeSize(wIDth,height)]; canvasVIEw.image = image; CFRelease(imageRef); CFRelease(imageContextRef); lastPoint = currentPoint; }
我现在得到的结果是,这幅画在视图的上半部分工作正常,但其余部分则是僵尸.就像在这个图像上(红色部分应该是canvasVIEw):
解决方法NSInteger wIDth = 1024;NSInteger height = 768;CGContextRef contextRef = CGBitmapContextCreate(0,kCGImageAlphaPremultiplIEdFirst); CGContextSetRGBstrokecolor(contextRef,1.0);CGContextFillRect(contextRef,CGRectMake(0.0f,0.0f,height));CGImageRef imageRef = CGBitmapContextCreateImage(contextRef);NSImage* image = [[NSImage alloc] initWithCGImage:imageRef size:NSMakeSize(wIDth,height)];CFRelease(imageRef);CFRelease(contextRef);总结
以上是内存溢出为你收集整理的objective-c – 桌面Cocoa中的UIGraphicsGetImageFromCurrentImageContext对应物?全部内容,希望文章能够帮你解决objective-c – 桌面Cocoa中的UIGraphicsGetImageFromCurrentImageContext对应物?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)