<%@ Import Namespace="System.Drawing" %> <%@ Import Namespace="System.Drawing.Imaging" %> <%@ Page Language="C#" Debug="true" %> <script runat="server"> void Page_Load(object sender, EventArgs e) { int intWidth = 0; int intHeight = 0; string FileName = null; intWidth = 400; intHeight = 200; FileName = "MyImages/Images.jpg"; Bitmap objBitmap = new Bitmap(intWidth, intHeight); Graphics objGraphic = Graphics.FromImage(objBitmap); objGraphic.FillRectangle(Brushes.Maroon, 0, 0, intWidth, intHeight); //*** Save As ***// objBitmap.Save(Server.MapPath(FileName), ImageFormat.Jpeg); //*** Close ***// objGraphic.Dispose(); //*** Nothing ***// objBitmap = null; objGraphic = null; //*** View Images ***// this.imgPicture.ImageUrl = FileName; } </script> <html> <head> <title>ThaiCreate.Com ASP.NET - Images (System.Drawing)</title> </head> <body> <form id="form1" runat="server"> <asp:Image id="imgPicture" runat="server" /> </form> </body> </html> </form>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท