Iphone 画图层

Spring AI Alibaba Graph进阶:如何用图算法优化你的推荐系统? 本文深入探讨了如何利用Spring AI Alibaba Graph的图算法优化推荐系统。通过分析用户行为数据的网络化特征,结合加权随机游走和社区发现算法,显著提升推荐精准度和用户点击率。文章还分享了混合推荐架构设计、性能优化技巧及生产环境中的实战经验,为开发者提供了一套完整的图算法推荐解决方案。 阅读详情

Example: Using Multiple CGLayer objects to Draw a Flag

This section shows how to use two CGLayer objects to draw the flag shown in Figure 12-5 onscreen. First you’ll see how to reduce the flag to simple drawing primitives, then you’ll look at the code needed to accomplish the drawing.

Figure 12-5   The result of using layers to draw the United States flag

The result of using layers to draw the United States flag

From the perspective of drawing it onscreen, the flag has three parts:

  • A pattern of red and white stripes. You can reduce the pattern to a single red stripe because, for onscreen drawing, you can assume a white background. You create a single red rectangle, then repeatedly draw the rectangle at various offsets to create the seven red stripes necessary for the U.S. flag. A CGLayer is ideal for repeated drawing. You draw the red rectangle to a CGLayer, then draw the CGLayer onscreen seven times.

  • A blue rectangle. You need the blue rectangle once, so using a CGLayer is of no benefit. When it comes time to draw the blue rectangle, draw it directly onscreen.

  • A pattern of 50 white stars. Like the red stripe, a CGLayer is ideal for drawing the stars. You create a path that outlines a star shape, and then fill the path with white. Draw one star to a CGLayer, then draw the layer 50 times, adjusting the offset each time to get the appropriate spacing.

The code in “Code that uses layers to draw a flag” produces the output shown in Figure 12-5 . A detailed explanation for each numbered line of code appears following the listing. The listing is rather long, so you might want to print the explanation so that you can read it as you look at the code. The myDrawFlag routine is called from within a Cocoa or Carbon application. The application passes a window graphics context and a rectangle that specifies the size of the view associated with the window graphics context.

Note:  Before you call this or any routine that uses CGLayer objects, you must check to make sure that the system is running Mac OS X v10.4 or later and has a graphics card that supports using CGLayer objects.

Listing 12-1   Code that uses layers to draw a flag

