getting image size next....

K

KarimL

Thanks for your advices...
but i need to get the Image height because i dynamically resize the height
of my webcontrol based on the image height.
More i just have the url (relative parth) to the the image but in design
time mode all variables concerning Server or Context
ar not set ! ...so I can't use MapPath function to obtain the physical
parth of the picture ...

So my second question is how to retrieve the
physical root path of the current application loaded in VS.NET (from
relative path) in Design Mode...

Thanks
Karim
 
H

Hermit Dave

read the image into a memory stream
load it into a System.Drawing.Image object
once you do that you can find the height and width etc of the image

hope this helps
 
M

Michael Ramey

You find the file in windows explorer, right click, properties, and look at
the location? I'm sorry I don't know if I'm understanding you, because
getting the physical path should be a pretty trivial task.

--Michael
 
S

Sam Fields

He's right. He's looking to use a relative path during design time.
Unfortunately, everything I found says .NET neglected to provide design-time
relative path methods / properties. Personally, I ended up writing my own 2
global properties as below.

As for the image size, I can't help you there. System.Drawing.Image sounds
like a good way to start, though.

Hope this helps!
Sam


public static bool DesignMode
{
get
{
return (HttpContext.Current == null);
}
}

public static string ApplicationPath
{
get
{
if (!DesignMode)
{
string currentpath = HttpContext.Current.Request.ApplicationPath;
if (currentpath.Substring(currentpath.Length) != "/") currentpath +=
"/";
return currentpath;
}
else
{
return "file://path to application root/";
}
}
}
 
K

KarimL

yes it could but it's a composite webcontrol
that embeds an image control and on of its properties is the url of the
image...
so at design time it pops the ImageUrlEditor, i keep the resulting string
value in a string and from
this string I try to get the size...
but there's no way to get the image size with this image component... so
other solution is my question below....

Karim
 
M

Michael Ramey

Do you care if at design time you can actually see the image on your
designer? If you don't just put the relative path. It'll probably give you
a big x (or whatever it does), to state it doesn't know where that file is,
but at runtime, you can grap the location, do a server.mappath, and you
should be good to go with getting the image size.
 
H

Hermit Dave

if he's so fixed up on wanting the size... then he should read it into a
stream and load it into System.Drawing,Image
then they can all the data he wants... (considering that the custom control
will be Rendered even in design mode in the application)
 
K

KarimL

Thanks Michael...
but for runtime all variables are instanciated (Server,context...) but my
problem is specific
to design time.... i seek a solution to get the image size :
a global function to translate the relative path to physical path
or
a way to retrieve the current loaded project in the VS.NET and it's
physical root path
.....

Karim
 
K

KarimL

i tested System.Drawing,Image.FromFile(relative_path)
but it doesn't work either...

Karim
 
H

Hermit Dave

well try the physical path.
since your object will be in memory and will be executed even in design
mode, i think you should be able to use
mappath to get the physical path. if not then hard code the application path
(web.config is a good place to start) and then at run time calculate the
exact physical path
 
M

Michael Ramey

Could you write a string function, that takes in an absolute path (the one
you set at design time), hacks it to a relative path, then run
server.mappath() on it?
 
K

KarimL

Yes I could... but this does not satisfies me....
i'm currently diving into VS.NET automation model ... I keep you informed if
i find something..

Karim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top