Topbar
Topbar
Sign in
|
Join
|
Client Center
Home
Products
Client Center
Contact
Purchase
Support forums
»
Products
»
Ajax Uploader
»
Re: Dimensions of uploaded image files
Dimensions of uploaded image files
Last post 09-03-2009, 6:12 AM by
jgra
. 2 replies.
Sort Posts:
Oldest to newest
Newest to oldest
Previous
Next
09-02-2009, 5:08 PM
55321
jgra
Joined on 09-02-2009
Posts 4
Dimensions of uploaded image files
Reply
Quote
Hi
I need to get the dimensions of image files uploaded via the ajaxuploader.
Is there any class that will help me do that?
JG
09-02-2009, 8:39 PM
55325
in reply to
55321
cutechat
Joined on 07-22-2004
Posts 2,332
Re: Dimensions of uploaded image files
Reply
Quote
JG,
Please check this code :
<
%@ Page
Language
=
"C#"
Title
=
"First sample"
%
>
<
%@ Import
Namespace
=
"CuteWebUI"
%
>
<
%@ Register
TagPrefix
=
"CuteWebUI"
Namespace
=
"CuteWebUI"
Assembly
=
"CuteWebUI.AjaxUploader"
%
>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"
>
<
script
runat
=
"server"
>
void InsertMsg(string msg)
{
ListBoxEvents.Items.Insert(0, msg);
ListBoxEvents.SelectedIndex
=
0
;
}
protected void UploadAttachments1_FileUploaded(object sender, UploaderEventArgs args)
{
//must copy the stream to MemoryStream, otherwise the stream may be locked by Image object
byte[]
data
=
new
byte[args.FileSize];
using (Stream
stream
=
args
.OpenStream())
{
stream.Read(data, 0, args.FileSize);
}
System.Drawing.Image
img
=
null
;
try
{
img
=
System
.Drawing.Image.FromStream(new MemoryStream(data));
}
catch
{
}
if (
img
== null)
{
InsertMsg("What you uploaded is not a image");
}
else
{
InsertMsg("You have uploaded a image : " + img.Width + "x" + img.Height);
}
}
</
script
>
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
id
=
"Head1"
runat
=
"server"
>
</
head
>
<
body
>
<
form
id
=
"Form1"
runat
=
"server"
>
<
CuteWebUI:UploadAttachments
runat
=
"server"
ID
=
"UploadAttachments1"
OnFileUploaded
=
"UploadAttachments1_FileUploaded"
>
</
CuteWebUI:UploadAttachments
>
<
br
/>
<
div
>
Server Trace:
<
br
/>
<
asp:ListBox
runat
=
"server"
ID
=
"ListBoxEvents"
Width
=
"800"
>
</
asp:ListBox
>
</
div
>
</
form
>
</
body
>
</
html
>
Regards,
Terry
09-03-2009, 6:12 AM
55345
in reply to
55325
jgra
Joined on 09-02-2009
Posts 4
Re: Dimensions of uploaded image files
Reply
Quote
That'll work!
Thanks
JG