我正在制作一个小型油漆程序.我在位图上使用SetPixel来绘制线条.当画笔大小变大时,如同25个像素一样,会有明显的性能下降.我想知道是否有更快的方法来绘制位图.以下是该项目的背景:
我将包括我的绘图代码,以防万一这是缓慢而不是Set-Pixel位.
这是在绘画发生的窗口:
private void canvas_MouseMove(object sender, MouseEventArgs e)
{
m_lastPosition = m_currentPosition;
m_currentPosition = e.Location;
if(m_penDown && m_pointInWindow)
m_currentTool.MouseMove(m_lastPosition, m_currentPosition, m_layer);
canvas.Invalidate();
}
Run Code Online (Sandbox Code Playgroud)
MouseMove的实现:
public override void MouseMove(Point lastPos, Point currentPos, Layer currentLayer)
{
DrawLine(lastPos, currentPos, currentLayer);
}
Run Code Online (Sandbox Code Playgroud)
DrawLine的实现:
// The primary drawing code for most tools. A line is drawn from the last position to the current position
public override void DrawLine(Point lastPos, Point currentPos, Layer currentLayer)
{
// Creat a line vector
Vector2D vector …Run Code Online (Sandbox Code Playgroud) 背景
我正在尝试创建一个简单的应用程序来真正理解整个DDD + TDD +等堆栈.我的目标是在运行时动态注入DAL存储库类.这使我的域和应用程序服务层可以测试.我计划使用"穷人的DI"来实现这一目标...所以我会在启动附近的一个简单的控制台应用程序中执行此操作:
// Poor man's DI, injecting DAL repository classes at runtime
var productRepository = new SimpleOrder.Repository.ProductRespository();
var customerRepository = new SimpleOrder.Repository.CustomerRepository();
var orderRepository = new SimpleOrder.Repository.OrderRepository();
// Constructor injection into this class in the Application Services layer,
// SimpleOrder.ApplicationFacade
OrderEntry oe = new OrderEntry(customerRepository, orderRepository, productRepository);
为了实现这种依赖注入,我创建了三个存储库接口:
-- ICustomerRepository -- IOrderRepository -- IProductRespository
一个典型的实现:
namespace SimpleOrder.Domain.Interfaces
{
public interface ICustomerRepository
{
Customer GetCustomerById(int customerId);
void SaveCustomer(Customer customer);
}
}
**请注意,SaveCustomer引用了域层中定义的Customer模型类.这是其他存储库的典型.
但是我不确定应该在哪个项目/层实施.我在解决方案中有5个项目:
SimpleOrder.ConsoleClient(presentation) - 我想从这里注入域的特定实现作为应用程序
SimpleOrder.ApplicationFacade(应用程序服务) - …
domain-driven-design interface ddd-repositories layer n-tier-architecture
请考虑以下代码:
library(ggplot2)
foo <- data.frame(x=1:10,A=1:10,B=10:1)
ggplot(melt(foo,id.vars="x"),aes(x,value,color=variable))+geom_line(size=5)
Run Code Online (Sandbox Code Playgroud)

我想将红线(A)置于B的顶部(参见交叉点),而颜色和它们在图例中出现的顺序不会改变.有什么办法吗?
我想学习如何在我的Android应用程序中创建图层(如在photoshop中).我想实现一个基本的东西:当我在画布中添加一个图像时,例如,我想要能够绘制画布,但画面不能影响图形的线条.然后我需要将该图像保存在我的SD卡上.
有什么建议/意见/例子吗?我可以用什么来实现这个目标?
我正在尝试通过创建图层并将其作为子图层添加到导航栏来更改导航栏的背景.但是,这只会影响导航栏.

我不想影响整个屏幕的顶部.代码包括:
let navBarLayer = StyleUtils.createGradientLayerWithColors(color: StyleUtils.Colors.SKY_BLUE, frame: (self.navigationController?.navigationBar.bounds)!)
self.navigationController?.navigationBar.layer.addSublayer(navBarLayer)
Run Code Online (Sandbox Code Playgroud)
所述createGradientLayerWithColors函数返回给定的帧中的CAGradientLayer.
我错过了什么?先感谢您.
编辑:
我试过纳撒尼尔的回答,但得到了这个:
值得一提的是,这也是一个TableView.
解:
我发现这个问题帮助我解决了这个问题.
最终正确的代码是:
func setNavBarColor() {
let navBar = self.navigationController?.navigationBar
//Make navigation bar transparent
navBar?.setBackgroundImage(UIImage(), for: .default)
navBar?.shadowImage = UIImage()
navBar?.isTranslucent = true
//Create View behind navigation bar and add gradient
let behindView = UIView(frame: CGRect(x: 0, y:0, width: UIApplication.shared.statusBarFrame.width, height: UIApplication.shared.statusBarFrame.height + (navBar?.frame.height)!))
let layerTop = StyleUtils.createGradientLayerWithColors(color: StyleUtils.Colors.SKY_BLUE, frame: behindView.bounds)
behindView.layer.insertSublayer(layerTop, at: 0)
self.navigationController?.view.insertSubview(behindView, belowSubview: navBar!)
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Erica Saduns Cookbook示例Chapter 8, Example 14 — Resize and Rotate来显然调整大小并旋转一个UIImageView.
1.)条纹背景视图.
2.)可以调整大小和旋转的交互式视图.
3.)具有透明部分的叠加图像.此视图在128处开始y轴,为768x768.
4.)上方和下方3,高度为2视图128.
******见下面的照片示例****
目前,我可以将整个视图的图层保存到照片库中[[[self view] layer] renderInContext:,并且#2的转换是正确的.但是,我需要一种方法来保存768x768 (照片示例中的浅绿色)框架,其中仅包括#2和#3,包括#2的转换.如果我使用[[#2 layer] renderInContext:,我会得到原始图像,而不是转换.(参见下面的#参考屏幕截图.
CGSize deviceSpec;
if ( IDIOM == IPAD ) { deviceSpec =CGSizeMake(768,768); } else { deviceSpec =CGSizeMake(320,480); }
if ( scale > 1.5 ) {
UIGraphicsBeginImageContextWithOptions(deviceSpec, NO, scale);
} else {
UIGraphicsBeginImageContext( deviceSpec );
}
CGContextRef …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我正在尝试将子视图添加到前面,然后将其放回到其原始图层位置.代码应该非常简单:
要将子视图放在前面(在我的自定义UIView类中):
[self.superview bringSubviewToFront:self];
Run Code Online (Sandbox Code Playgroud)
简单.我将原始z位置存储在一个名为的实例变量中,你猜对了zPosition.所以,前面的行-bringSubviewToFront:是:
zPosition = [self.superview.subviews indexOfObject:self];
Run Code Online (Sandbox Code Playgroud)
所以,我用来将子视图放在前面的所有代码都是:
zPosition = [self.superview.subviews indexOfObject:self];
[self.superview bringSubviewToFront:self];
Run Code Online (Sandbox Code Playgroud)
这应该是正常的.问题是当我尝试将子视图放回原位时.我只是这样做:
[self.superview exchangeSubviewAtIndex:zPosition withSubviewAtIndex:
[self.superview.subviews indexOfObject:self]];
Run Code Online (Sandbox Code Playgroud)
使用此代码,如果我有两个子视图,则会发生以下情况:
假设我有视图A和视图B.视图A在视图B上方.我点击视图B,它来到前面.我再次点击视图B(它应该回到原来的位置),没有任何反应,所以它现在在视图A上.如果我现在点击视图A,它会到达前面,但是当我再次点击它时(所以它应该回到原来的z位置:在视图B)下面,它的所有兄弟视图都消失了!
有谁看到可能导致这个问题的原因?
我试图使用setBeginTime将图层的不透明度和位置的动画延迟3秒.我已经调用了图层boxLayer.然而,动画在前3秒(该图层不应显示)中运行良好,图层将显示在其最终位置和不透明度.它不应该.组动画无法解决问题.有人可以帮忙吗?见下面的代码:
// Create an animation that will change the opacity of a layer
CABasicAnimation *fader = [CABasicAnimation animationWithKeyPath:@"opacity"];
// It will last 1 second and will be delayed by 3 seconds
[fader setDuration:1.0];
[fader setBeginTime:CACurrentMediaTime()+3.0];
// The layer's opacity will start at 0.0 (completely transparent)
[fader setFromValue:[NSNumber numberWithFloat:startOpacity]];
// And the layer will end at 1.0 (completely opaque)
[fader setToValue:[NSNumber numberWithFloat:endOpacity]];
// Add it to the layer
[boxLayer addAnimation:fader forKey:@"BigFade"];
// Maintain opacity to 1.0 JUST TO MAKE SURE IT …Run Code Online (Sandbox Code Playgroud) 我试图让下面的圆圈有一个不透明的纯白色,其中cornerRadius切出了UIView.
UIView *circle = [[UIView alloc] initWithFrame:CGRectMake(i * (todaySize + rightMargin), 0, smallSize, smallSize)];
circle.layer.cornerRadius = smallSize/2;
circle.layer.borderWidth = 0.5;
circle.layer.backgroundColor = [UIColor whiteColor].CGColor;
circle.backgroundColor = [UIColor whiteColor];
[self addSubview:circle];
Run Code Online (Sandbox Code Playgroud)
我尝试过一些事情,比如设置backgroundColor和opaque而没有任何运气.颜色混合图层仍然显示圆圈的周围是透明的.有人知道如何解决这个问题吗?