Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

127
Visualizações
I cant dynamical update image in blazor canvas

I am trying update img from src=@string, browser save image cache, and then draw first image constantly, but I want to update the image dynamically, from byte array. I turn off save cache function, and then nothing is drawn anymore, but I can update the @string and write it to console, where I see that string was updated. Also should say that I can update image when use onclick event, but its not what I want.

MyCode

@page "/"
@inject IJSRuntime JsRuntime;


<div>
    <img src="@Image64" @ref="imageRef" hidden/>
</div>

<div id="canvasHolder" style="position: fixed; width: 100%; height: 100%">
    <BECanvas Width="1000" Height="1000" @ref="CanvasRef"></BECanvas>
</div>



@code{
    protected BECanvasComponent CanvasRef;
    ElementReference imageRef;
    Canvas2DContext ctx;
    public string Image64 = "100";
    Random rand = new Random();
    PngFormat pngFormat = PngFormat.Instance;
    byte[] arr = new byte[2000000];
    Image<Rgba32> map;
    int countX = 0;
    int countY = 0;


    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        this.ctx = await CanvasRef.CreateCanvas2DAsync();
        await JsRuntime.InvokeAsync<object>("initRenderJS", DotNetObjectReference.Create(this));
        await base.OnInitializedAsync();
    }

    protected override async Task OnInitializedAsync()
    {
        System.Console.WriteLine("Mario");
        Image64 = "data:image/png;base64,.."; //+ "?nocache=<?php echo time(); ?>";      
    }


    [JSInvokable]
    public async ValueTask RenderInBlazor(float timeStamp)
    {
        countX += 15;
        countY += 10;
        await this.ctx.ClearRectAsync(0, 0, 1000, 1000);
        rand.NextBytes(arr);
        System.Console.WriteLine("1");
        Image64 = Convert.ToBase64String(arr); //+ "?nocache=<?php echo time(); ?>";
        await this.ctx.DrawImageAsync(imageRef, countX, countY, 400, 400);
    }
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda