| |
|
|
Open Image files through Stream - Aspose.Imaging Demos
|
|
| ASP.NET |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
<%@ Page Title="Load Image Files through File Path : Aspose.Imaging" Language="C#"
MasterPageFile="~/tpl/Demo.Master" AutoEventWireup="true" CodeBehind="Open-files-through-FilePath.aspx.cs"
Inherits="Aspose.Imaging.Demos.Open_files_through_FilePath" %>
<asp:Content ID="Content" ContentPlaceHolderID="MainContent" runat="server">
<table class="componentDescriptionTxt" border="0" cellpadding="0" cellspacing="0"
style="text-align: center; width: 100%; font-family: Arial; font-size: small;">
<tbody>
<tr>
<td style="width: 19; vertical-align: top;">
</td>
<td class="productTitle" style="width: 100%;">
<h2>
Open Image files through Stream - Aspose.Imaging Demos
</h2>
</td>
<td style="width: 19; vertical-align: top;">
</td>
</tr>
</tbody>
</table>
<div style="text-align: left; font-family: Arial; font-size: small;" class="componentDescriptionTxt">
<p>
This online demo demonstrates the ability of <a href="http://www.aspose.com/community/files/51/.net-components/aspose.imaging-for-.net/category1407.aspx">
Aspose.Imaging</a> for .NET to open existing Image files.
</p>
<p>
<b>Note: </b>At the moment, <strong>Aspose.Imaging for .Net</strong> API supports
only Bmp, Jpeg, Gif, Tiff and Png format images while opening.
<br />
<br />
Using the FileUpload control, upload a <strong>Bmp</strong> format file. Click <b>Process</b>
button after selecting any value from the dropdown to rotate the image accordingly.
</p>
<p>
<asp:FileUpload ID="FileUpload1" runat="server" Height="23px" Width="195px" />
<asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Text="Upload File"
Width="100px" />
<br />
<asp:Label ID="lblError" runat="server"></asp:Label>
<br />
<asp:DropDownList ID="ddlRotate" runat="server" Width="195px">
</asp:DropDownList>
<asp:Button ID="btnExecute" runat="server" Text="Process" OnClick="btnExecute_Click"
Width="100px" />
</p>
</div>
</asp:Content>
|
| C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Aspose.Imaging.Demos
{
public partial class Open_files_through_FilePath : System.Web.UI.Page
{
private static string filepath = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Loading dropdownlist with values of RotateFlipType Enum
ddlRotate.DataSource = Enum.GetValues(typeof(Aspose.Imaging.RotateFlipType));
ddlRotate.DataBind();
}
}
protected void btnExecute_Click(object sender, EventArgs e)
{
//Creating an instance of image class and initializing it with the uploaded file through File path
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(filepath))
{
//Rotating the image according to the value selected from dropdownlist
image.RotateFlip((RotateFlipType)Enum.Parse(typeof(RotateFlipType), this.ddlRotate.SelectedValue, true));
}
//Creating an instance of FileInfo and reading the File Path
System.IO.FileInfo file = new System.IO.FileInfo(filepath);
//Checking if File exists
if (file.Exists)
{
//Creating the Response Header
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
Response.End();
}
}
protected void btnUpload_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
try
{
//Check if uploaded file is of supported format
if (System.IO.Path.GetExtension(FileUpload1.FileName).Equals(".bmp", StringComparison.CurrentCultureIgnoreCase))
{
if (FileUpload1.PostedFile.ContentLength < (1024 * 1024) && FileUpload1.PostedFile.ContentLength > 0)
{
filepath = Server.MapPath(this.FileUpload1.FileName);
//Upload image to Server and display file information on Page
this.FileUpload1.PostedFile.SaveAs(MapPath(this.FileUpload1.FileName));
lblError.Text = "File name: " + FileUpload1.PostedFile.FileName + "<br/>" +
FileUpload1.PostedFile.ContentLength + " kb<br/>" + "Content type: " + FileUpload1.PostedFile.ContentType;
lblError.ForeColor = System.Drawing.Color.Black;
}
else
{
lblError.Text = "File size must be between 0 and 1MB";
lblError.ForeColor = System.Drawing.Color.Red;
}
}
else
{
lblError.Text = "Only bmp files are permitted at the moment";
lblError.ForeColor = System.Drawing.Color.Red;
}
}
catch (Exception ex)
{
lblError.Text = "ERROR: " + ex.Message.ToString();
lblError.ForeColor = System.Drawing.Color.Red;
}
else
{
lblError.Text = "You have not specified a file.";
lblError.ForeColor = System.Drawing.Color.Red;
}
}
}
}
|
|
|
|