Chronostasys / Blazor.Cropper

A blazor library provides component to crop image
MIT License
84 stars 19 forks source link

Croppers don't work as soon as there is another Cropper #74

Closed bergy6808 closed 9 months ago

bergy6808 commented 9 months ago

I want to allow users to choose the differents crops of an image. Having croppers inside a loop makes the first cropper unusable and others can't load the image at all.

Here's how I call the components

  @foreach (var (i, (w, h)) in ThumbnailSizes.WithIndex())
  {
      <div class="col-12">
          <Cropper @ref="croppers[i]" AspectRatio="@((double)w/h)" CropperHeight="150"
                   RequireAspectRatio="true" ImageFile="_cropperSource[i]"
                   InitCropHeight="150"
                   InitCropWidth="150"
                   AnimeGifEnable="true"
                   PureCSharpProcessing="true"
                   IsCropLocked="false"
                   IsImageLocked="false"></Cropper>
      </div>
  }

Here's how I set the source

  private static readonly (int Width, int Height)[] ThumbnailSizes = new[]
  {
      (1200, 630),
      (400, 230),
      (340, 500),
      (780, 300),
      (120, 90),
  };
  _cropperSource = ThumbnailSizes.Select(_ =>
  {
      var bytes = new byte[_newPictureFile.Bytes.Length];
      _newPictureFile.Bytes.CopyTo(bytes, 0);
      var ms = new MemoryStream(bytes);
      ms.Position = 0;
      return new StreamFile(ms);
  }).ToArray();
bergy6808 commented 9 months ago

Updated the package and it works fine now. Sorry for this.