| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 488 人关注过本帖
标题:求高人指教,GD与数组结合的问题
只看楼主 加入收藏
zfm0210
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2011-11-18
结帖率:60%
收藏
已结贴  问题点数:20 回复次数:9 
求高人指教,GD与数组结合的问题
小弟已经写了一段程序是可以将
图片附件: 游客没有浏览图片的权限,请 登录注册
显示出来的。用的是switch的语句,但是好像感觉程序太长了,希望可以有更加简单的办法。因为以前有做过一个text版本是用数组来做的,所以小弟试想用数组来试试看。

希望有高手能提示下,更好,更简便的方法
搜索更多相关主题的帖子: 工作 
2012-03-14 22:08
zaixuexi
Rank: 12Rank: 12Rank: 12
来 自:上海
等 级:火箭侠
威 望:8
帖 子:858
专家分:3233
注 册:2010-12-1
收藏
得分:10 
5*3,18位,3个字节,亮点置1,暗点0

技术问题,请不要以短消息方式提问
2012-03-16 00:02
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:10 
不知道你能不能运行
(Windows, .NET4, by VS2010)

test_GDI.exe.zip (9 KB)

不是.zip文件,改文件扩展名为.exe即可。

运行画面:
20120316025419.jpg.zip (50.05 KB)


[ 本帖最后由 TonyDeng 于 2012-3-16 03:18 编辑 ]

授人以渔,不授人以鱼。
2012-03-16 02:52
zfm0210
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2011-11-18
收藏
得分:0 
回复 3楼 TonyDeng
可以看到,请问是用什么方法来做的啊?
2012-03-16 05:39
zfm0210
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2011-11-18
收藏
得分:0 
回复 2楼 zaixuexi
刚刚在学,还在摸索,所以不是很明白a
2012-03-16 05:41
zfm0210
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2011-11-18
收藏
得分:0 
这个是我现在写的程序,是可以显示出图片,但是我觉得应该可以更简单的方法,希望可以指点下[code]#include <stdio.h>
#include <gd.h>
 
