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

<!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

转载于:https://www.cnblogs.com/happy-Chen/p/3716358.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
假设我们现在有一个图形类,其中包含了三种不同类型的图形:矩形、圆形和三角形。这个类使用一个整型变量来表示图形的类型,我们需要使用Replace Type Code with Classes重构手法来改善这个类的设计。 重构前的代码如下: ```c enum ShapeType { Rectangle, Circle, Triangle }; struct Shape { enum ShapeType type; double width; double height; double radius; double base; double height; }; void drawShape(struct Shape* shape) { switch (shape->type) { case Rectangle: // draw rectangle break; case Circle: // draw circle break; case Triangle: // draw triangle break; } } ``` 重构后的代码如下: ```c struct Shape { double width; double height; double radius; double base; double height; }; struct Rectangle { struct Shape shape; }; struct Circle { struct Shape shape; }; struct Triangle { struct Shape shape; }; void drawShape(struct Shape* shape) { // draw shape } void drawRectangle(struct Rectangle* rectangle) { drawShape(&(rectangle->shape)); } void drawCircle(struct Circle* circle) { drawShape(&(circle->shape)); } void drawTriangle(struct Triangle* triangle) { drawShape(&(triangle->shape)); } ``` 通过Replace Type Code with Classes重构手法,我们将图形类分成了三个子类,分别表示矩形、圆形和三角形,每个子类都包含了一个Shape结构体,用来表示图形的属性。同时,我们将原来的drawShape函数拆分成了三个函数,用来分别绘制不同类型的图形。这样做的好处是,可以使代码更加模块化、易于扩展和维护。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值