Trang chủĐăng kýĐăng nhập Cộng đồng tin học
Thứ 2, 2024-04-29, 2:21 AM
Khung đăng nhập

Khung tán gẫu
Xóm 'bà Tám'

http://congdongtinhoc.net
CHUYÊN TRANG GAME ONLINE GIẢI TRÍ//lehung-system.ucoz.net/stuff/

Thống kê diễn đàn
Bài viết mới nhất Trang chủ cập nhật Top 10 thành viên tích cực 10 Thành viên mới nhất
  • Quạt Hướng Trục
  • vào ucoz.com thiết kế web không hiểu sao...
  • Sothink DHTMLMenu 9.2 Build 90326
  • cho em quảng cáo cái
  • BIDV triển khai gói 10.000 tỷ đồng cho v...
  • Phượng Đã Nở Ngoài Hiên
  • Ngựa Ô Thương Nhớ
  • Những mẩu chuyện vui
  • 1001 cách biến "sim rác" thành...
  • Windows XP Media Center Edition 2008 - S...
  • Hướng dẫn chỉnh sửa dữ liệu trong form m...
  • 15 điều người dùng máy tính nên biết
  • Choáng vì "sâu" mới phát tán qua email
  • Giấu bớt những thành phần Control Panel ...
  • Thảo luận về IFrame Injection Attacks
  • Miễn phí bản quyền Ashampoo Anti-Malware...
  • Trải nghiệm với Camtasia Studio 7
  • 10 kỹ năng IT ‘hot’ của năm 2011
  • Intel công bố bộ vi xử lý Hệ thống trên ...
  • Kho phần mềm dành cho Android
  • Hung@info
  • thangbom
  • Hung@webmater
  • hebeo
  • giodaingan
  • david15
  • whitecat
  • luutruthongtin
  • systemfan_12
  • sha66b5cates0428
  • amir2x4
  • taiwindows075
  • kholuutru
  • shahmeerolivedigital9
  • ysg06363100
  • hetoxe6474
  • rootanalysisusa
  • memory_gift
  • systemfan_12
  • quatcongnghiep_saigon


  • [ Tổng hợp bài mới · Tổng số thành viên · Nội qui chung · Tìm kiếm bài viết · RSS ]
    • Page 1 of 1
    • 1
    Diễn đàn » Lập Trình » .NET » Asp.net và xoay hình
    Asp.net và xoay hình
    Hung@infoDate: Thứ 2, 2009-05-25, 10:45 PM | Bài viết # 1
    Trung úy
    Nhóm: Quản trị viên
    Bài viết: 994
    Uy tín: 10
    Hiện tại: Offline
    Nếu bạn muốn làm một việc xoay hình thì chúng ta hãy bắt đầu với ví dụ mẫu sau:

    Nội dung
    cấu hình trong web.config như sau :
    <httpHandlers>
    <add verb="*" path="ShowCar.axd" type="ImageHandler.ImageCar" />
    </httpHandlers>

    tạo một file trong app_code để load dữ liệu như sau : imagescar.cs

    Code
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Drawing.Text;
       
    namespace ImageHandler
    {
    /// <summary>
    /// Summary description for ImageCar
    /// </summary>
    ///
    public class ImageCar : IHttpHandler
    {
    public ImageCar()
    {
    //
    // TODO: Add constructor logic here
    //
    }
    public Bitmap RotateBitmap(float Angle, Bitmap bm_in)
    {
    try
    {
    float wid = bm_in.Width;
    float hgt = bm_in.Height;
    Point[] corners = { new Point(0, 0), new Point(int.Parse(wid.ToString()), 0), new Point(0, int.Parse(hgt.ToString())), new Point(int.Parse(wid.ToString()), int.Parse(hgt.ToString())) };
    int cx = int.Parse(wid.ToString()) / 2;
    int cy = int.Parse(hgt.ToString()) / 2;
    long i;
    for (i = 0; i <= 3; i++)
    {
    corners.X -= Convert.ToInt32(cx.ToString());
    corners.Y -= Convert.ToInt32(cy.ToString());
    }
    float theta = (float)(Angle * Math.PI / 180.0);
    float sin_theta = (float)Math.Sin(theta);
    float cos_theta = (float)Math.Cos(theta);
    float X;
    float Y;
    for (i = 0; i <= 3; i++)
    {
    X = corners.X;
    Y = corners.Y;
    corners.X = (int)(X * cos_theta + Y * sin_theta);
    corners.Y = (int)(-X * sin_theta + Y * cos_theta);
    }
    float xmin = corners[0].X;
    float ymin = corners[0].Y;
    for (i = 1; i <= 3; i++)
    {
    if (xmin > corners.X)
    xmin = corners.X;
    if (ymin > corners.Y)
    ymin = corners.Y;
    }
    for (i = 0; i <= 3; i++)
    {
    corners.X -= int.Parse(xmin.ToString());
    corners.Y -= int.Parse(ymin.ToString());
    }
    Bitmap bm_out = new Bitmap((int)(-2 * xmin), (int)(-2 * ymin));
    Graphics gr_out = Graphics.FromImage(bm_out);
    // ERROR: Not supported in C#: ReDimStatement
    Point[] temp = new Point[3];
    if (corners != null)
    {
    Array.Copy(corners, temp, Math.Min(corners.Length, temp.Length));
    }
    corners = temp;
    gr_out.DrawImage(bm_in, corners);
    return bm_out;
    }
    catch (Exception ex)
    {
    string s = ex.Message;
    return bm_in;
    }
    }
    public void ProcessRequest(System.Web.HttpContext context)
    {
    try
    {
    context.Response.ContentType = "image/gif";
    Image origImg = Image.FromFile(context.Server.MapPath("images/car.png"));
    Bitmap bm_in = new Bitmap(origImg);
    string strAngle = context.Request.Params["angle"].ToString();
    Bitmap bmt_dr = RotateBitmap(float.Parse(strAngle), bm_in);
    bmt_dr.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
    //writeImage(context);
    }
    catch (Exception objEx)
    {
    }
    }
    public bool IsReusable
    {
    get
    {
    return true;
    }
    }

    }
    }


    --== Cộng đồng tin học ==--
     
    Diễn đàn » Lập Trình » .NET » Asp.net và xoay hình
    • Page 1 of 1
    • 1
    Search:


      Copyright Cộng đồng tin học © 2024