CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  C#

用c#如何做二维图像的处理?我只剩下60分了:(

楼主therealseas()2005-06-02 12:44:06 在 .NET技术 / C# 提问

比如,模拟做一个一辆汽车在草原上从东开到西,另外一辆摩托车从西开到东,  
  这样的事情,用c#好实现吗?  
   
  事实上,我要实现的是不止一辆,有很多汽车到处跑,路线由程序确定,就像游戏里面的那种场景一样。用c#做这样的二维编程好做吗?大家多给点意见好吗?这种程序该怎么做呀? 问题点数:0、回复次数:7Top

1 楼lemong(風之影)回复于 2005-06-02 12:52:11 得分 0

实际上就是计算某一时间点上,各个图片的显示位置(汽车实际就是一个图片而已)  
  汽车是一个对象,地图也是一个对象  
  设计路线就是设计汽车相对地图的移动方式Top

2 楼wolfofsky(风之武)回复于 2005-06-02 13:05:43 得分 0

我可以给你个简单例子Top

3 楼therealseas()回复于 2005-06-02 13:11:57 得分 0

那图片怎么处理后才和背景图片融合的好啊?谁有这方面的例子呀?要用C#的例子,别的没有。  
   
    wolfofsky(风之武)   兄弟你的例子给我看一下好吗?Top

4 楼chenzhanyiczy(hi)回复于 2005-06-02 13:21:04 得分 0

用GDI+吧Top

5 楼wolfofsky(风之武)回复于 2005-06-02 14:14:55 得分 0