void myDrawFlag (CGContextRef context, CGRect* contextRect)
{
    int          i, j,
                 num_six_star_rows = 5,
                 num_five_star_rows = 4;
    float        start_x = 5.0,// 1
                 start_y = 108.0,// 2
                 red_stripe_spacing = 34.0,// 3
                 h_spacing = 26.0,// 4
                 v_spacing = 22.0;// 5
    CGContextRef myLayerContext1,
                 myLayerContext2;
    CGLayerRef   stripeLayer,
                 starLayer;
    CGRect       myBoundingBox,// 6
                 stripeRect,
                 starField;
 // ***** Setting up the primitives *****
    const CGPoint myStarPoints[] = {{ 5, 5},   {10, 15},// 7
                                    {10, 15},  {15, 5},
                                    {15, 5},   {2.5, 11},
                                    {2.5, 11}, {16.5, 11},
                                    {16.5, 11},{5, 5}};
 
    stripeRect  = CGRectMake (0, 0, 400, 17); // stripe// 8
    starField  =  CGRectMake (0, 102, 160, 119); // star field// 9
 
    myBoundingBox = CGRectMake (0, 0, contextRect->size.width, // 10
                                      contextRect->size.height);
 
     // ***** Creating layers and drawing to them *****
    stripeLayer = CGLayerCreateWithContext (context, // 11
                            stripeRect.size, NULL);
    myLayerContext1 = CGLayerGetContext (stripeLayer);// 12
 
    CGContextSetRGBFillColor (myLayerContext1, 1, 0 , 0, 1);// 13
    CGContextFillRect (myLayerContext1, stripeRect);// 14
 
    starLayer = CGLayerCreateWithContext (context,
                            starField.size, NULL);// 15
    myLayerContext2 = CGLayerGetContext (starLayer);// 16
    CGContextSetRGBFillColor (myLayerContext2, 1.0, 1.0, 1.0, 1);// 17
    CGContextAddLines (myLayerContext2, myStarPoints, 10);// 18
    CGContextFillPath (myLayerContext2);    // 19
 
     // ***** Drawing to the window graphics context *****
    CGContextSaveGState(context);    // 20
    for (i=0; i< 7;  i++)   // 21
    {
        CGContextDrawLayerAtPoint (context, CGPointZero, stripeLayer);// 22
        CGContextTranslateCTM (context, 0.0, red_stripe_spacing);// 23
    }
    CGContextRestoreGState(context);// 24
 
    CGContextSetRGBFillColor (context, 0, 0, 0.329, 1.0);// 25
    CGContextFillRect (context, starField);// 26
 
    CGContextSaveGState (context);              // 27
    CGContextTranslateCTM (context, start_x, start_y);      // 28
    for (j=0; j< num_six_star_rows;  j++)   // 29
    {
        for (i=0; i< 6;  i++)
        {
            CGContextDrawLayerAtPoint (context,CGPointZero,
                                            starLayer);// 30
            CGContextTranslateCTM (context, h_spacing, 0);// 31
        }
        CGContextTranslateCTM (context, (-i*h_spacing), v_spacing); // 32
    }
    CGContextRestoreGState(context);
 
    CGContextSaveGState(context);
    CGContextTranslateCTM (context, start_x + h_spacing/2, // 33
                                 start_y + v_spacing/2);
    for (j=0; j< num_five_star_rows;  j++)  // 34
    {
        for (i=0; i< 5;  i++)
        {
        CGContextDrawLayerAtPoint (context, CGPointZero,
                            starLayer);// 35
            CGContextTranslateCTM (context, h_spacing, 0);// 36
        }
        CGContextTranslateCTM (context, (-i*h_spacing), v_spacing);
    }
    CGContextRestoreGState(context);
 
    CGLayerRelease(stripeLayer);// 37
    CGLayerRelease(starLayer);        // 38
}

Here’s what the code does:

  1. Declares a variable for the horizontal location of the first star.

  2. Declares a variable for the vertical location of the first star.

  3. Declares a variable for the spacing between the red stripes on the flag.

  4. Declares a variable for the horizontal spacing between the stars on the flag.

  5. Declares a variable for the vertical spacing between the stars on the flag.

  6. Declares rectangles that specify where to draw the flag to (bounding box), the stripe layer, and the star field.

  7. Declares an array of points that specify the lines that trace out one star.

  8. Creates a rectangle that is the shape of a single stripe.

  9. Creates a rectangle that is the shape of the star field.

  10. Creates a bounding box that is the same size as the window graphics context passed to the myDrawFlag routine.

  11. Creates a layer that is initialized with the window graphics context passed to the myDrawFlag routine.

  12. Gets the graphics context associated with that layer. You’ll use this layer for the stripe drawing.

  13. Sets the fill color to opaque red for the graphics context associated with the stripe layer.

  14. Fills a rectangle that represents one red stripe.

  15. Creates another layer that is initialized with the window graphics context passed to the myDrawFlag routine.

  16. Gets the graphics context associated with that layer. You’ll use this layer for the star drawing.

  17. Sets the fill color to opaque white for the graphics context associated with the star layer.

  18. Adds the 10 lines defined by the myStarPoints array to the context associated with the star layer.

  19. Fills the path, which consists of the 10 lines you just added.

  20. Saves the graphics state of the windows graphics context. You need to do this, because you’ll draw the same stripe repeatedly, but in different locations.

  21. Sets up a loop that iterates 7 times, once for each red stripe on the flag.

  22. Draws the stripe layer (which consists of a single red stripe).

  23. Translates the current transformation matrix so that the origin is positioned at the location where the next red stripe must be drawn.

  24. Restores the graphics state to what is was prior to drawing the stripes.

  25. Sets the fill color to the appropriate shade of blue for the star field. Note that this color has an opacity of 1.0. Although all the colors in this example are opaque, they don’t need to be. You can create nice effects with layered drawing by using partially transparent colors. Recall that an alpha value of 0.0 specifies a transparent color.

  26. Fills the star field rectangle with blue. You draw this rectangle directly to the window graphics context. Don’t use layers if you are drawing something only once.

  27. Saves the graphics state for the window graphics context because you’ll be transforming the CTM to position the stars properly.

  28. Translates the CTM so that the origin lies in the star field, positioned for the first star (left side) in the first (bottom) row.

  29. This and the next for loop sets up the code to repeatedly draw the star layer so the five odd rows on the flag each contain six stars.

  30. Draws the star layer to the window graphics context. Recall that the star layer contains one white star.

  31. Positions the CTM so that the origin is moved to the right in preparation for drawing the next star.

  32. Positions the CTM so that the origin is moved upward in preparation for drawing the next row of stars.

  33. Translates the CTM so that the origin lies in the star field, positioned for the first star (left side) in the second row from the bottom. Note that the even rows are offset with respect to the odd rows.

  34. This and the next for loop sets up the code to repeatedly draw the star layer so the four even rows on the flag each contain five stars.

  35. Draws the star layer to the window graphics context.

  36. Positions the CTM so that the origin is moved to the right in preparation for drawing the next star.

  37. Releases the stripe layer.

  38. Releases the star layer.

Pulseaudio之同步/异步(十一) PulseAudio是一个声音服务器,一个后台进程从一个或多个音源(进程或输入设备)接受声音输入 然后重定向声音到一个或多个槽(声卡,远程网络PulseAudio服务,或其他进程)。 PulseAudio的主要特点包括: 可对每一个应用程序进行音量控制Per-application volume controls 可扩展的插件与支持可装载模块架构 兼容性许多流行的音频应用程序 支持多重音源和多重输出 低延时操作和支持延迟测量 一个对处理器资源效率零拷贝内存架构 能够发现本地网络上使用PulseAu 阅读详情

相关推荐

(学习笔记)机器人自主导航从零开始第四步———Rviz、Gazebo、Meshlab的安装

一、Rviz的安装 Rviz是一个

qq_59475883的博客 5068

iphone系统架构以及各层提供的主要服务

iPhone OS的技术实现包括四层:核心OS(Core OS)层、核心服务(Core Service)层、媒体(Media)层和Cocoa Touch层。系统低层为所有应用提供基础服务,其他较高层包含较多的复杂服务和技术。系统层次架构如图   当开发iPhone应用时,应尽可能多地引用较高层框架(Framework)。与低层框架(Framework)相比,较高层框架为低层结构提供了面向对

619

搞定8GB/s数据流:一个FPGA工程师的XDMA驱动调优实战(附避坑清单)

本文详细记录了FPGA工程师在XDMA驱动调优过程中实现8GB/s高带宽数据流的实战经验。通过优化DDR访问、中断响应、DMA映射等关键环节,解决了PCIE数据采集卡在高带宽场景下的性能瓶颈,并提供了实用的避坑清单和技术方案。

weixin_29194255的博客 213

iPhone开发笔记[1/50]:初学iPhone上用Quartz 2D画图

参考了An iOS 4 iPhone Graphics Drawing Tutorial using Quartz 2D这篇文章,用了30分钟在iPhone上画出了一条直线,核心代码全在drawRect这个方法中: - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); ...

申龙斌的程序人生 359

【ENVI初学】查看影像空间分辨率及重采样

