dispose of images correctly

6 posts, 0 answers
  1. Kevin
    Kevin avatar
    14 posts
    Member since:
    Jul 2012

    Posted 04 Jun 2012 Link to this post

    Requirements

    RadControls version

     

    .NET version

     

    Visual Studio version

     

    programming language

     

    browser support

    all browsers supported by RadControls


    PROJECT DESCRIPTION                                    
    Hi, im new to Rad controls and im developing an app that implements your RadCarosel.

    I was adding images / items to the carosel and it works great.The problem i have is, the carosel has a hold on the image which lock me out of modifying the image with another command
    eg i have an array of posters that i assign to the carosel, i then have another function that will change the size of the image. Theres a lock/ handle holding the image in memory and i dont know how to dispose if it correctly. I thought it might have been eary to .dispose of all the images in the carosel and reload it when i have finished making changes but this has proved difficult!!

    Vb.Net Code

    RadCarousel1.VisibleItemCount = 7

     

     

     

     

     

     

    Dim i As Integer = 0

     

    While i < directorylist.Count

     

    Try

     

     

    Dim image2 As New RadImageItem

    image2.Image =

     

    Image.FromFile(directorylist(i) + "\folder.jpg")

     

    RadCarousel1.Items.Add(image2)

     

     

    Catch ex As Exception

     

     

    End Try

    Any ideas on how to assign an image to a carosel and then dispose of the image correctly when i need to?

    Very limited threads on this control and the documentation is very vague!

    Thanks for any help :)

  2. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 07 Jun 2012 Link to this post

    Hi Kevin,

    Thank you for writing.

    Your approach for images assignment is correct. You should dispose these images when you do not need them anymore in RadCarousel - e.g. when closing the form that contains the carousel.

    As to our documentation, we are constantly striving to improve it. Still, there might be some omissions. We will appreciate it if you share with us ideas and details on how to improve our documentation, or point us to issues that you have encountered.

    Thank you for the cooperation.

    Regards,
    Peter
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Kevin
    Kevin avatar
    14 posts
    Member since:
    Jul 2012

    Posted 07 Jun 2012 Link to this post

    Problem solved !

    I assigned an imagelist to the control, populated it and added the items to the carousel.

    RadCarousel1.VisibleItemCount = 7

            'Create image list
            Dim imgList As ImageList = New ImageList
            imgList.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit
            imgList.ImageSize = New System.Drawing.Size(92, 138)

            'asign image list to carousel
            RadCarousel1.ImageList = imgList

            Dim i As Integer = 0
            While i < directorylist.Count

                'check if file exists
                Dim fFile As New FileInfo(directorylist(i) + "\folder.jpg")

                'if the movie poster is found add it to imagelist if not then load noPoster image
                If fFile.Exists Then
                    imgList.Images.Add(Image.FromFile(directorylist(i) + "\folder.jpg"))
                Else
                    imgList.Images.Add(My.Resources.noPosterImage)
                End If

                Try

                    Dim imageReturned = imgList.Images.Item(i)

                    Dim image1 As New RadImageButtonElement
                    image1.DisplayStyle = DisplayStyle.Image

                    'get movie name
                    Dim temp As String = directorylist.Item(i)
                    Dim tempName() As String = temp.Split("\")
                    Dim movName = tempName(tempName.Count - 1)

                    'assign name to image
                    image1.Text = movName

                    'add image object as new image
                    image1.Image = New Bitmap(imageReturned)

                    'add image to carousel
                    RadCarousel1.Items.Add(image1)



                Catch ex As Exception

                End Try


                i = i + 1
            End While

    I also had issues with the selected image index (wrong values) but by assigning the text to the image i can use that name to find the correct path to load my movie data

  5. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 12 Jun 2012 Link to this post

    Hi Kevin,

    Thank you for writing back.

    I can confirm this as the right way to fill up the carousel with images.

    Thank you for sharing your solution. I hope it will be useful to other developers as well.

    Kind regards,
    Peter
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  6. Kevin
    Kevin avatar
    14 posts
    Member since:
    Jul 2012

    Posted 15 Jun 2012 Link to this post

    Hi,

    Just an update on the .dispose() method.

    .dispose() will dispose of all the elements in the control, this is not what i wanted but to mearly replace one item with a new poster.

    so. . . . i used the .items.clear() method to clear all element, repopulated an imagelist and added the images again.

    Did the trick  . . . .:)
  7. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 20 Jun 2012 Link to this post

    Hi Kevin,

    Thank you for sharing your findings with other developers as well. I am happy that you managed to find a solution for this case.

    Kind regards,

    Peter
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Back to Top
UI for WinForms is Visual Studio 2017 Ready