asp.Netは画像をアップロードし、サムネイルのコードを同時に生成します

8937 ワード

 
  





<br>  <br>void Page_Load(Object sender, EventArgs e) <br>{ <br>if (!Page.IsPostBack) <br>{ <br>ImgPreview.Visible = false; <br>} <br>} <br>void GetThumbnailImage(int width, int height, string strInfo, int left, int right) <br>{ <br>string file = "Uploads/" + uploadFile.PostedFile.FileName.Substring(uploadFile.PostedFile.FileName.LastIndexOf('\\') + 1); <br>string newfile = "Uploads/" + uploadFile.PostedFile.FileName.Substring(uploadFile.PostedFile.FileName.LastIndexOf('\\') + 1) + ".jpg"; <br>string strAdd = strInfo; <br>System.Drawing.Image oldimage = System.Drawing.Image.FromFile(Server.MapPath(file)); <br>System.Drawing.Image thumbnailImage = <br>oldimage.GetThumbnailImage(width, height, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero); <br>Response.Clear(); <br>Bitmap output = new Bitmap(thumbnailImage); <br>Graphics g = Graphics.FromImage(output); <br>g.DrawString(strAdd, new Font("Courier New", 14), new SolidBrush(Color.Red), left, right); <br>output.Save(Server.MapPath(newfile), System.Drawing.Imaging.ImageFormat.Jpeg); <br>Response.ContentType = "image/gif"; <br>ImgPreview.Visible = true; <br>ImgPreview.ImageUrl = newfile; <br>} <br>bool ThumbnailCallback() <br>{ <br>return true; <br>} <br>void Button_Click(object sender, EventArgs e) <br>{ <br>int width, height, left, right; <br>string strAddInfo = txtAddInfo.Text; <br>width = Int32.Parse(txtWidth.Text); <br>height = Int32.Parse(txtHeight.Text); <br>left = Int32.Parse(txtLeft.Text); <br>right = Int32.Parse(txtRight.Text); <br>if (!(uploadFile.PostedFile.ContentLength > 0)) <br>{ <br>lblErrInfo.Text = " "; <br>} <br>else <br>{ <br>string path = Server.MapPath("./Uploads/" + uploadFile.PostedFile.FileName.Substring(uploadFile.PostedFile.FileName.LastIndexOf('\\') + 1)); <br>if (File.Exists(path)) <br>{ <br>lblErrInfo.Text = " "; <br>} <br>else <br>{ <br>uploadFile.PostedFile.SaveAs(path); <br>GetThumbnailImage(width, height, strAddInfo, left, right); <br>} <br>} <br>} <br>










width:100
height:150



AspxBoy.Com



:left:10
right:135













asp.Net(vbscript)は画像をアップロードし、同時にサムネイルを生成します.
   <br>  Sub UploadFile(sender As Object, e As EventArgs) <br>  If FileUp.PostedFile.ContentLength = 0 Then <br>  FileInfo.Visible = False <br>  Exit Sub <br>  Else <br>  FileInfo.Visible = True <br>  FDisplay1.Visible = True <br>  End If <br>  FSize.Text =" "+ CStr(FileUp.PostedFile.ContentLength/1024)+"KB" <br>  FName.Text = " :"+FileUp.PostedFile.FileName+"<br>"+FName.Text <br>  " <br>  on error resume next <br>  dim myconn as sqlconnection <br>  dim mycomm as sqlcommand <br>  dim sql as string <br>  dim id as integer <br>  Dim image,anewimage As System.Drawing.Image <br>  dim width,height,newwidth,newheight as integer <br>  Dim callb As System.Drawing.Image.GetThumbnailImageAbort <br>  myConn=New sqlconnection(ConfigurationSettings.AppSettings(" ")) <br>  myconn.open() <br>  sql="insert into picture ( , , , ) values (""&request.cookies("dgxyl").values("dgxylname")&"",""&request.cookies("dgxyl").values("dgxylbj")&"",""&trim(request("TextBox1"))&"",""&request("r1")&"")" <br>  Mycomm=New sqlcommand(sql,myconn) <br>  mycomm.executenonquery() <br>  myconn.close() <br>  Dim myCommand As New SqlCommand("select top 1 id from picture order by id desc", myConn) <br>  myCommand.Connection.Open() <br>  Dim myReader As SqlDataReader=mycommand.executereader() <br>  if myReader.Read() then <br>  id=myReader("id") <br>  end if <br>  myconn.close() <br>  " <br>  FileUp.PostedFile.SaveAs( Server.MapPath("\classpic\")&cstr(id)&".jpg" ) <br>  " <br>  image=System.Drawing.Image.FromFile(Server.MapPath("/classpic/"+cstr(id)+".jpg")) <br>  width=image.Width <br>  height=image.height <br>  if width>height then <br>  newwidth=250 <br>  newheight=image.height/image.Width*newwidth <br>  else <br>  newheight=250 <br>  newwidth=image.Width/image.height*newheight <br>  end if <br>  response.write("id="+cstr(id)+"width="+cstr(Width)+";height="+cstr(height)+" ") <br>  response.write("newwidth="+cstr(newwidth)+";newheight="+cstr(newheight)+"<br>") <br>  aNewImage=image.GetThumbnailImage(newwidth,newheight,callb,new System.IntPtr()) <br>  aNewImage.Save(Server.MapPath("/smallpic/"+cstr(id)+".jpg")) <br>  image.Dispose() <br>  Dim FileSplit() As String = Split( FileUp.PostedFile.FileName, "\" ) <br>  Dim FileName As String = FileSplit(FileSplit.Length-1) <br>  Dim Exts() As String = Split( FileName, "." ) <br>  Dim Ext As String = LCase(Exts(Exts.Length-1)) <br>  FDisplay.Text = "<A Target="_blank" HREF="/classpic/"&cstr(id)&".jpg"& ""> </A>" <br>  FDisplay1.text="<a href="/picture/default.asp?bj="&cstr(request.cookies("dgxyl").values("dgxylbj"))&""> </a>" <br>  End Sub <br>  
   <br>  <!-- <br>  var requestsubmitted=false; <br>  function guestbook_Validator(theForm) <br>  { <br>  // <br>  if (requestsubmitted==true){ <br>  alert(" , !"); <br>  return(false); <br>  } <br>  requestsubmitted=true; <br>  return (true); <br>  } <br>  //--> <br>  

  
  

の を しく してください


  

  

  

  

  
  

   :" name="R1" checked> ( , )

   :

  
  

  
  


  

  


  

  


  

      
  1. , !

  2.   
  3. , , !

  4.