int main()
{
 
  
  FILE *jpgFile = NULL;
 gdImagePtr gdImage =gdImageCreate (600,200);
 
 
 
  int black;
  int red;
 
  int a,b,c,d;
  scanf("%1d%1d%1d%1d",&a,&b,&c,&d);
 
 
   
    black = gdImageColorAllocate(gdImage, 0, 0, 0);
     
   
    red = gdImageColorAllocate(gdImage, 255, 0, 0);
   
   
    gdImageSetPixel(gdImage, 60, 100, red);
   
    switch (a)  
      {         
        case 0 : gdImageFilledEllipse( gdImage, 20, 20, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 40, 20, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 60, 20, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 20, 40, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 60, 40, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 20, 60, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 60, 60, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 20, 80, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 60, 80, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 20, 100, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 40, 100, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 60, 100, 20, 20, red );break;
                 
         case 1 : gdImageFilledEllipse( gdImage, 40, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 100, 20, 20, red );break;
                 
         case 2 : gdImageFilledEllipse( gdImage, 20, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 20, 20, 20, red );      
                  gdImageFilledEllipse( gdImage, 60, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 20, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 20, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 20, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 100, 20, 20, red );break;
                 
         case 3 : gdImageFilledEllipse( gdImage, 20, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 20, 20, 20, red );      
                  gdImageFilledEllipse( gdImage, 60, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 20, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 20, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 100, 20, 20, red );break;
                 
         case 4 : gdImageFilledEllipse( gdImage, 20, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 20, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 20, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 60, 20, 20, red );            
                  gdImageFilledEllipse( gdImage, 60, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 100, 20, 20, red );break;
                 
         case 5 : gdImageFilledEllipse( gdImage, 20, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 20, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 20, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 20, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 100, 20, 20, red );break;
                 
         case 6 : gdImageFilledEllipse( gdImage, 20, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 20, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 20, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 20, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 20, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 100, 20, 20, red );break;
                 
         case 7 : gdImageFilledEllipse( gdImage, 20, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 100, 20, 20, red );break;
                 
         case 8 : gdImageFilledEllipse( gdImage, 20, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 20, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 20, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 20, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 20, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 100, 20, 20, red );break;
                 
         case 9 : gdImageFilledEllipse( gdImage, 20, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 20, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 20, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 20, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 40, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 60, 100, 20, 20, red );break;           
                 
        }                 
                        
                 
    switch (b)
       {
          case 0 : gdImageFilledEllipse( gdImage, 100, 20, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 120, 20, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 140, 20, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 100, 40, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 140, 40, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 100, 60, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 140, 60, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 100, 80, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 140, 80, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 100, 100, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 120, 100, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 140, 100, 20, 20, red );break;
                  
          case 1 : gdImageFilledEllipse( gdImage, 120, 20, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 120, 40, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 120, 60, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 120, 80, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 120, 100, 20, 20, red );break;
                  
          case 2 : gdImageFilledEllipse( gdImage, 100, 20, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 120, 20, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 140, 20, 20, 20, red );      
                   gdImageFilledEllipse( gdImage, 140, 40, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 100, 60, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 120, 60, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 140, 60, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 100, 80, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 100, 100, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 120, 100, 20, 20, red );
                   gdImageFilledEllipse( gdImage, 140, 100, 20, 20, red );break;
                  
         case 3 : gdImageFilledEllipse( gdImage, 100, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 120, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 20, 20, 20, red );      
                  gdImageFilledEllipse( gdImage, 140, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 100, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 120, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 100, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 120, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 100, 20, 20, red );break;
         
        case 4 :  gdImageFilledEllipse( gdImage, 100, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 100, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 100, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 120, 60, 20, 20, red );            
                  gdImageFilledEllipse( gdImage, 140, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 100, 20, 20, red );break;
                 
         case 5 : gdImageFilledEllipse( gdImage, 100, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 120, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 100, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 100, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 120, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 100, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 120, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 100, 20, 20, red );break;
                 
         case 6 : gdImageFilledEllipse( gdImage, 100, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 120, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 100, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 100, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 120, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 100, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 100, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 120, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 100, 20, 20, red );break;
                 
         case 7 : gdImageFilledEllipse( gdImage, 100, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 120, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 100, 20, 20, red );break;                                                   
                  
         case 8 : gdImageFilledEllipse( gdImage, 100, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 120, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 100, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 100, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 120, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 100, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 100, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 120, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 100, 20, 20, red );break;
                 
         case 9 : gdImageFilledEllipse( gdImage, 100, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 120, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 100, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 100, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 120, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 100, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 120, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 140, 100, 20, 20, red );break;
                           
       }
2012-03-16 05:48
zfm0210
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2011-11-18
收藏
得分:0 
switch (c)
      {     
        case 0 : gdImageFilledEllipse( gdImage, 180, 20, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 200, 20, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 220, 20, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 180, 40, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 220, 40, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 180, 60, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 220, 60, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 180, 80, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 220, 80, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 180, 100, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 200, 100, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 220, 100, 20, 20, red );break;
                 
         case 1 : gdImageFilledEllipse( gdImage, 200, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 100, 20, 20, red );break;   
                 
         case 2 : gdImageFilledEllipse( gdImage, 180, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 20, 20, 20, red );      
                  gdImageFilledEllipse( gdImage, 220, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 180, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 180, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 180, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 100, 20, 20, red );break;
                 
         case 3 : gdImageFilledEllipse( gdImage, 180, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 20, 20, 20, red );      
                  gdImageFilledEllipse( gdImage, 220, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 180, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 180, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 100, 20, 20, red );break;
                 
         case 4 : gdImageFilledEllipse( gdImage, 180, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 180, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 180, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 60, 20, 20, red );            
                  gdImageFilledEllipse( gdImage, 220, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 100, 20, 20, red );break;
                 
         case 5 : gdImageFilledEllipse( gdImage, 180, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 180, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 180, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 180, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 100, 20, 20, red );break;
                 
         case 6 : gdImageFilledEllipse( gdImage, 180, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 180, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 180, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 180, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 180, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 100, 20, 20, red );break;
                 
         case 7 : gdImageFilledEllipse( gdImage, 180, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 100, 20, 20, red );break;
                 
         case 8 : gdImageFilledEllipse( gdImage, 180, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 180, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 180, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 180, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 180, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 100, 20, 20, red );break;
                 
         case 9 : gdImageFilledEllipse( gdImage, 180, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 180, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 180, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 180, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 200, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 220, 100, 20, 20, red );break;
                 
      }
                                                                                                            
    switch (d)
      {
        case 0 : gdImageFilledEllipse( gdImage, 260, 20, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 280, 20, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 300, 20, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 260, 40, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 300, 40, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 260, 60, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 300, 60, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 260, 80, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 300, 80, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 260, 100, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 280, 100, 20, 20, red );
                 gdImageFilledEllipse( gdImage, 300, 100, 20, 20, red );break;
                 
         case 1 : gdImageFilledEllipse( gdImage, 280, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 100, 20, 20, red );break;     
                 
         case 2 : gdImageFilledEllipse( gdImage, 260, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 20, 20, 20, red );      
                  gdImageFilledEllipse( gdImage, 300, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 260, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 260, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 260, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 100, 20, 20, red );break;   
                 
         case 3 : gdImageFilledEllipse( gdImage, 260, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 20, 20, 20, red );      
                  gdImageFilledEllipse( gdImage, 300, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 260, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 260, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 100, 20, 20, red );break;
                 
         case 4 : gdImageFilledEllipse( gdImage, 260, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 260, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 260, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 60, 20, 20, red );            
                  gdImageFilledEllipse( gdImage, 300, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 100, 20, 20, red );break;
                 
         case 5 : gdImageFilledEllipse( gdImage, 260, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 260, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 260, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 260, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 100, 20, 20, red );break;
                 
         case 6 : gdImageFilledEllipse( gdImage, 260, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 260, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 260, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 260, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 260, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 100, 20, 20, red );break;   
                 
         case 7 : gdImageFilledEllipse( gdImage, 260, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 100, 20, 20, red );break;     
                 
         case 8 : gdImageFilledEllipse( gdImage, 260, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 260, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 260, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 260, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 260, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 100, 20, 20, red );break;   
                 
         case 9 : gdImageFilledEllipse( gdImage, 260, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 20, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 260, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 40, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 260, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 60, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 80, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 260, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 280, 100, 20, 20, red );
                  gdImageFilledEllipse( gdImage, 300, 100, 20, 20, red );break;         
                                                                     
       }
                  
   
  jpgFile = fopen( "test.jpg", "wb" );
  gdImageJpeg( gdImage, jpgFile, -1 );
 
 
  fclose( jpgFile );
 
    gdImageDestroy(gdImage);
} [/code]
2012-03-16 05:48
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
你这样写就成死代码了,没有变化性。

