- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
到目前为止我已经有一幅画了。我有不同颜色的按钮,但我不知道如何更改它们的颜色。我有所有的 RGB 颜色代码,但是如何使用 IBAction 实现它,它会更改 CGContextSetRGBStrokeColor
UIGraphicsGetCurrentContext()
.h:
@interface GameScreen : UIViewController {
BOOL mouseSwiped;
float lineWidth;
CGPoint lastPoint;
IBOutlet UIImageView *drawImage;
}
@end
.m:
#import "GameScreen.h"
#import "DoodlePicViewController.h"
#import "Settings.h"
@implementation GameScreen
@synthesize theimageView,choosePhoto, takePhoto;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
mouseSwiped = NO;
UITouch *touch = [touches anyObject];
lineWidth = thickness.value;
lastPoint = [touch locationInView:self.view];
lastPoint.y -= 20;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
mouseSwiped = YES;
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.view];
currentPoint.y -= 20;
UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), lineWidth);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),1.0, 1.0, 1.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if(!mouseSwiped) {
UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), lineWidth);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
CGContextFlush(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
}
@end
我真的很想弄清楚,但我被困住了☹
最佳答案
我认为你可以使用 slider ,因为它的值是从0到1。你可以获取3个 slider 的值,然后将它们传递给CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),1.0, 1.0, 1.0, 1.0) ,没有IB你也可以做到。我不认为IB是一件好事。
关于iphone - CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6426766/
到目前为止我已经有一幅画了。我有不同颜色的按钮,但我不知道如何更改它们的颜色。我有所有的 RGB 颜色代码,但是如何使用 IBAction 实现它,它会更改 CGContextSetRGBStroke
我正在 UIView 继承类的 -drawRect: 中调用 UIGraphicsGetCurrentContext() 。然后将 View 添加到 ScrollView 上。在 -scrollVie
我正在研究 UIView 的子类。在这个 View 中,我需要 UIGraphicsGetCurrentContext。我画了一个水平条,它工作得很好。现在在同一个 View 中,如果用户触摸任何地方
项目使用ASDK(Texture)。有一个主节点,它有一个子节点,在某些情况下需要显示子节点的外边界,在这个项目中是通过添加一个边界节点和UIGraphicsGetCurrentContext来完成的
我有一个实现徒手画的 View ,但我有一个小问题。我注意到在 iPad 3 上一切都变得糟糕,所以我尝试更新我的绘图代码(可能就像我一开始就应该做的那样)以仅更新被描边的部分。但是,打开后的第一笔,
我正在尝试绘制带有图像的 imageView。 let context = UIGraphicsGetCurrentContext() context?.translateBy(x: imageVie
我正在尝试理解 Quartz 并获取您必须借鉴的上下文。如果我有一个创建上下文的函数,但随后我将另一个函数调用到同一上下文中的其他绘图,我是否需要将上下文从第一个方法传递到下一个方法?或者我是否可以只
我正在使用CGContextRef。 UIGraphicsBeginImageContext(self.drawImage.frame.size); CGContextRef context=UIGr
我正在尝试将 UIScrollView 的所有内容保存为 .pdf。我找到了一些保存当前 View 的教程,它们都依赖于使用 UIGraphicsGetCurrentContext() 创建 CGCo
我有一个输出饼图的 swift 类,我想从 drawRect 方法中取出绘图逻辑,因为 UIGraphicsGetCurrentContext 在 draw 方法之外返回 nil 我需要改变绘制饼图
来自 Apple iOS Documentation #UIGraphicsGetCurrentContext : "在 iOS 4 及更高版本中,您可以从应用程序的任何线程调用此函数。" 还有,为什
我正在构建一个带有自定义 drawRect 函数的 UIView。这是一个相当复杂的 View ,需要绘制许多不同的项目。我基本上将其分解为每个需要绘制的项目一个函数。 我想知道的是,我应该将从 UI
我在这里尝试将单个 PDF 页面转换为 PNG,在 UIGraphicsGetCurrentContext 突然开始返回 nil 之前,它工作得很好。 我正试图在这里追溯我的步骤,但我不太确定我知道这
CGContextRef currentContext = UIGraphicsGetCurrentContext(); UIGraphicsBeginImageContext(drawImage.f
我编写了这个自定义 UIView 类来绘制自定义形状 class ShapeView: UIView { var color: UIColor? init(frame: CGRect, color:
我正在编写一个 iOS 应用程序并集成 FDWaveformView 2.0.0 通过 CocoaPods。有时 UIGraphicsGetCurrentContext() 返回 nil,并且我收到“
在 iOS 8 之前,我对此没有问题,现在,是的。 日志: Assertion failed: (CGFloatIsValid(x) && CGFloatIsValid(y)), function v
我必须绘制一个形状并检测用户触摸是否在形状内部,所以我定义了一个继承自 UIView 的自定义类,如下所示: class ShapeView: UIView { override init(fra
我是 iOS API 这些部分的新手,这里有一些问题在我脑海中造成无限循环 为什么 ..BeginImageContext 有大小而 ..GetCurrentContext 没有大小?如果 ..Get
我创建了一个类,它绘制一个单条形图,在设置时指示百分比值。如何为该栏设置动画,使其从左向右增长? 我已经拥有的动画功能无法像它希望的那样工作...... class EasyLineView : UI
我是一名优秀的程序员,十分优秀!