Code Monkey home page Code Monkey logo

Comments (8)

stefanloerwald avatar stefanloerwald commented on August 16, 2024

Hi @destrugter,

I see how that would be useful, but am not sure whether it's going to be easy to implement. It might be as easy as providing a callback/event in OnAfterRenderAsync of the Diagram component, but I don't know for sure. Could you experiment with this and let me know?

Out of curiosity: how are you taking screenshots?

BR
Stefan

from blazor.diagrams.

destrugter avatar destrugter commented on August 16, 2024

Currently the way I'm doing it is calling ZoomToFit, awaiting a 1s Task, then using html2canvas to convert the element to a canvas, and then converting it to a blob, and finally converting that blob to a png and copying it to the clipboard.

from blazor.diagrams.

Clive321A avatar Clive321A commented on August 16, 2024

@destrugter id love to see how you have implemented this, so you are able to render a diagram to a PNG?

from blazor.diagrams.

destrugter avatar destrugter commented on August 16, 2024

@CliveBennett I used this JS called html2canvas. It works pretty well. The command I have after you have downloaded html2canvas is await html2canvas(document.querySelector("#" + id)).then(canvas => canvas.toBlob(blob => navigator.clipboard.write([new ClipboardItem({ 'image/png': blob })])));

from blazor.diagrams.

Clive321A avatar Clive321A commented on August 16, 2024

Awesome, appreciate that ill give it a go.

from blazor.diagrams.

Clive321A avatar Clive321A commented on August 16, 2024

I managed to get the copying of the diagram to a PNG working, thanks for the pointer.

But, because some of the diagrams that get generated can be quite large, I really need to have a dynamic sized image, so I can have a large image for the large ones, and a small image for the small ones.

Is there a property for the diagram class that would give me the max rendered width and height in pixels?, even if cropped on screen?

from blazor.diagrams.

destrugter avatar destrugter commented on August 16, 2024

@CliveBennett The code I was using was this:

private async Task GetDiagramScreenshot()
{
	diagram.ZoomToFit();
	await Task.Delay(1000);
	image_url = await TakeScreenshot();
}

I am using the await Task.Delay(1000) because I am unsure of when ZoomToFit is finished working, which is why I opened this issue in the first place. If I'm understanding you correctly, this should get you what you're after?

from blazor.diagrams.

Clive321A avatar Clive321A commented on August 16, 2024

@destrugter the issue is that a lot of our diagrams can render off screen as they are quite large, I use the little viewport control to enable people to scroll around the diagram.

This is an example of what they can look like

image

But I needed to grab the entire diagram in one hit onto a single image.

What I ended up doing was to change the containing div to 5000x5000 pix with JS prior to running Html2Canvas which then generates a large image with the diagram at the top, then I wrote some code to Crop the image to a sensible size by scanning the pixels for whitespace.
Works well (so far!) thanks again for the help

from blazor.diagrams.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.