授人以渔,不授人以鱼。
2012-03-16 12:44
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
要输出成图片是吧,我把程序整理好一点再发给你看看。

授人以渔,不授人以鱼。
2012-03-16 15:33
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
test_GDI.exe.zip (9 KB)


代码只供参考,不作实现:

程序代码:
#include <Windows.h>
#include <bitset>
#include "Screen.h"

class LED
{
private:

    static const int Width = 4;                                 // 字模宽度
    static const int Height = 5;                                // 字模高度
    static const int Characters = 10;                           // 字模数目
    static const UCHAR FontImage[Characters][Height];           // 字模数据

    HPEN hPen;
    HBRUSH hBrush;

public:

    // 面板数据结构
    static struct Panel_t
    {
        USHORT Top;             // 顶部位置
        USHORT Left;            // 左边位置
        USHORT Width;           // 宽度
        USHORT Height;          // 高度
        USHORT DotSize;         // 点规模(每个点的直径)
        COLORREF Color;         // 面板颜色
    };
    struct Panel_t Panel;

    COLORREF ForeColor;         // 文字颜色
    COLORREF BackColor;         // 文字背景色

    VOID ShowPanel(HDC& hDC);
    VOID ShowText(HDC& hDC, CHAR* Text, USHORT x, USHORT y);
    VOID ShowText(HDC& hDC, CHAR Ch, USHORT x, USHORT y);

    ~LED()
    {
        DeleteObject(hBrush);
        DeleteObject(hBrush);
    }
};

const UCHAR LED::FontImage[Characters][Height] =
{
    { 0x0E, 0x0A, 0x0A, 0x0A, 0x0E },
    { 0x04, 0x04, 0x04, 0x04, 0x04 },
    { 0x0E, 0x02, 0x0E, 0x08, 0x0E },
    { 0x0E, 0x02, 0x0E, 0x02, 0x0E },
    { 0x0A, 0x0A, 0x0E, 0x02, 0x02 },
    { 0x0E, 0x08, 0x0E, 0x02, 0x0E },
    { 0x0E, 0x08, 0x0E, 0x0A, 0x0E },
    { 0x0E, 0x02, 0x02, 0x02, 0x02 },
    { 0x0E, 0x0A, 0x0E, 0x0A, 0x0E },
    { 0x0E, 0x0A, 0x0E, 0x02, 0x0E }
};

