码迷,mamicode.com
首页 > 其他好文 > 详细

截图Rectangle contructor with double type perameters with Jcrop for crop image

时间:2014-05-09 04:02:32      阅读:335      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   java   tar   ext   

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../js/jquery.min.js"></script>
<script src="../js/jquery.Jcrop.js"></script>
<script type="text/javascript">
    jQuery(function ($) {
        $(‘#imgCrop‘).Jcrop({
            boxWidth: 450,
            boxHeight: 400,
            onSelect: getcroparea, // will tell the coordinates
            minSize: [308, 308],
        });
        function getcroparea(c) {
            jQuery(‘#X‘).val(c.x);
            jQuery(‘#Y‘).val(c.y);
            jQuery(‘#W‘).val(c.w);
            jQuery(‘#H‘).val(c.h);
        };
    });
</script>
<link rel="stylesheet" href="demo_files/main.css" type="text/css" />
<link rel="stylesheet" href="demo_files/demos.css" type="text/css" />
<link rel="stylesheet" href="../css/jquery.Jcrop.css" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <!-- This is the image we‘re attaching Jcrop to -->
  <img src="demo_files/sago.jpg" id="imgCrop" alt="[Jcrop Example]" />
        <asp:Button ID="btnCrop" runat="server" Text="Crop" OnClick="btnCrop_Click" />
    </div>
        <asp:Image ID="imgUpload" runat="server" ImageUrl="demo_files/sago.jpg" />
        <asp:HiddenField ID="X" runat="server" Value="22" />
         <asp:HiddenField ID="Y" runat="server" Value="122" />
         <asp:HiddenField ID="W" runat="server"  Value="212"/>
         <asp:HiddenField ID="H" runat="server" Value="22" />
    </form>
</body>
</html>

 

 protected void btnCrop_Click(object sender, EventArgs e)
    {
         // Crop Image Here & Save
    string fileName = Path.GetFileName(imgUpload.ImageUrl);
    string filePath = Path.Combine(Server.MapPath("~/UploadImages"), fileName);
    string cropFileName = "";
    string cropFilePath = "";
    if (File.Exists(filePath))
    {
        System.Drawing.Image orgImg = System.Drawing.Image.FromFile(filePath);
        Rectangle CropArea = new Rectangle(
            Convert.ToInt32(X.Value),
            Convert.ToInt32(Y.Value),
            Convert.ToInt32(W.Value),
            Convert.ToInt32(H.Value));
        try
        {
            Bitmap bitMap = new Bitmap(CropArea.Width, CropArea.Height);
            using (Graphics g = Graphics.FromImage(bitMap))
            {
                g.DrawImage(orgImg, new Rectangle(0, 0, bitMap.Width, bitMap.Height), CropArea, GraphicsUnit.Pixel);
            }
            cropFileName = "crop_" + fileName;
            cropFilePath = Path.Combine(Server.MapPath("~/UploadImages"), cropFileName);
            bitMap.Save(cropFilePath);
            Response.Redirect("~/UploadImages/" + cropFileName, false);
        }
        catch (Exception ex)
        {
            throw;
        }
    }
    }

 

 

 

Box Sizing Method

http://forums.asp.net/t/1977993.aspx?Input+string+was+not+in+a+correct+format+when+i+upload+an+image

Hope it helps you.

http://forums.asp.net/t/1977993.aspx?Input+string+was+not+in+a+correct+format+when+i+upload+an+image

截图Rectangle contructor with double type perameters with Jcrop for crop image,布布扣,bubuko.com

截图Rectangle contructor with double type perameters with Jcrop for crop image

标签:style   blog   class   java   tar   ext   

原文地址:http://www.cnblogs.com/happy-Chen/p/3716358.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!