Last post Nov 25, 2009 08:15 AM by sandy060583
May 18, 2008 10:02 PM|istakoza|LINK
I am trying to get the image height and width of an image I have obtained from a database and downloaded to an aspx page.
I know I need to use something like:
to declare the image but when I do it this way I get the following error
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust
level in the configuration file.
Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=220.127.116.11, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
So I figured it had somthing to do with not using the physical path.
So I got the physical path like this:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.OutOfMemoryException: Out of memory.
So now I am lost, can anyone in the know help me on this?
May 19, 2008 01:20 AM|avidyarthi|LINK
FileStream fs = new FileStream(MapPath(ImageFolder + "/" + fileName),
FileMode.Open, FileAccess.Read, FileShare.Read);
System.Drawing.Image image = System.Drawing.Image.FromStream(fs)
fileLength = Convert.ToInt32(fs.Length);
fileWidth = image.Width;
fileHeight = image.Height;
Hope this helps.
May 19, 2008 02:18 AM|istakoza|LINK
I am sorry, can you please put that in VB?
May 19, 2008 05:27 AM|istakoza|LINK
Someone please help this is my code how do I get the image height and width so I can resize, also how do I resize??
May 19, 2008 08:28 PM|avidyarthi|LINK
try out the code on this post to resize the image and also to get the width and the height.
also there is a link posted by me in this thread. That might also be helpful to you.
Hope it helps
May 24, 2008 10:19 PM|istakoza|LINK
I got it, but I think I did it the hard way. But if anyone has the same problem, here is the solution I came up with.
'******Connect to the database and bring back the main image Information******
origimage = System.Drawing.Image.FromStream(MainMS)
nPercent = PercentWidth
nPercent = PercentHeight
Image1.Width = origimage.Width * nPercent
Image1.Height = origimage.Height * nPercent
Mar 01, 2009 03:33 AM|mudassarkhan|LINK
Hi Do this way
Nov 17, 2009 07:10 PM|msandfox|LINK
It is actually even simpler than that.
Public Function GetImageWidth(ByVal ImgFile As String) As Integer
Dim newImage As Image = Image.FromFile(ImgFile)
Then simply call the function from the page like so.
<%If GetImageWidth(Server.MapPath("Photos\RSites\" & drRSites.Item("saLogo"))) > 200 Then%>
or in whatever format you may need.
Hope this is useful.
Nov 25, 2009 08:15 AM|sandy060583|LINK