VOID LED::ShowPanel(HDC& hDC)
{
    hPen = CreatePen(PS_SOLID, 1, Panel.Color);
    hBrush = CreateSolidBrush(Panel.Color);
    SelectObject(hDC, hPen);
    SelectObject(hDC, hBrush);
    Rectangle(hDC, Panel.Left, Panel.Top, Panel.Left + Panel.Width, Panel.Top + Panel.Height);
}

VOID LED::ShowText(HDC& hDC, CHAR* Text, USHORT x, USHORT y)
{
    while (*Text)
    {
        ShowText(hDC, *Text++, x, y);
        x += Width * Panel.DotSize;
    }
}

VOID LED::ShowText(HDC& hDC, CHAR Ch, USHORT x, USHORT y)
{
    int x1(x);
    int y1(y);
    int x2(x + Panel.DotSize);
    int y2(y1 + Panel.DotSize);

    for (SHORT row = 0; row <= Height - 1; row++)
    {
        for (SHORT col = Width - 1; col >= 0; col--)
        {
            std::bitset<Width> b(FontImage[Ch - '0'][row]);
            if (b.test(col))
            {
                hPen = CreatePen(PS_SOLID, 1, ForeColor);
                hBrush = CreateSolidBrush(ForeColor);
            }
            else
            {
                hPen = CreatePen(PS_SOLID, 1, BackColor);
                hBrush = CreateSolidBrush(BackColor);
            }
            SelectObject(hDC, hPen);
            SelectObject(hDC, hBrush);
            Ellipse(hDC, x1, y1, x2, y2);
            x1 += Panel.DotSize;
            x2 += Panel.DotSize;
        }
        x1 = x;
        x2 = x + Panel.DotSize;
        y1 = y2;
        y2 += Panel.DotSize;
    }
}

// 程序入口
int wmain(void)
{
    HDC hDC = GetDC(GetConsoleWindow());            // 取控制台窗口为绘图设备
   
    LED theLED;
    theLED.Panel.DotSize = 20;
    theLED.Panel.Top = 10;
    theLED.Panel.Left = 50;
    theLED.Panel.Width = 340;
    theLED.Panel.Height = 120;
    theLED.Panel.Color = RGB(0,255,0);
    theLED.ForeColor = RGB(255,0,0);
    theLED.BackColor = theLED.Panel.Color;

    const WCHAR Tips[] = L"Space: 翻转颜色   Esc: 结束程序";
    RECT Rect;
    Rect.top = theLED.Panel.Top + theLED.Panel.Height + 10;
    Rect.left = theLED.Panel.Left;
    Rect.bottom = Rect.top + 20;
    Rect.right = theLED.Panel.Left + theLED.Panel.Width;
    SetBkColor(hDC, TRANSPARENT);
    SetTextColor(hDC, RGB(255,255,255));
    DrawTextW(hDC, Tips, _countof(Tips) - 1, &Rect, DT_CENTER);

    Screen screen;
    screen.SetCursorVisible(false);
    bool Finish(false);
    while (!Finish)
    {
        theLED.ShowPanel(hDC);
        theLED.ShowText(hDC, "1290", theLED.Panel.Left + 10, theLED.Panel.Top + 10);
        WCHAR Key = screen.ReadKey();
        switch (Key)
        {
            case Screen::K_SPACE:
                if (theLED.Panel.Color != RGB(0,255,0))
                {
                    theLED.Panel.Color = RGB(0,255,0);
                    theLED.ForeColor = RGB(255,0,0);
                }
                else
                {
                    theLED.Panel.Color = RGB(255,0,0);
                    theLED.ForeColor = RGB(0,255,0);
                }
                theLED.BackColor = theLED.Panel.Color;
                break;
            case Screen::K_ESC:
                Finish = true;
                break;
        }
    }
    screen.SetCursorVisible(true);

    ReleaseDC(NULL, hDC);                           // 释放绘图资源

    return EXIT_SUCCESS;
}


[ 本帖最后由 TonyDeng 于 2012-3-16 19:34 编辑 ]

授人以渔,不授人以鱼。
2012-03-16 19:32
快速回复:求高人指教,GD与数组结合的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036260 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved