4 Replies - 1567 Views - Last Post: 04 March 2013 - 10:00 AM Rate Topic: -----

#1 Pooja Mengaji  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 24-February 13

how to store images in memory when upload button clicked?

Posted 03 March 2013 - 05:24 AM

i hav created a form where there is a button Upload. when user clicks on the button there are multiple images uploaded in the flowlayoutpanel called PhotoGallery wsing openfilediaolgue. what i want is when the user runs the form the uploaded images should be there in the panel. also the path of the image shud appear in the textboxes. in the code below only one textbox appears with a single path. please help
 Private Sub upload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles upload.Click
        PhotoGallery.Visible = True
        Dim OpenFileDialog1 As New OpenFileDialog
        OpenFileDialog1.Filter = "Images (*.BMP;*.JPG;*.GIF,*.PNG,*.TIFF)|*.BMP;*.JPG;*.GIF;*.PNG;*.TIFF|" + "All files (*.*)|*.*"
        OpenFileDialog1.Multiselect = True
        OpenFileDialog1.Title = "Select Photos"
        Dim strm As System.IO.Stream
        Dim tb As New TextBox
        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            For Each file As String In OpenFileDialog1.FileNames
                Dim imageControl As New PictureBox()
                imageControl.Height = 150
                imageControl.Width = 200
                Dim myCallback As New Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)
                Dim myBitmap As New Bitmap(file)
                Dim myThumbnail As Image = myBitmap.GetThumbnailImage(200, 150, myCallback, IntPtr.Zero)
                imageControl.Image = myThumbnail
                'imageControl.
                PhotoGallery.AutoScroll = True
                PhotoGallery.Controls.Add(imageControl)
                strm = OpenFileDialog1.OpenFile()
                'tb.Size.Equals(384, 20)
                tb.Text = OpenFileDialog1.FileName.ToString()
                PhotoGallery.Controls.Add(tb)

            Next
        End If

        Dim MoveLocation As String
        Dim TransferPath = "D:images"
        Dim imgAdres As String
        Dim fileName

        imgAdres = OpenFileDialog1.FileName
        fileName = System.IO.Path.GetFileName(imgAdres)
        MoveLocation = TransferPath + fileName

        If System.IO.File.Exists(imgAdres) = True Then
            If System.IO.File.Exists(MoveLocation) = False Then
                System.IO.File.Move(imgAdres, MoveLocation)
                'AutosizeImage(MoveLocation, PictureBox1)

            End If
        End If
    End Sub

    Public Function ThumbnailCallback() As Boolean
        Return False
    End Function



Is This A Good Question/Topic? 0
  • +

Replies To: how to store images in memory when upload button clicked?

#2 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5677
  • View blog
  • Posts: 12,208
  • Joined: 02-June 10

Re: how to store images in memory when upload button clicked?

Posted 03 March 2013 - 07:38 AM

First - there is no 'uploading' taking place, is there? You aren't uploading the images to a server are you because I don't see any code for that here.

I had to read that description 10 times to even get a hint at what you are really asking about.

Quote

what i want is when the user runs the form the uploaded images should be there in the panel.


Are you saying that you want the selected images to be persistent between launches of the program? You want the user to be able to close the program. Then when the user launches the program again in the future those same images should be re-loaded to the panel automatically. Have I translated your question correctly?
Was This Post Helpful? 0
  • +
  • -

#3 Pooja Mengaji  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 24-February 13

Re: how to store images in memory when upload button clicked?

Posted 03 March 2013 - 08:44 AM

View PosttlhIn`toq, on 03 March 2013 - 07:38 AM, said:

First - there is no 'uploading' taking place, is there? You aren't uploading the images to a server are you because I don't see any code for that here.

I had to read that description 10 times to even get a hint at what you are really asking about.

Quote

what i want is when the user runs the form the uploaded images should be there in the panel.


Are you saying that you want the selected images to be persistent between launches of the program? You want the user to be able to close the program. Then when the user launches the program again in the future those same images should be re-loaded to the panel automatically. Have I translated your question correctly?

yes thats exactly what i want. i hav not uplaoded the images to the server. mine is a desktop application & as im new to vb.net, so dont know to do it. please help
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5677
  • View blog
  • Posts: 12,208
  • Joined: 02-June 10

Re: how to store images in memory when upload button clicked?

Posted 03 March 2013 - 09:04 AM

Quote

How To Store Images In Memory When Upload Button Clicked?


Well, first, your idea that you are to keep these images in memory is way off. You don't store data in memory between instances of your application.

You need to store the paths of the images to a file someplace on the hard drive. Then when the program launches you check that file, read all the paths, load the images.

We have several tutorials on how to save and load settings. In your case those paths are just additional settings.

You also really need to work on breaking down the functions of your program to much smaller methods. Your "upload_click" event is doing MANY things that should be in other methods. You should have seperate methods that do just one thing:
Get filepath
Read image from disc
Add image to panel

You seem to be doing a lot of typing for having no actual plan or program design. I strongly urge you to do a lot more planing before sitting down at the keyboard. There is a link in my signature block for this.

Q: ... save data, save properties, save environmental variables, serialize my data/class?
A:

This post has been edited by tlhIn`toq: 03 March 2013 - 09:05 AM

Was This Post Helpful? 0
  • +
  • -

#5 IronRazer  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 377
  • View blog
  • Posts: 1,098
  • Joined: 01-February 13

Re: how to store images in memory when upload button clicked?

Posted 04 March 2013 - 10:00 AM

Hello Pooja Mengaji,
This may not be exactly what you want but, i put this together to give you an example of how you could do it. It will add a picturbox and a textbox with the picture and filename onto a panel for each picture opened and place it in the flowlayoutpanel. It also saves the pathnames of the pictures in a text file in the apps directory. Every time you open the app it will read the text file and display the pictures in the flowlayoutpanel. To test it make a new form and add 1 new button and 1 new flowlayoutpanel. Then use this code.
Option Explicit On
Option Strict On

Public Class Form1
    Dim mytxtpath As String = My.Application.Info.DirectoryPath & "\Picnames.txt"

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If System.IO.File.Exists(mytxtpath) Then
            Dim strmReader As New System.IO.StreamReader(mytxtpath)
            While Not strmReader.EndOfStream
                Dim picname As String = strmReader.ReadLine
                AddPanelItems(picname)
            End While
            strmReader.Close()
        End If
        FlowLayoutPanel1.AutoScroll = True
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        FlowLayoutPanel1.Visible = True
        Dim OpenFileDialog1 As New OpenFileDialog
        OpenFileDialog1.Filter = "Images (*.BMP;*.JPG;*.GIF,*.PNG,*.TIFF)|*.BMP;*.JPG;*.GIF;*.PNG;*.TIFF|" + "All files (*.*)|*.*"
        OpenFileDialog1.Multiselect = True
        OpenFileDialog1.Title = "Select Photos"

        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            For Each file As String In OpenFileDialog1.FileNames
                AddPanelItems(file)
            Next
            AddNamesToFile(OpenFileDialog1.FileNames)
        End If
    End Sub

    Private Sub AddNamesToFile(ByVal names() As String)
        Dim allnames As String = ""
        Dim strmWriter As New System.IO.StreamWriter(mytxtpath, True)
        For Each picname In names
            strmWriter.Write(picname)
            strmWriter.WriteLine()
        Next
        strmWriter.Close()
    End Sub

    Private Sub AddPanelItems(ByVal picturename As String)
        Dim pnl As New Panel
        pnl.Width = 200
        pnl.Height = 150
        pnl.BackColor = Color.Black

        Dim pb As New PictureBox
        pb.Width = 188
        pb.Height = 115
        pb.Location = New Point(6, 6)
        pb.SizeMode = PictureBoxSizeMode.Zoom
        pb.ImageLocation = picturename
        pb.Parent = pnl

        Dim tb As New TextBox
        tb.Width = 188
        tb.Location = New Point(6, 126)
        tb.Text = picturename
        tb.Parent = pnl

        FlowLayoutPanel1.Controls.Add(pnl)
    End Sub
End Class


This post has been edited by IronRazer: 04 March 2013 - 10:18 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1