码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Go语言学习笔记-A Tour of Go 练习笔记-Images


    Exercise: Images

    练习题目:

    Remember the picture generator you wrote earlier? Let's write another one, but this time it will return an implementation of image.Image instead of a slice of data.

    Define your own Image type, implement the necessary methods, and call pic.ShowImage.

    Bounds should return a image.Rectangle, like image.Rect(0, 0, w, h).

    ColorModel should return color.RGBAModel.

    At should return a color; the value v in the last picture generator corresponds to color.RGBA{v, v, 255, 255} in this one.

    联系程序:

    1. package main
    2. import "golang.org/x/tour/pic"
    3. import "image"
    4. import "image/color"
    5. type Image struct {
    6. }
    7. func (i Image) ColorModel() color.Model {
    8. return color.RGBAModel
    9. }
    10. func (i Image) Bounds() image.Rectangle {
    11. return image.Rect(0, 0, 255, 255)
    12. }
    13. func (i Image) At(x, y int) color.Color {
    14. return color.RGBA{(uint8)(x+y), (uint8)(x+y), 255, 255}
    15. }
    16. func main() {
    17. m := Image{}
    18. pic.ShowImage(m)
    19. }

    运行结果:

     学习笔记:该题目通过为结构体Image实现Go中Image接口定义的三个方法,从而达到生成一张自定义图片的功能。ColorModel定义图片的色彩模型,Bounds定义图片的大小,At定义了图片中每个点的颜色值(程序中,每个点的颜色值是通过点位坐标(x,y)相加获得,也可以修改为x*y等取值方式)。

  • 相关阅读:
    mybatis源码阅读系列(一)
    玩转Makefile文件
    flex的用法 代码6
    苹果安卓网页的H5封装成App的应用和原生开发的应用有什么不一样?
    sublime merge 自定义命令
    2.7 Python-运算符
    Node.js 零基础入门 Node.js 零基础入门第四天 4.1 数据库的基本概念 && 4.2 安装并配置MySQL && 4.3 MySQL的基本使用
    java Arrays类
    科研试剂DSPE-PEG-VIP,二硬脂酰基磷脂酰乙醇胺-聚乙二醇-血管活性肠肽VIP
    LSB利器-zsteg
  • 原文地址:https://blog.csdn.net/sxmatch/article/details/128132643
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号