迈克尔·阿布拉什图形编程黑皮书:优化与技术探索

3星 · 超过75%的资源 需积分: 10 3 下载量 111 浏览量 更新于2024-07-24 1 收藏 13.68MB PDF 举报
《图形编程黑皮书》(Graphics Programming Black Book, Special Edition) 是由Michael Abrash撰写的一本经典著作,由The Coriolis Group出版社出版,其ISBN号为1576101746,首次发行日期为1997年7月1日。这本书是图像编程领域的权威指南,特别适合对图形编程有浓厚兴趣的专业人士或开发者深入学习。 该书分为三个部分,探讨了高性能图形编程的关键技术和策略。以下是各章节的概览: 1. **最佳优化存在于你的思维深处** - "The Best Optimizer Is between Your Ears" 这一章强调人类因素在代码优化中的重要作用。作者阐述理解高效率编程的重要性,指出速度并不是唯一的衡量标准,而是需要综合考虑性能、可读性和维护性。章节内容包括规则制定、明确目标、设计架构(如大蓝图和小模块)、深入理解问题领域、权衡不同的解决方案以及激发创新思维。 2. **两种世界的差异:汇编语言的独特性** - "A World Apart" 在这个章节中,作者讨论了汇编语言与高级语言的不同之处,特别是关于个体指令与整体性能的关系。通过介绍汇编语言的本质特性、转换效率的挑战、自给自足性以及知识的重要性,读者可以了解如何选择合适的起点,开始探索汇编语言的世界。 3. **假设一切:理解并利用Zen定时器** - "Assume Nothing" 这一部分着重于理解并充分利用底层资源,例如通过"Zen Timer"这一概念来揭示无知的成本。章节讲解如何正确使用工具和技术,以避免由于缺乏了解而导致的性能损失。 此外,书中还提供了详细的介绍、前言以及关于作者的信息,帮助读者全面理解和应用书中所学的知识。为了方便查找特定内容,书中还提供了索引和搜索提示,允许读者快速定位他们感兴趣的主题。 《图形编程黑皮书》不仅涵盖了基础和进阶的图形编程技术,而且深入探讨了如何在实践中进行高效优化,对于任何想要提升图形性能的程序员来说,都是一本不可或缺的参考书。阅读本书将有助于提升你的编程技巧,理解硬件与软件交互的微妙之处,并培养出在复杂系统中做出明智决策的能力。

优化这段代码能产生不同的单元格宽度:public void myGraphicsGeneration(String name,String cellsValue[][], String path) { // 字体大小 int fontTitileSize = 15; // 横线的行数 int totalrow = cellsValue.length+1; // 竖线的行数 int totalcol = 0; if (cellsValue[0] != null) { totalcol = cellsValue[0].length; } // 图片宽度 int imageWidth = 1024; // 行高 int rowheight = 40; // 图片高度 int imageHeight = totalrow*rowheight+50; // 起始高度 int startHeight = 10; // 起始宽度 int startWidth = 10; // 单元格宽度 int colwidth = (int)((imageWidth-20)/totalcol); BufferedImage image = new BufferedImage(imageWidth, imageHeight,BufferedImage.TYPE_INT_RGB); Graphics graphics = image.getGraphics(); graphics.setColor(Color.WHITE); graphics.fillRect(0,0, imageWidth, imageHeight); graphics.setColor(new Color(220,240,240)); //画横线 for(int j=0;j<totalrow; j++){ graphics.setColor(Color.black); graphics.drawLine(startWidth, startHeight + (j + 1) * rowheight, startWidth + colwidth * totalcol, startHeight + (j + 1) * rowheight); } //画竖线 for(int k=0;k<totalcol+1;k++){ graphics.setColor(Color.black); graphics.drawLine(startWidth + k * colwidth, startHeight + rowheight, startWidth + k * colwidth, startHeight + rowheight * totalrow); } //设置字体 Font font = new Font("微软雅黑",Font.BOLD,fontTitileSize); graphics.setFont(font); //写标题 String title = "【"+ name +"】"; graphics.drawString(title, startWidth, startHeight+rowheight-10); //写入内容 for(int n=0;n<cellsValue.length;n++){ for(int l=0;l<cellsValue[n].length;l++){ if (n == 0) { font = new Font("微软雅黑",Font.BOLD,fontTitileSize); graphics.setFont(font); }else if (n > 0 && l >0) { font = new Font("微软雅黑",Font.PLAIN,fontTitileSize); graphics.setFont(font); graphics.setColor(Color.RED); } else { font = new Font("微软雅黑",Font.PLAIN,fontTitileSize); graphics.setFont(font); graphics.setColor(Color.BLACK); } if(cellsValue[n][l]==null){ cellsValue[n][l] = ""; } graphics.drawString(cellsValue[n][l].toString(), startWidth + colwidth * l + 5, startHeight + rowheight * (n + 2) - 10); } } // 保存图片 createImage(image, path); }

2023-06-06 上传