Avatar of SilverDemetrio
SilverDemetrio
 asked on

Como puedo conocer el Height y el Width de una imagen dinamicamente en Asp.Net? En javascript si la puedo obtener, pero no se como pasar el contenido de variables de Javascript a Asp.Net.

Saludos !  Me podrian ayudar en Como puedo conocer  el Height y el Width de una imagen dinamicamente en Asp.Net? En javascript si la puedo obtener, pero no se como pasar el contenido de variables de Javascript a Asp.Net. Lo requiero ya que estoy presentando imagenes en una pagina y necesito sus dimenciones para reducirla segun mi frame en la pagina sin que se distorcione la imagen.
Gracias!

Silverio
.NET ProgrammingJavaScript

Avatar of undefined
Last Comment
abel

8/22/2022 - Mon
abel

eh... translation?
jdcomp

He needs to know how he can figure out the height and width of an image on ASp.net. He needs to resize according to his frame on his website without distortioning the image on it He know how to do it in jave but can figure out how to move the infor to Asp.net

There I'm almost sure that is what he wants
abel

aha, thanks! Hope the OP doesn't mind an English answer...
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER CERTIFIED SOLUTION
abel

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
abel

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SilverDemetrio

ASKER
Saludos Abel!  
Intente el
 
Abel greetings! It tries
 
<%@ Import Namespace="System.Drawing" %>
 
&..
Image img = Image.FromFile("filename.jpg");
int height = img.Height;
int width = img.Width;
 
Pero no me aceptaba el Image.FromFile&
 
But it did not accept the Image.FromFile to me&
 
Estoy trabajando Sin CodeBehaind.
 
am working Without CodeBehaind.
 
Y buscando en internet encontre un ejemplo con BitMap y que si me daba el height y el Width, pero como lo carga a memoria, no me permite borrarlo posteriormente.
 
Me podrias mandar un mini ejemplo con el Image.FromFile, ya que talvez este si me permita borrar la imagen desde una rutina..
 
And looking for in Internet encontre an example with BitMap and that if it gave height and the Width me, but like it load to memory, does not allow me to erase it later. Podrias to send a mini example to me with the Image.FromFile, since talvez this if it allows me to erase the image from a routine.
 
 
El programa que realice con BitMap es el siguiente:
 
The program that realises with BitMap is the following one:
 
 
<%@ Page Language="VB" %>
 
<%@ Import Namespace="System.Drawing" %>
&.
 
Sub Page_Load(ByVal Source As Object, ByVal E As EventArgs)
 
imgBitmap = New Bitmap(C:\Img\Documentos\50\Img1\50_010.JPG, True)
Me.lblH.Text = imgBitmap.Height.ToString
Me.lblW.Text = imgBitmap.Width.ToString
 
End Sub
 
&&& 
 
Protected Sub imgBtnBorra_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
 
&..
 
'==============================================
Me.Image1.ImageUrl = "C:\Img\Documentos\50\Img1\50_010.JPG"
strPaso = Me.Image1.ImageUrl
imgBitmap = New Bitmap(strPaso, False)
    ( o el  imgBitmap = New Bitmap(strPaso, true)
 
'==============================================
 
File.Delete("C:\Img\Documentos\50\Img1\50_010.JPG")
 
---à>>>> Error:
The process cannot access the file 'C:\Img\Documentos\50\Img1\50_010.JPG' because it is being used by another process.
 
 
End Sub
 
&&&.
 
Error: al momento de Borrar la imagen que se presento en pantalla
 
Error: at the time of Erasing the image that I appear in screen
 
 
The process cannot access the file 'C:\Img\Documentos\50\Img1\50_010.JPG' because it is being used by another process.
 
 
Silverio
SilverDemetrio

ASKER

Saludos nuevamente Abel !
 
Ya encontre el Error, tengo que darle el Dispose inmediatamente de que detecto su Height y Width, y cuando quiera borrar la imagen ya esta libearada.
 
Gracias por tu gran, gran, gran, gran &.. ayuda!!!!
 
Seguimos en contacto ¡
 
Silverio
-------
Greetings again Abel!
Or encontre the Error, I must immediately give the Dispose him of which I detect its Height and Width, and when it wants to erase the image or this libearada.
Thanks for your great, great, great one, great ..... aid!
We follow in contact
Silverio  
SilverDemetrio

ASKER
Greetings again Abel!
With system.drawing is to me a valuable aid for my, which agradesco you, already I could realise a viewfinder of images that queria to do, to visualize and to erase, I could realise and it with your aid.
Thanks for your great, great, great one, great ..... aid!
sincerely!
Silverio
P.D.: It excuses the Translation, since it realises with a Translator. (Yahoo! Babel Fish).
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
abel

> The process cannot access the file 'C:\Img\Documentos\50\Img1\50_010.JPG' because it is being used by another process.
 

Well, I though you only wanted the size of the image. I'm actually quite surprised that the the asp.net process is allowed on the my documents directory, which should not be accessible from the web server user....

Anyway, you can put a Using-block around it and you should be fine, that will have it released automatically.

(If you do not use the using-block, make sure to use img.Close() + img.Dispose() before you are trying to delete it and place that in the finally of your try/catch)



using (Image img = Image.FromFile("test.jpg"))
{
    // get width/height
}  // at end of using-block image is disposed/closed and can be deleted
File.Delete("test.jpg");

Open in new window

abel

Apologies, you use VB. In which case the above code should read:

Using img As System.Drawing.Image = System.Drawing.Image.FromFile("test.jpg")
    ' get width/height '
End Using
' at end of using-block image is disposed/closed and can be deleted'
System.IO.File.Delete("test.jpg")

Open in new window

abel

Note that, when using a Using-block, you do not need to call .Close() and .Dispose() manually.
Your help has saved me hundreds of hours of internet surfing.
fblack61
abel

Ah, I see you graded me already... tx! Glad I could be of some help. Do see my last comments, they may help you out on the locked file.

> P.D.: It excuses the Translation, since it realises with a Translator. (Yahoo! Babel Fish).

no problem, it was a bit hard to read, but I understood the main lines, I think.

-- Abel --