图片RotateFlip ASP.NET C# [英] Image RotateFlip ASP.NET C#

查看:63
本文介绍了图片RotateFlip ASP.NET C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第五天尝试在我的Web应用程序ASP.NET中旋转图像,互联网上的所有解决方案都不适合我。



这个是我在.aspx.cs中的代码



This is my fifth day trying to Rotate Image in my Web Application ASP.NET, all the solutions in the internet didn't work with me.

This is my code in .aspx.cs

protected void BtnRotateImage_Click(object sender, EventArgs e)
    {
        string vImageName = LblFarmId.Text;

        string vPath = "~/attachments/survey/" + vImageName + ".jpg";

        Image1.ImageUrl = vPath;

        //get the path to the image
        string path = Server.MapPath(vPath);

        //create an image object from the image in that path
        System.Drawing.Image img = System.Drawing.Image.FromFile(path);

        //rotate the image
        img.RotateFlip(RotateFlipType.Rotate90FlipXY);

        //save the image out to the file
        img.Save(path);

        //release image file
        img.Dispose();

    }





在.aspx页面





In .aspx page

<asp:Image ID="Image1" runat="server" ImageUrl=""  width="600" height="800"/>





我点击按钮,没有任何反应,图像不会旋转。



我的代码有什么问题吗?



I click on the button, nothing happen , the image doesn't rotate.

is there any wrong in my code?

推荐答案

你的代码没有错;你只是不刷新页面。好吧,在某些情况下,您可以更改图像并保存。但是现在,从逻辑上思考:你的客户端,网络浏览器如何知道图像被修改了?



参见:

如何从代码重新加载页面在母版页后面 [ ^ ],

http://www.c-sharpcorner.com/UploadFile/8911c4/auto-refresh-or-reload-page-in-Asp-Net [ ^ ]。



-SA
Nothing's wrong with your code; you just don't refresh the page. All right, on some event, you change the image and save it. But now, think logically: how your client side, a Web browser, "knows" that the image is modified?

See also:
How to reload the page from code behind of the master page[^],
http://www.c-sharpcorner.com/UploadFile/8911c4/auto-refresh-or-reload-page-in-Asp-Net[^].

—SA


这篇关于图片RotateFlip ASP.NET C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