使用ASP.NET动态生成图片

ASP.NET动态生成图片


using  System;
using  System.Collections;
using  System.ComponentModel;
using  System.Data;
using  System.Drawing;
using  System.Drawing.Imaging;
using  System.Web;
using  System.Web.SessionState;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.HtmlControls;

namespace  Birdshome
{
    
/// <summary>
    
/// Summary description for _Default.
    
/// </summary>

    public class _Default : System.Web.UI.Page
    
{
        
int m_Unit = 3;

        
private void Page_Load(object sender, System.EventArgs e)
        
{
            
// Put user code to initialize the page here
            int counter_width = 32/8;
            
int counter_height =16;
            Bitmap bmp 
= new Bitmap(counter_width*m_Unit*8, counter_height*m_Unit);
            GenerateBitmap(bmp);
            Response.Clear();
            Response.ContentType 
= "image/jpeg";
               bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
        }


        
Web Form Designer generated code

        
private void GenerateBitmap(Bitmap bmp)
        
{
            
//#define counter_width 32
            
//#define counter_height 16
            int counter_width = 32/8;
            
int counter_height =16;
            
byte [] counter_bits = new byte[]
            
{
                
0x000x000x000x00,  0x000x000x000x00
                
0x000x000x000x00,  0x000x000x000x00
                
0x000x000x000x00,  0x000x000x000x00
                
0x3E0x1C0x7F0x7F,  0x630x060x030x03
                
0x600x030x030x03,  0x600x030x030x03
                
0x3C0x3F0x3F0x3F,  0x600x630x600x60
                
0x600x630x600x60,  0x600x630x600x60
                
0x630x630x630x63,  0x3E0x3E0x3E0x3E
            }
;
            Graphics g 
= Graphics.FromImage(bmp);
            
forint i=0 ; i < counter_height ; i++ )
            
{
                
forint j=0 ; j < counter_width ; j++ )
                
{
                    
byte by = counter_bits[counter_width*i+j];
                    
forint k=0 ; k < 8 ; k++ )
                    
{
                        
byte bit = 0;
                        bit 
= (byte)(by & 0x01);
                        Rectangle rect 
= new Rectangle(k*m_Unit+j*8*m_Unit, i*m_Unit, m_Unit, m_Unit);
                        Brush brush;

                        
if( bit == 0x01 )
                        
{
                            brush 
= Brushes.Yellow;
                        }

                        
else
                        
{
                            brush 
= Brushes.Blue;
                        }

                        g.FillRectangle(brush, rect);
                        by 
= (byte)(by >> 1);
                    }

                }

            }

        }

    }

}

 完
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值