ComponentOne Bitmap for WinForms
Features / Applying Transformations / Scaling an Image
In This Topic
    Scaling an Image
    In This Topic

    Scaling is an important requirement of image processing as it resizes (increases and decreases the size) image. Bitmap also allows scaling in and out an image through the InterpolationMode property of the Scaler class.

    The image below shows scaling in and scaling out feature.

    Scale image using ComponentOne Bitmap for WinForms

    The following code illustrates scaling in and scaling out an image on button clicks. This example uses the sample created in the Quick start section.

    Private Sub ApplyTransform(t As BaseTransform)
        Dim newBitmap = bitmap.Transform(t)
        bitmap.Dispose()
        bitmap = newBitmap
        selection = New RectF(1.0F, 1.0F)
        UpdateImage()
    End Sub
    
    'Event to scale out the image on button click
    Private Sub Button2_Click(sender As Object, e As EventArgs) _
        Handles Button2.Click
        Dim px As Integer = CInt(bitmap.PixelWidth * 1.6F + 0.5F)
        Dim py As Integer = CInt(bitmap.PixelHeight * 1.6F + 0.5F)
        ApplyTransform(New Scaler(px, py, _
                        C1.Win.Bitmap.InterpolationMode.HighQualityCubic))
    End Sub
    
    'Event to scale in the image on button click
    Private Sub Button3_Click(sender As Object, e As EventArgs) _
        Handles Button3.Click
        Dim px As Integer = CInt(bitmap.PixelWidth * 0.625F + 0.5F)
        Dim py As Integer = CInt(bitmap.PixelHeight * 0.625F + 0.5F)
        If px > 0 AndAlso py > 0 Then
            ApplyTransform(New Scaler(px, py, _
                            C1.Win.Bitmap.InterpolationMode.HighQualityCubic))
        End If
    End Sub
    
    void ApplyTransform(BaseTransform t)
    {
        var newBitmap = bitmap.Transform(t);
        bitmap.Dispose();
    
        bitmap = newBitmap;
        selection = new RectF(1f, 1f);
    
        UpdateImage();
    }
            
    //Event to scale out the image on button click
    private void button3_Click(object sender, EventArgs e)
    {
        int px = (int)(bitmap.PixelWidth * 1.6f + 0.5f);
        int py = (int)(bitmap.PixelHeight * 1.6f + 0.5f);
        ApplyTransform(new Scaler(px, py, 
            C1.Win.Bitmap.InterpolationMode.HighQualityCubic));
    }
    
    //Event to scale in the image on button click
    private void button4_Click(object sender, EventArgs e)
    {
        int px = (int)(bitmap.PixelWidth * 0.625f + 0.5f);
        int py = (int)(bitmap.PixelHeight * 0.625f + 0.5f);
        if (px > 0 && py > 0)
        {
            ApplyTransform(new Scaler(px, py, 
                C1.Win.Bitmap.InterpolationMode.HighQualityCubic));
        }
    }
    
    See Also