goto2008

GOTO2008

博客园 首页 新随笔 联系 订阅 管理

                
int maxwidth=120;
                
int maxheight=120;
                
string fcolor=colors.SelectedItem.Value;

                
if(myfile.PostedFile!=null)
                
{
                    
if(typeid!=null &&  typeid.ToString()!="")
                    
{
                        HttpPostedFile mfile
=myfile.PostedFile;
                        
if(mfile.ContentLength<0)
                        
{
                            error.InnerHtml
="<img src=img/error.gif> 请输入正确的路径!";
                            
return;
                        }

                        
if(mfile.ContentLength>size)
                        
{
                            error.InnerHtml
="<img src=img/error.gif> 文件太大!请不要超过"+(size/1024).ToString()+"K";
                            
return;
                        }

                        
int myfilesize=mfile.ContentLength;
                        
int filesizes=mfile.ContentLength;
                        
string[] typef=ftype.Split(new char[]{','});
                        
string dot=mfile.FileName.Substring(mfile.FileName.Length-3).ToLower().Replace(",",",");

                        
bool iffile=false;
                        
for(int i=0;i<typef.Length;i++)
                        
{
                            
if(typef.GetValue(i).ToString().ToLower()==dot)
                            
{
                                iffile
=true;
                            }

                        }

                        
if(iffile==false)
                        
{
                            error.InnerHtml
="<img src=img/error.gif> 文件类型不正确!";
                            
return;
                        }

                        
if(dot=="peg")
                        
{
                            dot
="jpeg";
                        }

    
                        
string titles=Server.HtmlEncode(title.Text);
         
                
                        
string now=DateTime.Now.ToString().Replace(":","-").Replace(" ","-");
                        Random dom
=new Random();
                        
string mydon=dom.Next(1000).ToString();
                        
string bigpath="File/"+uid.ToString()+"/bigimg/"+typeid+"-"+now+mydon+"."+dot;
                    
                        
byte[] mFileByte = new Byte[filesizes];
                        mfile.InputStream.Read(mFileByte,
0,filesizes);
                        System.IO.FileStream saveFile 
= new System.IO.FileStream(Server.MapPath(bigpath),System.IO.FileMode.Create);
                        saveFile.Write(mFileByte,
0,mFileByte.Length);
                        saveFile.Close();

                        
string   strFilename;
                        strFilename 
= Server.MapPath(bigpath)  ; 
                        
string smallpath="File/"+uid.ToString()+"/smallimg/"+typeid+"-"+now+mydon+".jpg";
                        System.Drawing.Image img 
= System.Drawing.Image.FromFile(Server.MapPath(bigpath));

                        
int w=img.Width;
                        
int h=img.Height;
                        Double sw
=img.Width;
                        Double sh
=img.Height;
                        
if(w>h)
                        
{
                            
if(w>maxwidth)
                            
{
                                sw
=maxwidth;
                                sh
=Convert.ToDouble(h*maxwidth/w);

                            }

                        }

                        
else   
                        
{
                            
if(h>maxheight)
                            
{
                                sh
=maxheight;
                                sw
=Convert.ToDouble(w*maxheight/h);

                            }

                        }

                     
             
                    
                     
                 


                        
//生成缩略图
                        string file=bigpath; 
                        
string newfile=smallpath; 
                        
string strAdd=fonts.Text; 
                        
int left=Convert.ToInt32(lefts.Text);
                        
int right=Convert.ToInt32(rights.Text);
                        System.Drawing.Image oldimage 
= System.Drawing.Image.FromFile(Server.MapPath(file)); 
                        System.Drawing.Image thumbnailImage 
= 
                            oldimage.GetThumbnailImage(Convert.ToInt32(sw),Convert.ToInt32(sh),
new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero); 
                        Response.Clear(); 
                        Bitmap output
=new Bitmap(thumbnailImage); 
                        Graphics g
=Graphics.FromImage(output); 
                        
if(fcolor=="Green")
                        
{
                            g.DrawString(strAdd,
new Font("Arial"10),new SolidBrush(Color.Green),left,right); 
                        }

                        
else if(fcolor=="Blue")
                        
{
                            g.DrawString(strAdd,
new Font("Arial"10),new SolidBrush(Color.Blue),left,right); 
                        }

                        
else if(fcolor=="Red")
                        
{
                            g.DrawString(strAdd,
new Font("Arial"10),new SolidBrush(Color.Red),left,right); 
                        }

                        
else if(fcolor=="Yellow")
                        
{
                            g.DrawString(strAdd,
new Font("Arial"10),new SolidBrush(Color.Yellow),left,right); 
                        }

                        output.Save(Server.MapPath(newfile),System.Drawing.Imaging.ImageFormat.Jpeg); 

                        
//
posted on 2005-01-09 16:37  GOTO2008  阅读(150)  评论(0)    收藏  举报