This is a migrated thread and some comments may be shown as answers.
Rotator resize images from folders
1 Answer 15 Views
This is a migrated thread and some comments may be shown as answers.
Allan
Top achievements
Rank 2
Allan asked on 04 Jun 2013, 05:58 AM
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.Items.Add(GetThumbNail(fileName))
    Next
    RadRotator1.Start(True)
    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
    image.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone)
    image.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone)
    ' calculate aspect ratio so image is not distorted
    Dim ratio As Double = 0
    If image.Width > image.Height Then
        ratio = ClientRectangle.Width / image.Width
    Else
        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

1 Answer, 1 is accepted

Sort by
0
Slav
Telerik team
answered on 06 Jun 2013, 04:51 PM
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())
rotator.Items.Add(rotatorItem)

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.

Regards,
Slav
Telerik
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.
Asked by
Allan
Top achievements
Rank 2
Answers by
Slav
Telerik team
Share this question
or