Rotator resize images from folders

2 posts, 0 answers
  1. Allan
    Allan avatar
    121 posts
    Member since:
    Jun 2008

    Posted 04 Jun 2013 Link to this post

    Is it possible to implement the following example for winforms in using the AJAX controls:

    Private Sub TutorialCreatingASlideViewerWithRadRotator_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim myPicturesPath As String = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)
        For Each fileName As String In Directory.GetFiles(myPicturesPath, "*.jpg")
        RadRotator1.ShouldStopOnMouseOver = False
    End Sub
    Private Function GetThumbNail(ByVal path As String) As RadImageItem
        Dim imageItem As New RadImageItem()
        Dim image As Image = image.FromFile(path)
        ' workaround to prevent using internal image thumbnail
        ' calculate aspect ratio so image is not distorted
        Dim ratio As Double = 0
        If image.Width > image.Height Then
            ratio = ClientRectangle.Width / image.Width
            ratio = ClientRectangle.Height / image.Height
        End If
        Dim newWidth As Integer = Convert.ToInt32(image.Width * ratio)
        Dim newHeight As Integer = Convert.ToInt32(image.Height * ratio)
        imageItem.Image = image.GetThumbnailImage(newWidth, newHeight, Nothing, IntPtr.Zero)
        Return imageItem
    End Function
    Private Sub RadRotator1_BeginRotate(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.BeginRotateEventArgs) Handles RadRotator1.BeginRotate
        RadLabelElement1.Text = [String].Format("Rotating from item {0} to {1}", e.From, e.[To])
    End Sub
  2. Slav
    Slav avatar
    1359 posts

    Posted 06 Jun 2013 Link to this post

    Hello Allan,

    You can use a similar approach for populating the items in a RadRotator for ASP.NET AJAX. The difference is that you need to create an object of type RadRotatorItem, put the image in its Controls collection and then add the rotator item in the Items collection of the rotator:
    Dim rotatorItem As New RadRotatorItem()
    rotatorItem.Controls.Add(New Image())

    Also, I noticed that you are resizing the images that are inserted in the rotator. The items in the RadRotator for ASP.NET AJAX need to have the same size (this is described in the configuration help article). If your images are with different sizes, you can put every image in a panel with the same size and then add this panel in the rotator item.

    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top