例如,如果线段长度为900米,对应的像素数量为30个,那么影像的空间分辨率为30米。通过计算长度与像素数量的比值,即可得到影像的空间分辨率。,在弹出的对话框中,输入重采样后输出文件的xy分辨率大小。在测量结果窗口中,可以看到该线段的长度以及角度。在影像上点击并拖动鼠标,绘制一条直线段。工具,选择要重采样的影像后点击ok。,避免了插值过程中光谱信息的改变。:最近邻插值法通过选择原始影像中。在ENVI中打开影像后右键选择。指示了每个像素的地理跨度(聚合为一个新像素,通常通过。方法一:查看影像的元数据。

weixin_41619112的博客 5595

Win11内核隔离无法打开的解决方案详解

内核隔离问题的解决需遵循"先硬件后软件"的排查原则,90%以上的案例可通过驱动清理或外设断开解决。对于必须禁用该功能的用户,建议定期使用Windows Defender进行全盘扫描,并保持系统更新至最新版本。技术决策需在安全性和兼容性之间取得平衡,本文提供的多维解决方案可帮助用户构建更稳定的Windows 11使用环境。

mmoo_python的博客 4854

iphone画图

0 CGContextRef context = UIGraphicsGetCurrentContext(); 设置上下文 1 CGContextMoveToPoint 开始画线 2 CGContextAddLineToPoint 画直线 4 CGContextAddEllipseInRect 画一椭圆 4 CGContextSetLineCap 设置线条终点形状 4 CGC

任海丽(3G/移动开发) 2081

从零开始安装 Windows 11 和 Ubuntu 22.04 双系统

本文详解Windows与Ubuntu 22.04双系统安装流程:需提前确认BIOS模式(UEFI/GPT或Legacy/MBR),关闭BitLocker加密、设备加密及快速启动;推荐Rufus/Ventoy制作启动盘。安装时需规划分区方案(建议单独划分EFI系统分区),注意引导器安装位置选择。双系统启动通过BIOS引导顺序管理,安装后需同步Windows与Linux系统时间。教程适配主流UEFI+GPT设备,强调操作前数据备份及Windows更新策略调整,避免兼容性问题。

萑澈的博客 3807

iPhone 动画图片

设置动画图片的步骤:   1 定义图片数组   2 初始化UIImageView对象 并添加到视图中   3 设置动画的列组视图 周期时间 循环次数   4 开始动画 代码: NSMutableArray* imageArray = [[NSMutableArray alloc]initWithObjects:nil]; for(int i = 1 ;i { UIImage

u011413730的专栏 459

DRV2605L触觉驱动芯片实战指南:从自动校准到音频转触觉应用

触觉反馈技术是现代人机交互的核心组成部分,它通过精确控制振动马达来模拟物理触感,广泛应用于智能手机、游戏手柄和汽车触摸屏等领域。其原理在于将电信号转化为机械振动,关键在于如何高效、精准地驱动不同类型的马达(如ERM和LRA)。这项技术的核心价值在于提升交互的真实感和沉浸感。在工程实践中,集成驱动芯片如DRV2605L通过内置智能反馈引擎和自动校准功能,解决了传统驱动方式响应慢、效果不一致的难题。它特别适用于需要高质量触觉反馈的应用场景,例如消费电子、游戏外设和车载信息娱乐系统。其中,自动校准能自适应优化驱动

weixin_42631411的博客 346

图解联合概率密度、边缘概率密度、条件概率密度之间的关系

简要图解联合概率密度、边缘概率密度、条件概率密度之间的关系

一个搬运知识的笨小孩 2万+

Iphone Quartz 画图坐标的转换

Iphone 中坐标的原点是在左上角,但是 Quartz中绘图的坐标原点在左下角,如果不转换的话,绘制的字符将是上下颠倒. 那么,如何转换呢? //显示区域的高度 CGContextTranslateCTM(context, 0.0, rect.size.height); //高度乘以-1,加上上面的最大高度,就实现了上下翻转 CGContextScaleCTM(context, 1...

gaomingjun的博客 165

使用MATLAB和Simulink来设计并仿真一个智能家居多传感器数据融合系统

智能家居多传感器数据融合系统旨在通过集成来自多种不同类型的传感器的数据,以提供更精确和可靠的环境信息或用户状态监测。例如,将温度、湿度、光照强度、运动检测等多种传感器的数据结合起来,可以更好地了解家庭内部的状态,并做出相应的调整或响应。在这个教程中,我们将使用MATLAB和Simulink来设计并仿真一个智能家居多传感器数据融合系统。

amy_mhd的博客 194

iphone开发笔记和技巧总结----各处收集所得

iphone开发笔记和技巧总结 1.iphone程序中实现截屏的一种方法 在iphone程序中实现截屏的一种方法://导入头文件#import QuartzCore/QuartzCore.h//将整个self.view大小的图层形式创建一张图片image UIGraphicsBeginImageContext(self.view.bounds.size);[self.view.lay...

dayiqiao8331的博客 173

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

InTheHand.Net.Personal+BlueTooth4,蓝牙开发

项目中有蓝牙开发的必备dll,现在网上相关的文档博客不少,有的说的多有的说少,但是却很少有这两个dll,分享一下。

iphone6无法加载图片资源文件

这样写之后,所有的机型全部能够正常展示,除了ipone6。查找一番原因之后发现,我的图片资源都是webp格式的图像资源,ipone6无法解析该资源为图像资源,所以无法加载。电脑自带画图工具打开,再点击保存,选择为png或者jpg格式。在开发项目时,需要动态的展示图片。

weixin_44312227的博客 414

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

如何实现远程协助iPhone?

朋友、家人、同事的手机出现问题希望你来帮助解决时,一款远程协助软件可以为你省不少力。公司中要为iPhone用户提供技术支持也需要一款实用的远程工具来提高工作效率和竞争力。一般远程控制安卓手机部分品牌可以轻松实现,但是由于苹果公司并未授权给任何公司iPhone的signing,因此目前还没有任何远程控制软件可以实现直接控制操作iPhone。虽然无法直接控制,但也可以通过屏幕共享、屏幕白板(画图)、发送截屏等功能来提供间接的远程协助。

RSUPPORT的博客 5420

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

iphone 在UIView上画图,画线,画多边形

1.自定义一个 CustomView : UIView类,该类继承自 UIView,当然也可以继承自UIView的子类,比如 UIScrollView2.在CustomView中重写下面的方法,这个方法中的内容绘制代码,可以参考 iphone Quartz 2D 开发指南.- (void)drawRect:(CGRect)rect { CGContextRef conte

wu11wuwu的专栏 1万+

iphone 看法常用技巧总结

原文摘自:http://www.cocoachina.com/iphonedev/sdk/2011/1028/3433.html1)iphone程序中实现截屏的一种方法 在iphone程序中实现截屏的一种方法: //导入头文件 #import QuartzCore/QuartzCore.h //将整个self.view大小的图层形式创建一张图片image UIGraphicsBeginIma...

weixin_34221276的博客 65

iPhone操作系统整体架构层次

1.Core OS层-----包含核心部分、文件系统、网络基础、安全特性、能量管理和一些设备驱动,还有一些系统级别的API。 2.Core Services层----提供核心服务,例如字符串处理函数、集合管理、网络管理、URL处理工具、联系人维护、偏好设置等。 . 3.Media层----该层框架和服务依赖Core Services层,向Cocoa Touch层提供画

新风作浪的博客专栏 5003

方案中画图的重要性

其实在设计方案中,一个合适的画图往往比很多文字叙述都直观。这一阵子对iphone移动开发产生了兴趣,感觉心中有很多东西要做,有很多东西要写。 可是最直观,最形象的东西,还是在一张大图上写写画画,不断扩展,想想最终给人展示的东西不也是一个图形吗。

ts_rfl的专栏 556
上一篇: Save Image to UserDefaults
下一篇: Using multiple CGLayer objects to draw a flag
nitghost
博客等级 码龄19年 32粉丝 111原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址