We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to change the size of images from original size in carousel Item?

Carousel control displays the image in its original size by default. But we can customize the selected item image size in Carousel by changing the Bitmap image size. The following code demonstrates the same.


Code Example: [C#]



Code Example: [VB]


'Initialize the data tabel


Private dt As New DataTable()


dt.Columns.Add("col1", GetType(Byte()))


'Set Image


Dim img As Image = Image.FromFile("../../Images/10812.jpg")


Dim img1 As Image = Image.FromFile("../../Images/Bird.jpg")


Dim img2 As Image = Image.FromFile("../../Images/10811.jpg")


Dim img3 As Image = Image.FromFile("../../Images/Bird.jpg")


Dim dr As DataRow = dt.NewRow()


Dim dr1 As DataRow = dt.NewRow()


Dim dr2 As DataRow = dt.NewRow()


Dim dr3 As DataRow = dt.NewRow()


'Add image to data table


dr("col1") = imageToByteArray(img)


dr1("col1") = imageToByteArray(img1)


dr2("col1") = imageToByteArray(img2)


dr3("col1") = imageToByteArray(img3)










'Image into carousel




Public Function imageToByteArray(ByVal imageIn As System.Drawing.Image) As Byte()


Dim ms As New MemoryStream()


imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)


Return ms.ToArray()


End Function


''' <summary>

''' To Add Carousel dynamically

''' </summary>


Private value As Object = Nothing


Private Sub SetImagesForCarousel()


For Each drow As DataRow In dt.Rows


value = drow("col1")


If value.ToString().Length > 0 Then


Dim imagenbuffer() As Byte = DirectCast(value, Byte())


Dim ms As New MemoryStream(imagenbuffer)


Dim carouselImage As New CarouselImage()


carouselImage.ItemImage = Image.FromStream(ms)


'To change size of the image.


carouselImage.ItemImage = resizeImage(carouselImage.ItemImage, New Size(1500, 600))




End If


Next drow


Me.carousel1.ImageSlides = True


Me.carousel1.RotateAlways = False


Me.carousel1.TransitionSpeed = 1F


Me.carousel1.ShowImagePreview = True


carousel1.UseOriginalImageinPreview = True


End Sub


Public Shared Function resizeImage(ByVal imgToResize As Image, ByVal size As Size) As



Return CType(New Bitmap(imgToResize, size), Image)


End Function




Figure: By default, selected Carousel Item Image displayed in its original size.


Figure: Selected Carousel Item Image size has been changed/resized.




C#: CarouselSample


VB: CarouselSample


Article ID: Published Date: Last Revised Date: Platform: Control: .NET Framework:
8969 07/13/2018 07/13/2018 WinForms Carousel 4
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon