This is a migrated thread and some comments may be shown as answers.

dispose of images correctly

5 Answers 413 Views
Carousel
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 2
Kevin asked on 04 Jun 2012, 10:29 PM

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 :)

5 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 07 Jun 2012, 01:13 PM
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 >>
0
Kevin
Top achievements
Rank 2
answered on 07 Jun 2012, 06:58 PM
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

0
Peter
Telerik team
answered on 12 Jun 2012, 08:34 AM
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 >>
0
Kevin
Top achievements
Rank 2
answered on 15 Jun 2012, 03:41 PM
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  . . . .:)
0
Peter
Telerik team
answered on 20 Jun 2012, 01:01 PM
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 >>
Tags
Carousel
Asked by
Kevin
Top achievements
Rank 2
Answers by
Peter
Telerik team
Kevin
Top achievements
Rank 2
Share this question
or