View Modes

Define the view mode of the cropper.

Simple Usage

With the ViewMode in Options prop you can change the view mode of the cropper.

ViewMode enumeration contains the following view modes:

Vm0 - no restrictions;

Vm1 - restrict the crop box not to exceed the size of the canvas;

Vm2 - restrict the minimum canvas size to fit within the container. If the proportions of the canvas and the container differ, the minimum canvas will be surrounded by extra space in one of the dimensionss;

Vm3 - restrict the minimum canvas size to fill fit the container. If the proportions of the canvas and the container are different, the container will not be able to fit the whole canvas in one of the dimensions;


@using Cropper.Blazor.Models;

<div class="img-container">
    <CropperComponent @ref="cropperComponent" Src="images/Rivne.jpg"
                      Options="cropperOptions" Class="big-img" />
div>

<MudButtonGroup Color="Color.Primary" Variant="Variant.Filled" OverrideStyles="false" Class="mud-width-full">
    <MudTooltip Text="View Mode 0" RootClass="mud-width-full">
        <MudButton OnClick="@(()=>SetViewMode(ViewMode.Vm0))" Color="Color.Primary" Variant="Variant.Filled" Class="ml-0"
                   Style="@(cropperOptions.ViewMode == ViewMode.Vm0 ? "background-color: var(--mud-palette-primary-darken)" : "")" FullWidth="true">
            VM0
        MudButton>
    MudTooltip>
    <MudTooltip Text="View Mode 1" RootClass="mud-width-full">
        <MudButton OnClick="@(()=>SetViewMode(ViewMode.Vm1))" Color="Color.Primary" Variant="Variant.Filled" Class="ml-0"
                   Style="@(cropperOptions.ViewMode == ViewMode.Vm1 ? "background-color: var(--mud-palette-primary-darken)" : "")" FullWidth="true">
            VM1
        MudButton>
    MudTooltip>
    <MudTooltip Text="View Mode 2" RootClass="mud-width-full">
        <MudButton OnClick="@(()=>SetViewMode(ViewMode.Vm2))" Color="Color.Primary" Variant="Variant.Filled" Class="ml-0"
                   Style="@(cropperOptions.ViewMode == ViewMode.Vm2 ? "background-color: var(--mud-palette-primary-darken)" : "")" FullWidth="true">
            VM2
        MudButton>
    MudTooltip>
    <MudTooltip Text="View Mode 3" RootClass="mud-width-full">
        <MudButton OnClick="@(()=>SetViewMode(ViewMode.Vm3))" Color="Color.Primary" Variant="Variant.Filled" Class="ml-0"
                   Style="@(cropperOptions.ViewMode == ViewMode.Vm3 ? "background-color: var(--mud-palette-primary-darken)" : "")" FullWidth="true">
            VM3
        MudButton>
    MudTooltip>
MudButtonGroup>
@code {
    private CropperComponent? cropperComponent = null!;

    private Options cropperOptions = new Options
    {
        ViewMode = ViewMode.Vm3
    };

    public void SetViewMode(ViewMode viewMode)
    {
        cropperOptions.ViewMode = viewMode;
        cropperComponent?.Destroy();
        cropperComponent?.InitCropper();
    }
}


Copyright © 2022-2024 Cropper.Blazor

Powered by .NET 8.0.3

An unhandled error has occurred. Reload 🗙