空输出png文件格式开罗

如何解决空输出png文件格式开罗

我已经为C渲染了一个示例。我的意思是,使用Cairo的最小C程序显示了Here。 但是,当我尝试渲染此代码时:

<p>ampm true:   <span id="time1"></span> (default)</p>
<p>ampm false:  <span id="time2"></span></p>

我得到一个空的png。看起来好像有东西,但没有画出来。 我编译:

#include <cairo.h> int main(void){ /* Where we gonna draw. The image to print. */ cairo_surface_t *surface; /* The context. The printed layer by a surface */ cairo_t *cr; /* The format (in this case ARGB),width and height of surface */ surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,120,120); /* The context behind of surface */ cr = cairo_create(surface); /* void cairo_set_source_rgb(cairo_t *cr,double red,double green,double blue); */ cairo_set_source_rgb(cr,0); /* void cairo_move_to(cairo_t *cr,double x,double y); */ /* After this call the current point will be (x,y). */ cairo_move_to (cr,0); /* void cairo_line_to(cairo_t *cr,double y); */ /* Adds a line to the path from the current position (x,y). After this call the current point will be (x,y). */ /* Must be a current point,otherwise the beahavior gonna be like move_to */ cairo_line_to (cr,1,1); cairo_move_to (cr,0); cairo_line_to (cr,1); /* void cairo_set_line_width(cairo_t *cr,double width); */ /* Sets the current line width within the cairo context. The line width value specifies the diameter of a pen is circular */ cairo_set_line_width (cr,0.2); /* void cairo_stroke(cairo_t *cr); */ /* A drawing operator that strokes the current path according to the current line width,line join,line cap,and dash settings. */ cairo_stroke (cr); /* void cairo_rectangle(cairo_t *cr,double y,double width,double height); */ /* Adds a closed sub-path rectangle of the given size to the current path at position (x,y) in user-space coordinates. */ /* This function is logically equivalent to: * cairo_move_to (cr,x,y); * cairo_rel_line_to (cr,width,0); * cairo_rel_line_to (cr,height); * cairo_rel_line_to (cr,-width,0); * cairo_close_path (cr); * *************************************/ cairo_rectangle (cr,0.5,0.5); /* cairo_set_source_rgba(cairo_t *cr,double blue,double alpha); */ /* Sets the source pattern within cr to a translucent color. This color will then be used for any subsequent drawing operation * until a new source pattern is set. * The color and alpha components are floating point numbers in the range 0 to 1. If the values passed in are outside that range,* they will be clamped. * The default source pattern is opaque black,(that is,it is equivalent to cairo_set_source_rgba(cr,0.0,1.0)). * *****************************************************************************************************************************/ cairo_set_source_rgba (cr,0.80); /* void cairo_fill(cairo_t *cr); */ /* A drawing operator that fills the current path according to the current fill rule,(each sub-path is implicitly closed before * being filled). After cairo_fill(),the current path will be cleared from the cairo context. * *****************************************************************************************************************************/ cairo_fill (cr); cairo_rectangle (cr,0.5); cairo_set_source_rgba (cr,0.60); cairo_fill (cr); cairo_rectangle (cr,0.40); cairo_fill (cr); cairo_surface_write_to_png(surface,"image.png"); cairo_destroy(cr); cairo_surface_destroy(surface); return 0; }

我的cc -o file $(pkg-config --cflags --libs cairo) file.c超出了这个范围:

brew info Cairo

pkg-config可以解决这个问题:

cairo: stable 1.16.0 (bottled),HEAD Vector graphics library with cross-device output support https://cairographics.org/ /usr/local/Cellar/cairo/1.16.0_3 (117 files,5.7MB) * Poured from bottle on 2020-10-12 at 00:17:34 From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/cairo.rb License: LGPL-2.1 ==> Dependencies Build: pkg-config ✔ Required: fontconfig ✔,freetype ✔,glib ✔,libpng ✔,lzo ✔,pixman ✔ ==> Options --HEAD Install HEAD version ==> Analytics install: 110,282 (30 days),348,240 (90 days),254,903 (365 days) install-on-request: 13,651 (30 days),54,037 (90 days),132,345 (365 days) build-error: 0 (30 days)

和pkg-config Cflags:

-L/usr/local/Cellar/cairo/1.16.0_3/lib -lcairo

有什么看不见的错误吗?一切看起来很棒。我不知道会发生什么。

解决方法

cairo_rectangle (cr,0.5,0.5);

您似乎假设坐标在0..1范围内,可以覆盖整个表面。

这不是事实。取而代之的是,坐标织布来自0..width0..height

您的指令将创建一个在每个方向上都有半个像素的矩形,并且线宽之前设置为1/5像素。这些坐标不会让您看到太多。

您链接的样本使用大得多的值。试试看。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-