首页 \ 问答 \ 在当前上下文中绘制弧(Drawing arc in current context)

在当前上下文中绘制弧(Drawing arc in current context)

我试图在当前上下文中绘制自定义弧,但结果不是我期望看到的,我有简单的代码行,如果绘制方法。

-(void) drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextBeginPath(context);
    CGContextSetGrayFillColor(context, 1.0, 0.7);
    CGContextMoveToPoint(context, 100,100);
    CGContextAddArc(context, 100, 100, 80, 0, M_PI_2, 0);
    CGContextClosePath(context);
    CGContextFillPath(context);
}

这是结果。 在此处输入图像描述

但我预计会看到这样的结果。 为什么M_PI_2出现在圆圈的底部? 应该有3 * M_PI_2,我做错了什么? 在此处输入图像描述


I trying to draw custom arc in current context, but the result is not what i expected to see, i have the simple lines of code if draw method.

-(void) drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextBeginPath(context);
    CGContextSetGrayFillColor(context, 1.0, 0.7);
    CGContextMoveToPoint(context, 100,100);
    CGContextAddArc(context, 100, 100, 80, 0, M_PI_2, 0);
    CGContextClosePath(context);
    CGContextFillPath(context);
}

and here is the result. enter image description here

But I'm was expected to see result like this. Why M_PI_2 appears on bottom side of the circle? there should be a 3*M_PI_2, what I'm doing wrong? enter image description here


原文:https://stackoverflow.com/questions/14285518
更新时间:2023-07-19 06:07

最满意答案

也许我的画布有零宽度和高度。 因为我只是初始化它,并没有使用。 我只是添加这个命令,一切都完成了。

myCanvas.drawRectangle(0,0,1,1);

所以我的画布有宽度和高度。 您也可以尝试其他绘图,如多边形,圆形或椭圆形。


maybe my canvas has zero width and height. because i just initialize it and haven't use yet. i just add this command and all done.

myCanvas.drawRectangle(0,0,1,1);

so my canvas has width and height. you can also try another draw, like polygon, circle or ellipse.

相关问答

更多
  • 默认缓冲区大小为8192个字符 http://developer.android.com/reference/java/io/BufferedReader.html BufferedReader(Reader in) Constructs a new BufferedReader, providing in with a buffer of 8192 characters. 除了这个文档,我已经提取了rt.jar压缩文件,并且使用JD-GUI从java.io. *中反编译了BufferedReader. ...
  • 随机猜测:你正在使用sizeof buf ,其中buf只是一个指针(可能传递给一个函数),从而获得指针的大小而不是指针所指向的内存块的大小。 你不能使用sizeof获得后者,你必须在一个单独的变量中传递它。 Random guess: you're using sizeof buf where buf is just a pointer (probably passed to a function), and thus getting the size of the pointer instead of t ...
  • 总之:没有 C不会执行任何运行时检查,除非您手动执行它们。 您可以使用自己的函数,宏和每个缓冲区簿记来防止无效访问。 但是,您将不得不在任何地方使用此接口,这意味着您将无法直接访问该缓冲区。 由于额外的条件检查,您还会看到对性能的影响。 您可以通过在代码分支上使用直接访问来避免其中的一些情况,这些代码分支被证明不会导致越界访问。 编辑: 还有一个相当主要的问题是“一旦检测到无效访问,代码应该做什么”。 你的程序是否应该输出一个错误并退出,就好像它遇到了其他语言的异常一样? 它应该忽略错误吗? 它应该试图解决 ...
  • 还没有亲自尝试过。 Youtube有一个弃用的函数,即getVideoBytesLoaded() ,它返回当前视频加载的字节数。 它现在被getVideoLoadedFraction()所取代 。 Havent personally tried this yet. Youtube has a deprecated function namely getVideoBytesLoaded() which returns the number of bytes loaded for the current vid ...
  • 要回答你的直接问题:(1)文件系统倾向于使用2的幂,所以你想要做同样的事情。 (2)工作缓冲区越大,误差小的影响就越小。 如你所说,如果你分配4100并且实际的块大小是4096,你需要两次读取来填充缓冲区。 相反,如果你有一个1,000,000字节的缓冲区,那么一个块高或低并不重要(因为它需要245个4096字节的块来填充该缓冲区)。 此外,较大的缓冲区意味着OS具有更好的订购读取的机会。 也就是说,我不会使用NIO。 相反,我会使用一个简单的BufferedInputStream ,我的read()可能有 ...
  • 也许我的画布有零宽度和高度。 因为我只是初始化它,并没有使用。 我只是添加这个命令,一切都完成了。 myCanvas.drawRectangle(0,0,1,1); 所以我的画布有宽度和高度。 您也可以尝试其他绘图,如多边形,圆形或椭圆形。 maybe my canvas has zero width and height. because i just initialize it and haven't use yet. i just add this command and all done. myC ...
  • 当您说可以使用mmap定期收集性能数据时,您的理解是正确的。 在开始之前, perf使用两个缓冲区来记录不同类型的事件。 在主环缓冲区(环形缓冲区包含该辅助缓冲区)下使用辅助缓冲区来存储不同种类的事件信息 。 既然你问我关于主要的perf缓冲区,我会尝试回答这个问题。 您可以修改perf缓冲区大小。 根据文档, perf缓冲区大小是根据页面定义的。 它被定义为1 + 2 ^ n页,其中需要一个页面来存储有关perf使用的环形缓冲区的元数据。 当您尝试使用perf record记录事件时,(阅读perf re ...
  • 简答:没有。 答案很长:或许,有些黑客攻击...... 编辑此类后,您必须自己构建Tomcat: Jasper常量 ...或者你可以做一个Perl派,并一次编辑所有的JSP。 首先备份,因为这是在线编辑: 对于没有缓冲区集的指令: /usr/bin/perl -pi -e 's|<%@ page|<%@ page buffer="new" |g' `find . -type f -name '*.jsp'` 对于已设置的缓冲区: /usr/bin/perl -pi -e 's|buffer="old"|b ...
  • 我的问题解决了,当我使用另一种颜色TYPE_4BYTE_ABGR而不是TYPE_INT_ARGB 。 根据文档,我看不出它会如何影响缓冲区大小,因为它们都是: an image with 8-bit RGBA color components 不过,我现在正在获得正确的缓冲区大小。 我将尝试进行更多调查,并在找到解释后发布更新。 My problem was solved, when I used another color type, TYPE_4BYTE_ABGR instead of TYPE_IN ...
  • 这不是那样的 sizeof(buffer); 返回指针buffer的大小,而不是数组。 如果您有一个如下所示的数组 char szArray[100]; 然后 sizeof(szArray); 将返回100,因为szArray是一个数组,但指针不是数组。 This does not work like that sizeof(buffer); returns the size of buffer which is a pointer, not an array. If you have an ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)