using   System;  
  using   System.Windows.Forms;  
  using   System.Drawing;  
  using   System.Drawing.Drawing2D;  
  using   System.Drawing.Imaging;  
  using   System.Drawing.Text;  
  using   System.Globalization;  
  using   System.Threading;  
  using   System.Resources;  
  using   System.Reflection;  
  public   class   Form1:System.Windows.Forms.Form  
  {  
  private   int   px,j,x,y,o,h,kx,ky;  
  private   int   mi=0;  
  private   int[]   d,ranx,rany,mxa,mya;  
  private   float   mx;  
  private   float   my;  
  private   float   rx;  
  private   float   ry;  
  private   float   i;  
  private   float   z;  
  private   float   m;  
  private   float   n;  
  private   Graphics   g;  
  private   Image   imageFile;  
  private   System.Windows.Forms.Timer   myTimer;  
  private   System.ComponentModel.Container   components=null;  
  private   ResourceManager   rm;  
  private   StatusBar   statusBar1;  
  private   StatusBarPanel   panel1,panel2;  
  private   PictureBox   picturebox1;  
  private   Random   random1;  
  Pen[]   randompen;  
  public   Form1()  
  {  
  InitializeComponent();  
  }  
  protected   override   void   Dispose(bool   disposing)  
  {  
  if(disposing)  
  {  
  if   (components!=null)    
  {  
  components.Dispose();  
  }  
  }  
  base.Dispose(disposing);  
  }  
  private   void   InitializeComponent()  
  {  
  this.components=new   System.ComponentModel.Container();  
  this.rm=new   ResourceManager("game",this.GetType().Assembly);  
  this.imageFile=Image.FromFile("SampImag.jpg");  
  this.MaximumSize=new   Size(640,480);    
  CreateMyStatusBar();  
  this.SetStyle(ControlStyles.DoubleBuffer|ControlStyles.UserPaint|ControlStyles.AllPaintingInWmPaint,true);  
  this.UpdateStyles();  
  this.Text="This   is   a   small   game";  
  this.ResizeRedraw=true;  
  myTimer   =   new   System.Windows.Forms.Timer(this.components);  
  myTimer.Tick   +=   new   EventHandler(mytick);  
        myTimer.Interval=50;  
  d=new   int[50];  
  randompen=new   Pen[50];  
  ranx=new   int[50];  
  rany=new   int[50];  
  mxa=new   int[10];  
  mya=new   int[10];  
  //   Create   an   empty   MainMenu.  
  MainMenu   mainMenu1   =   new   MainMenu();  
  MenuItem   menuItem1   =   new   MenuItem();  
  MenuItem   menuItem2   =   new   MenuItem();  
  menuItem1.Text   =   ("file");  
  menuItem2.Text   =   ("edit");  
  //   Add   two   MenuItem   objects   to   the   MainMenu.  
  mainMenu1.MenuItems.Add(menuItem1);  
  mainMenu1.MenuItems.Add(menuItem2);  
  MenuItem   submenu11=new   MenuItem("news");  
  MenuItem   submenu12=new   MenuItem("open");  
  MenuItem   submenu13=new   MenuItem("save");  
  MenuItem   submenu14=new   MenuItem("quit");  
  menuItem1.MenuItems.Add(submenu11);  
  menuItem1.MenuItems.Add(submenu12);  
  menuItem1.MenuItems.Add(submenu13);  
  menuItem1.MenuItems.Add(submenu14);  
  submenu11.Click+=new   System.EventHandler(this.newclick);  
  submenu14.Click+=new   System.EventHandler(this.quitclick);  
  //Bind   the   MainMenu   to   Form1.  
  this.Menu   =   mainMenu1;  
  this.picturebox1=new   PictureBox();  
  this.picturebox1.Width=this.ClientSize.Width;  
  this.picturebox1.Height=this.ClientSize.Height-statusBar1.Height;  
  this.picturebox1.SizeMode=PictureBoxSizeMode.StretchImage;  
  this.picturebox1.BackColor=Color.Black;  
  this.picturebox1.MouseDown+=new   System.Windows.Forms.MouseEventHandler(this.formmousedown);  
  this.picturebox1.MouseMove+=new   MouseEventHandler(this.mousemove);  
  this.picturebox1.MouseLeave+=new   EventHandler(this.mouseleave);  
  this.picturebox1.Anchor=(AnchorStyles.Bottom|AnchorStyles.Right|AnchorStyles.Top|AnchorStyles.Left);  
  this.picturebox1.Paint+=new   PaintEventHandler(this.picturebox1paint);  
  this.picturebox1.MouseEnter+=new   EventHandler(this.mouseenter);  
  //this.picturebox1.Image=imageFile;  
  this.Controls.Add(this.picturebox1);  
  random1=new   Random();  
   
  }  
  public   void   mousemove(object   sender,MouseEventArgs   e)  
  {  
  x=e.X;  
  y=e.Y;  
  }  
  public   void   mouseleave(object   sender,EventArgs   e)  
  {  
  o=1;  
  }  
  public   void   mouseenter(object   sender,EventArgs   e)  
  {  
  if(j==2)  
  {  
  o=2;  
  }else  
  {  
  o=1;  
  }  
  }  
  protected   override   void   OnResize(EventArgs   e)  
  {  
  if(this.WindowState==FormWindowState.Maximized)  
  this.statusBar1.SizingGrip=false;  
  else   this.statusBar1.SizingGrip=true;  
  base.OnResize(e);  
  }  
  private   void   CreateMyStatusBar()  
  {  
  //   Create   a   StatusBar   control.  
  statusBar1   =   new   StatusBar();  
  statusBar1.Height=18;  
  //   Create   two   StatusBarPanel   objects   to   display   in   the   StatusBar.  
  panel1   =   new   StatusBarPanel();  
  panel2   =   new   StatusBarPanel();  
   
  //   Display   the   first   panel   with   a   sunken   border   style.  
  panel1.BorderStyle   =   StatusBarPanelBorderStyle.Sunken;  
  //   Initialize   the   text   of   the   panel.  
  panel1.Text   ="wait";  
  //   Set   the   AutoSize   property   to   use   all   remaining   space   on   the   StatusBar.  
  panel1.AutoSize   =   StatusBarPanelAutoSize.Spring;  
  //   Display   the   second   panel   with   a   raised   border   style.  
  //panel2.BorderStyle   =   StatusBarPanelBorderStyle.Raised;  
  //   Create   ToolTip   text   that   displays   the   current   time.  
  panel2.ToolTipText   =   System.DateTime.Now.ToShortTimeString();  
  //   Set   the   text   of   the   panel   to   the   current   date.  
  panel2.Text   =   System.DateTime.Today.ToLongDateString();  
  //   Set   the   AutoSize   property   to   size   the   panel   to   the   size   of   the   contents.  
  panel2.AutoSize   =   StatusBarPanelAutoSize.Contents;  
                                   
  //   Display   panels   in   the   StatusBar   control.  
  statusBar1.ShowPanels   =   true;  
   
  //   Add   both   panels   to   the   StatusBarPanelCollection   of   the   StatusBar.                          
  statusBar1.Panels.Add(panel1);  
  statusBar1.Panels.Add(panel2);  
   
  //   Add   the   StatusBar   to   the   form.  
  this.Controls.Add(statusBar1);  
  }  
   
  public   void   formmousedown(object   sender,MouseEventArgs   e)  
  {  
  kx=e.X;  
  ky=e.Y;  
      if(px!=0)  
  {  
  for(int   k=0;k<10;k++)  
  {  
  mxa[k]=x;  
  mya[k]=y;  
  }  
          i=1;  
  j=2;  
  o=2;  
  h=2;  
      float   sx;  
      float   sy;  
          sx=e.X-mx;  
        sy=e.Y-my;  
        rx=mx;  
        ry=my;  
        z=(float)Math.Sqrt(sx*sx+sy*sy);  
        m=sx/z;  
        n=sy/z;  
  panel1.Text=("run");  
          myTimer.Start();  
  }  
  }  
  Top

6 楼wolfofsky(风之武)回复于 2005-06-02 14:15:15 得分 0

private   void   newclick(object   sender,EventArgs   e)  
  {    
  myTimer.Enabled=false;  
  i=1;  
  m=1/(float)Math.Sqrt(2);  
  n=m;  
      mx=20;  
      my=20;  
  rx=20;  
  ry=20;  
  px=1;  
  j=1;  
  h=1;  
  o=1;  
  for(int   c=1;c<50;c++)  
  d[c]=50;  
  panel1.Text=("ready");  
  this.picturebox1.Invalidate();  
  }  
  private   void   quitclick(object   sender,EventArgs   e)  
  {  
  this.Close();  
  }  
  private   void   mytick(object   sender,EventArgs   e)  
  {  
  //this.picturebox1.Invalidate(new   Region(new   RectangleF(mx-15,my-15,30,30)));  
   
  if(mi<10)  
  {  
  mxa[mi]=x;  
  mya[mi]=y;  
  mi++;  
  }else  
  {  
  mi=0;  
  }  
  this.picturebox1.Invalidate();  
  if(i<=z)  
  {  
  mx=rx+i*m;  
  my=ry+i*n;  
  i=i+1;  
  }else  
  {  
  //myTimer.Stop();  
  panel1.Text=("ready");  
  }  
  panel2.ToolTipText   =   System.DateTime.Now.ToShortTimeString();  
  this.picturebox1.Update();  
  }  
  protected   void   picturebox1paint(Object   sender,PaintEventArgs   e)  
  {  
  //画背景  
  e.Graphics.DrawImage(imageFile,0,0,this.ClientSize.Width,this.ClientSize.Height-this.statusBar1.Height);  
  g=e.Graphics;  
  g.SmoothingMode=SmoothingMode.AntiAlias;  
  Pen   redPen=new   Pen(Color.Red,2);  
  Pen   greenpen=new   Pen(Color.Green,2);  
  if(px!=0)  
        {              
  //if(i<=z)  
  //{  
  //g.Clear(Color.Black);  
  if(o==2)  
  {  
  for(int   ji=0;ji<10;ji++)  
  g.FillEllipse(new   SolidBrush(Color.FromArgb(random1.Next(255),random1.Next(255),random1.Next(255))),mxa[ji],mya[ji],4,4);  
  }  
  g.DrawEllipse(redPen,mx-10,my-10,20,20);  
  g.DrawLine(redPen,mx,my,mx+m*13,my+n*13);  
  if(j==2)  
  for(int   i=1;i<=20;i++)  
  {  
  paintcircle(g,i);  
  }  
  if(h==2)  
  {  
  g.DrawEllipse(greenpen,kx-2,ky-2,4,4);  
  }  
          //}else  
          //{  
          // myTimer.Stop();  
          // g.DrawEllipse(redPen,mx-10,my-10,20,20);  
  // g.DrawLine(redPen,mx,my,mx+m*13,my+n*13);  
          //}  
  }  
  }  
  void   paintcircle(Graphics   pc,int   di)  
  {  
  if(d[di]>20)  
  {  
  randompen[di]=new   Pen(Color.FromArgb(random1.Next(255),random1.Next(255),random1.Next(255)),2);  
  ranx[di]=random1.Next(this.picturebox1.ClientSize.Width);  
  rany[di]=random1.Next(this.picturebox1.ClientSize.Height);  
  if(random1.Next(1,10)>5)  
  d[di]=1;  
  }else  
  {  
  d[di]++;  
  pc.DrawEllipse(randompen[di],ranx[di]-d[di],rany[di]-d[di],d[di]*2,d[di]*2);  
  }  
   
  }  
  [STAThread]  
  static   void   Main(string[]   args)  
  {  
  Application.Run(new   Form1());  
  }  
  }Top

7 楼cerwg()回复于 2005-06-02 15:24:29 得分 0

markTop

相关问题

  • C++图像处理
  • 一个C#二维数组问题
  • 一维图像数组转换二维图像数组的问题
  • 如何把二维数组pBuffer以图像的形式快速显示出来?
  • 在C++中返回二维数组,怎么老是出错?
  • 手头上没有C的书,如何定义二维数组?
  • c++中如何传递二维数组,函数接口?
  • c中怎样动态定义二维数组?谢谢
  • c++中二维动态数组的定义方法求教!!
  • 如何在c++中进行二维数组的随机赋值

关键词

  • c#
  • menuitems
  • picturebox
  • statusbar
  • panel
  • submenu
  • mainmenu
  • rany
  • randompen
  • ranx

得分解答快速导航

  • 帖主:therealseas

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo