Kahless
Kahless

Reputation: 1253

Converting image to imagedata and vice versa without drawing to canvas

I'm wondering if there's a way to convert images to imagedata and vice versa without drawing to canvas.

I know the methods getImageData() and toDataURL() can be used to copy the canvas but what if I'd prefer to take an imc.src path and convert that directly to imagedata. Or convert imagedata directly to a DataURL without passing it to canvas.

Upvotes: 0

Views: 324

Answers (1)

Jeff Escalante
Jeff Escalante

Reputation: 3167

I think the answer to this question is no. If you check out the docs for ImageData, you'll see that it's tied quite directly to the canvas element and all it's properties are read-only. In addition, if you pop into the console and try new ImageData, you'll see that it's not allowed for you to construct one from scratch yourself, and that the function contents are native code.

If someone finds a way to do this, I'd be very impressed -- you never know what you don't know. But since the spec specifically says it shouldn't be possible and clearly efforts have been made to prevent it from happening, I'd say it's probably not a good bet either way.

Perhaps there's another workaround for the issue you are facing. If you re-word your question to include a more broad view of your problem, some of us might be able to suggest possible alternate solutions, as you are starting to see in the first comment.

Upvotes: 1

Related Questions