Zum Inhalt springen

Hochgeladenes Bild direkt im Browser anzeigen


Empfohlene Beiträge

Geschrieben

Wenn en bild hochgeladen wird, soll es dem Nutzer direkt im Browser angezeigt werden, wei bewerkstellige ich das am besten??

Ich mein das würd irgendwie so funktionieren:

Upload.PostedFile.InputStream

Bin mir da aber nicht so ganz sicher =)

grüße Horstiii

Geschrieben

Ich komm halt nicht mehr drauf, wie ein Bild welches ich mit hilfe einer upload funktion hochgeladen abe direkt im browerfenster angezeigt wird.

Um das Bild auf der Festplatte zu speichern benutze ich:

Upload.PostedFile.SaveAs(hier pfad eingeben);

nur wie kann ich anstatt das bild auf der festapltte zu speichern, das bild direkt im browser anzeigen lassen??

da komm ich nicht weiter

Geschrieben

Ein Blick in die MSDN hilft: FileUpload.PostedFile-Eigenschaft (System.Web.UI.WebControls)


      Sub DisplayFileContents(ByVal file As HttpPostedFile)


            Dim myStream As System.IO.Stream

            Dim fileLen As Integer

            Dim displayString As String

            Dim loop1 As Integer


            ' Get the length of the file.

            fileLen = FileUpload1.PostedFile.ContentLength


            ' Display the length of the file in a label.

            LengthLabel.Text = "The length of the file is " _

                               + fileLen.ToString + " bytes."


            ' Create a byte array to hold the contents of the file.

            Dim Input(fileLen) As Byte


            ' Initialize the stream to read the uploaded file.

            myStream = FileUpload1.FileContent


            ' Read the file into the byte array.

            myStream.Read(Input, 0, fileLen)


            ' Copy the byte array to a string.

            For Loop1 = 0 To fileLen - 1

                displayString = displayString & Input(loop1).ToString()

            Next Loop1


            ' Display the contents of the file in a 

            ' textbox on the page.

            ContentsLabel.Text = "The contents of the file as bytes:"


            Dim ContentsTextBox As New TextBox

            ContentsTextBox.TextMode = TextBoxMode.MultiLine

            ContentsTextBox.Height = Unit.Pixel(300)

            ContentsTextBox.Width = Unit.Pixel(400)

            ContentsTextBox.Text = displayString


            ' Add the textbox to the Controls collection

            ' of the Placeholder control.

            PlaceHolder1.Controls.Add(ContentsTextBox)


        End Sub


Aufruf:

' Call a helper routine to display the contents

' of the file to upload.

DisplayFileContents(FileUpload1.PostedFile)

Solltest dann entsprechend den Inhalt / Stream in einer PictureBox ausgeben, anstatt wie im Beispiel einer Textbox.

So long,

wos

Geschrieben

Wenn du die Datei eh schon gespeichert hast und sie im Browser anzeigen willst, dann nehm doch den IMG-TAG vom HTML mit dem entsprechenden Pfad. :rolleyes:

Geschrieben
original.Save(Response.OutputStream, ImageFormat.Jpeg);

so klappts, nur wie mache ich das das bild in einer image box angezeigt wird, denn so stehn da nur fragezeichen und so.

Geschrieben

Oben hab ich mich vertan =)

war doch nur save

original is ein bitmap^^

achja, im ie7 funzt das, nur im ff nich =(

muss nurnoch wissen, wie ich das in eine picturebox reinbekommen ;)

Erstelle ein Benutzerkonto oder melde Dich an, um zu kommentieren

Du musst ein Benutzerkonto haben, um einen Kommentar verfassen zu können

Benutzerkonto erstellen

Neues Benutzerkonto für unsere Community erstellen. Es ist einfach!

Neues Benutzerkonto erstellen

Anmelden

Du hast bereits ein Benutzerkonto? Melde Dich hier an.

Jetzt anmelden

Fachinformatiker.de, 2024 by SE Internet Services

fidelogo_small.png

Schicke uns eine Nachricht!

Fachinformatiker.de ist die größte IT-Community
rund um Ausbildung, Job, Weiterbildung für IT-Fachkräfte.

Fachinformatiker.de App

Download on the App Store
Get it on Google Play

Kontakt

Hier werben?
Oder sende eine E-Mail an

Social media u. feeds

Jobboard für Fachinformatiker und IT-Fachkräfte

×
×
  • Neu erstellen...