ComponentOne Bitmap for UWP
Features / Applying Transformations / Rotating an Image
In This Topic
    Rotating an Image
    In This Topic

    Bitmap provides the flexibility to rotate images to different angles, 90 degrees, 180 degrees, and 270 degrees in clockwise direction. TransformOptions property of FlipRotator class provided by C1Bitmap can be used to rotate an image. The TransformOptions property accepts value from the TransformOptions enum to set the transformation options.

    The image given below shows an image rotated by 180 degrees in clockwise direction.

     

    The following code implements rotating on an image by 180 degrees in clockwise direction on a button's click event. This example uses the sample created in the Quick Start.

    Private Async Function UpdateImageSource() As Task
        Dim sb As SoftwareBitmap = btmp.ToSoftwareBitmap()
        Await sbs.SetBitmapAsync(sb)
        img.Source = sbs
    End Function
    
    Private Async Function ApplyTransform(t As BaseTransform) As Task
        Dim bm = btmp.Transform(t)
        btmp.Dispose()
        btmp = bm
        Await UpdateImageSource()
    End Function
    
    Private Async Sub btnRotate_Click(sender As Object, e As RoutedEventArgs)
        Await ApplyTransform(New FlipRotator(TransformOptions.Rotate180))
    End Sub
    
    private async Task ApplyTransform(BaseTransform t)
    {
        var bm = btmp.Transform(t);
        btmp.Dispose();
        btmp = bm;
        await UpdateImageSource();
    }
    
    private async void btnRotate_Click(object sender, RoutedEventArgs e)
    {
        await ApplyTransform(new FlipRotator(TransformOptions.Rotate180));
        
    }
    
    See Also