none
Image Index runs out of memory RRS feed

  • Question

  • Hi team

    I have Image Slider which load images from Dir and shows them one after the other. Work fine BUT

    I the image Index list keeps running out of memory.

        Private Function GetImagesFromFolder(ByVal path As String) As String()
            Return System.IO.Directory.GetFiles(path)
        End Function

        Private Sub imageSlider1_CanGetNextPrevImage(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.CanGetNextPrevImageEventArgs) Handles ImageSlider1.CanGetNextPrevImage
            Dim editor = TryCast(sender, ImageSlider)
            If e.IsNext Then
                e.CanGetImage = (currentImageIndex < paths.Count - 1 OrElse editor.AllowLooping)
            Else
                e.CanGetImage = (currentImageIndex > 0 OrElse editor.AllowLooping)
            End If
        End Sub

        Private Sub imageSlider1_GetImage(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.GetImageEventArgs) Handles ImageSlider1.GetImage
            If e.IsStartUp Then
                e.Image = Image.FromFile(paths(currentImageIndex))
                Return
            End If
            If e.IsNext Then
                If currentImageIndex = paths.Count - 1 Then
                    currentImageIndex = -1
                End If
                e.Image = Image.FromFile(paths(currentImageIndex + 1))
                If e.CurrentImageUpdated Then
                    currentImageIndex += 1
                End If
            ElseIf e.IsPrev Then
                If currentImageIndex = 0 Then
                    currentImageIndex = paths.Count
                End If
                e.Image = Image.FromFile(paths(currentImageIndex - 1))
                If e.CurrentImageUpdated Then
                    currentImageIndex -= 1
                End If
            End If
            gcCounter += 1
            If gcCounter = 5 Then
                gcCounter = 0
                GC.Collect()
            End If
        End Sub

    Can any help with this

    • Moved by Stanly Fan Thursday, December 7, 2017 5:32 AM 3rd control
    Friday, December 1, 2017 9:22 AM

All replies

  • Hi ronbSA,

    I have never heard about "ImageSlider". Are you using some 3rd party control?

    Regards,

    Ashidacchi

    Monday, December 4, 2017 1:20 AM
  • Hi RonbSA,

    I'm afraid the "Image Slider" is a 3rd control provided by DevExpress, right?

    If so, it will be more appropriate to ask your question at DevExpress support.

    Thank you for your understanding.

    Regards,

    Stanly

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 4, 2017 2:32 AM
  • Hi,

    I have no idea about "ImageSlider", but you need to display/include images in the control after decreasing resolution of the images.
    If you display/include them without decreasing their resolution, they require much memory. 

    (a) display images with decreasing their resolution
    (2) when user select/scroll a specific image, you can read/show its original image from file.

    Regards,

    Ashidacchi

    Monday, December 4, 2017 2:49 AM
  • Hi Stanly

    Thanks for your reply

    Yes it is a DevExpress product BUT I have been through this problem with them and they say is is .NET issue

    So this is why I have come to you.  It will do the same thing if i use a Picture Box.

    So the problem must be with Visual Studio NOT managing the computers Memery

    Regards

    Ron B

    Monday, December 4, 2017 7:01 AM
  • Hi Ron,

    >>It will do the same thing if i use a Picture Box.

    If so, I suggest you to provide a simple demo that can reproduce this issue with Picture Box instead of "Image Slider", and please input your code with the following icon for more convenient to test:

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Edited by Stanly Fan Monday, December 4, 2017 7:47 AM
    Monday, December 4, 2017 7:08 AM
  • Sorry for Delay

    The code page is as follows:

    Imports System.Windows.Forms
    Imports System.IO
    
    Public Class PictureBosDemo
        Dim MyFilePath As String = ""
        Dim Image As Image
        Dim Counter As Integer = 0
        Dim images As String()
    
        Private Sub BtnExit_Click(sender As Object, e As EventArgs) Handles BtnExit.Click
            Close()
        End Sub
    
        Private Sub btnRun_Click(sender As Object, e As EventArgs) Handles btnRun.Click
            moveTimer.Interval = 1000
            ''    moveTimer.Tick += New EventHandler(moveTimer_Tick)
            images = Directory.GetFiles(MyFilePath)
    
    
            MoveTimer.Start()
        End Sub
    
        Private Sub btnSelectPath_Click(sender As Object, e As EventArgs) Handles btnSelectPath.Click
            Dim ofd As New OpenFileDialog
            If ofd.ShowDialog = Windows.Forms.DialogResult.OK AndAlso ofd.FileName <> "" Then
                MyFilePath = Path.GetDirectoryName(ofd.FileName)
                MsgBox("You have Selected this folder = " & MyFilePath)
                If Len(MyFilePath) > 3 Then
                    Me.btnRun.Visible = True
                    Me.lblRun.Visible = True
                    Me.lblPath.Text = MyFilePath
                Else
                    Me.btnRun.Visible = False
                    Me.lblRun.Visible = False
                End If
            End If
    
    
        End Sub
    
        Private Sub PictureBosDemo_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub MoveTimer_Tick(sender As Object, e As EventArgs) Handles MoveTimer.Tick
    
            Image = Image.FromFile(images(Counter))
    
            PictureBox1.Image = Image
            If Counter < images.Count - 1 Then
                Counter = Counter + 1
            Else
                Counter = 0
            End If
    
    
        End Sub
    
    
    
    End Class

    This Demo will run out of Memory which is my problem I am having

    It looks like it will only show 22 Images the Runs out of memory.

    Hope you can Help

    Monday, December 18, 2017 3:19 AM
  • Hi,

    I suppose you need to shrink size of the Image before "PictureBox1.Image = Image".
    Private Sub MoveTimer_Tick(sender ......) Handles MoveTimer.Tick
    Call Me.prc_ShrinkThumnailImage()
    If Counter < images.Count -1 then
    .....
    End If
    End Sub
    ' ---------------------------------------------
    Private Sub prc_ShrinkThumbnailImage() ' -- Thumbnail_Image = System.Drawing.Image
        Dim shrinkImage As System.Drawing.Image = Image.FromFile(images(Counter))
        Dim imageQuality As Single = 0.3

    Dim imgWidth As Integer = shrinkImage.Width
    Dim imgHeight As Integer = shrinkImage.Height
    Dim workImage As System.Drawing.Image
    ' --- when Width or Height of original image is over 768 pixel, shrink it
    If (imgWidth > 768) OrElse (imgHeight > 768) Then
    imgWidth = imgWidth * imageQuality ' -- * 0.3
    imgHeight = imgHeight * imageQuality ' -- * 0.3
    workImage = shrinkImage.GetThumbnailImage _
    (imgWidth, imgHeight, New System.Drawing.Image.GetThumbnailImageAbort(AddressOf dummy), IntPtr.Zero)
    PictureBox1.Image = workImage
    Else
    PictureBox1.Image = shrinkImage
    End If
    End Sub
    The above is a bookish code, not implemented in real project. But my real code is very near to it. 

    Regards,

    Ashidacchi


    • Edited by Ashidacchi Monday, December 18, 2017 4:22 AM
    Monday, December 18, 2017 4:20 AM