New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
screenshot not working correctly #358
Comments
@MirkoAlo Can you please share how you got it working? ie: to take a snapshot? |
I have a button in html that whit a click launch this function: document.querySelector('a-scene').components.screenshot.getCanvas('equirectangular'); i tried whit perspective also but the background of a cam is always black or white, i can see only the model. Thank's for help |
@MirkoAlo Will you share your code snippet, so i could evaluate it? I too had same results when i tried to capture screenshot like this: Generate and Download Screenshot of webpage without lossing the styles (https://stackoverflow.com/a/44495166)
HTML:
The above snippet uses html2canvas.js to capture the contents of an id and writes the same into a canvas, then save image file using FileSaver.js. So basically import those two files to get this code working. Since html2canvas doesn't supports video tag yet, it wont capture contents for a-scene (in AR.js on A-Frame). Whenever i try to capture screenshot like this, i'm too getting screenshots with black background 😢 . |
@MirkoAlo @liyasthomas |
@Esmolan @MirkoAlo Hi guys, lately I found a working example to capture a video frame and download it. Its here: https://tutorialzine.com/2016/07/take-a-selfie-with-js This simple uses a |
@liyasthomas Thanks Liyas! I am struggling to get it to work just the code for some reason it tell me the video is null. Also I asked in another forum how to make this work and they recommended rendering the camera feed as a texture and then automatically the screenshot component will now capture it However, I've had no luck converting the camera to a texture when using A-frame up to this time. |
@liyasthomas Hey! I've been playing around with merging the video tag with A-Frame. Until now I was able to grab the video tag of A-frame and taking a snapshot but for some reason it only takes the webcam now and not the 3D model.
JS:
` Any ideas? I think we are almost there. |
@Esmolan Have you tried with a simple And by the way, you are right, we are almost there!
|
@liyasthomas Thanks! Sounds good. Yeah, just tried with a simple Let me know if you find anything! I will keep playing with the code a debugging. Thanks 👍 |
I'm having the same problem as well, it's either just a blank canvas with the 3D objects or just the video stream without the 3D elements |
@crazycat9x Hi. If you don't mind, share your current code snippets & screenshots of output so others could easily debug it. |
guys I got it to work!!!!!
|
@crazycat9x Cool!! Would you mind sharing your code! and screenshot! @liyasthomas Take a look :D |
The mergeImages func is from https://github.com/lukechilds/merge-images
|
For the image based marker, I think it would be impossible as AR.js use ~20x20 ascii image as a mean of detection, it would simply be too pixelated to use anything besides simple marker with fat border. |
There is a bug in my code
suppose to be
|
Yeah i got that as well, only on mobile thou , my laptop seem to work fine. The a-scene actually have width larger than the mobile display, so when you merge it got squeezed. I tried to force the a-scene width to 100% of display, but every element inside a-scene got squish instead. |
@crazycat9x Likewise. Laptop seems to work fine. I will let you know, maybe if we try to resize the a scene with the video size. |
How about we try to implement screen record and download the video?? That would be super cool! |
@liyasthomas Hey! That sounds cool. But I have another question. Is there a way to have image based markers in web VR? Perhaps not using A-frame but three.js, etc? |
I afraid its still not possible. Anyway its a core feature. I hope @jeromeetienne and team may consider it in near future. |
@crazycat9x Hi Crazycat were you able to solve this? |
@Esmolan you mean the image being squeezed? then no, I havn't solved it yet. |
@crazycat9x Thats right! I am checking that with other programmers bc I cant seem it to work it out. Will keep you posted |
@crazycat9x Hey! when you capture the video frame. Does it take the width and height of where its being captured? We should resize the a-scene to the width and height of the video capture first. And then merge them. |
@crazycat9x @Esmolan Hi~both! I modified resizeCanvas function. It looks normal ! Because a-scene's frame is 4096 x 2048 by default. So you need to deal with this by calibrating its frame size.
|
哈哈哈 |
@Yufan-Lin - Using your code, the landscape works great, but portrait only shows the video capture, not the 3D model. Any thoughts on how to debug this? |
for me was working better the 'old' resizeCanvas. anyway guys, thanks for this! |
I just swapped width and height for portrait mode like below
|
Hi, can someone post the complete example of working screenshot taking+downloading mechanism, in glitch, please? |
Actually this is complete code: #358 (comment) Just
That's all! |
I'd like to make a contribution to this thread. I've improved the function captureVideoFrame(video, format) {
if (typeof video === 'string') {
video = document.querySelector(video);
}
format = format || 'jpeg';
if (!video || (format !== 'png' && format !== 'jpeg')) {
return false;
}
const canvas = document.createElement("CANVAS");
canvas.width = screen.width;
canvas.height = screen.height;
const imageWidth = video.videoHeight * (screen.width / screen.height);
canvas.getContext('2d').drawImage(
video,
(video.videoWidth - imageWidth) / 2,
0,
imageWidth,
video.videoHeight,
0,
0,
screen.width,
screen.height,
);
var dataUri = canvas.toDataURL('image/' + format);
var data = dataUri.split(',')[1];
var mimeType = dataUri.split(';')[0].slice(5)
var bytes = window.atob(data);
var buf = new ArrayBuffer(bytes.length);
var arr = new Uint8Array(buf);
for (var i = 0; i < bytes.length; i++) {
arr[i] = bytes.charCodeAt(i);
}
var blob = new Blob([ arr ], { type: mimeType });
canvas.remove();
return { blob: blob, dataUri: dataUri, format: format, width: screen.width, height: screen.height };
}; |
I think I've fixed the code. Maybe it can be useful: `
` |
hello someone can help me ? I have seen the code above and there is a querySelector ('video') section, where do we get the video tag? I don't use video tags at all when using ar.js |
@Alsania14 |
Guys I'm having this issue. It takes the screenshot but half of the screen is white. How can I fix this? |
Hi guys, I solved the problem. Here's a complete sample code:
Point at the trex If you get the maximum call stack size error, see this issue |
Wait, html2canvas works? I've spent hours trying to get that working! Good job if you did! Thanks, |
Yes, html2canvas works. I could not make it work with html-to-image though. Enjoy. I also spent hours trying to make it work. You can see the issue I created here. Also if you can comment on this issue. I need to know how to monkey patch the variable at runtime. The author of html2canvas doesn't reply on github or email. |
Thank you a lot!!! You solved my probem. All code above is working 'partially'. TNX) Now my app is working correctly on both Mobile phone and PC |
Thanks a lot mate!!!, worked like a charm, only thing i had to change was the html part where i had my own aframe code i.e using mindar and then adding allowTaint and foreignObjectRendering to the html2canvas to fix the tainted canvas issue. |
Hi guys!
Im trying to add a function for make a screenshot of my 3D model rendered in AR, the model is captured but the nackground of the object is always black or white.
Anybody can help me??
Thanks
The text was updated successfully, but these errors were encountered: