I'm trying to get the screenshot of a given URL as a bitmap image on the Windows Phone. The WebBrowser class does not seem to have the DrawToBitmap method.
Any pointers on how to get this working?
Use WriteableBitmap to render the WebBrowser control and its contents to a bitmap as described by Laurent's article Taking a screenshot from within a Silverlight #WP7 application, which also explains how to save it to the media library.
You can't take a screenshot of the WebBrowser Control as there seems to be a bug with the way it works with WriteableBitmaps. An alternative method could be to send the URL to a web service which takes a screenshot on the server and returns it back to your app.
Related
I have a window.open code to launch inappbrowser on phonegap. I use it for displaying image.
This inappbrowser has EnableViewPortScale=yes, so it's totally zoomable.
However, it seems like there is zoom-out-limit in inappbrowser. Here is the code.
window.open(myFullImageUrl, '_blank',
'location=no,EnableViewPortScale=yes,presentationstyle=pagesheet');
It's already zoomed-in a little. I can zoom-in-and-out because of EnableViewPortScale=yes for sure.
However, it seems like there is zoom-out-limit.
when i load up 1024x768 photo, it doesn't show fully zoomed-out photo(on both iOS and Android), but it's like 120%-ish already zoomed in.
I Just created stackoverflow account, so i can't upload photo. sorry!(it says i need 10 reputations to upload image)
There is no true solution for this issue.
So what I did is I just continue using inAppBrowser, but just instead of directly loading image from Amazon server(that's where I stored all images), I just made my window.open to go to another my URL and attach that url as a parameter after '?'.
The reason why I did this is because then I can force the Image web-view to have brief Javascript and CSS to render this dang-image correctly.
And as you guys know, this page must have meta-data that allows user-scale true, and must NOT have max-scale value.
So, Yep. Long story short, If you DIRECTLY load up the image in the inAppBrowser of phonegap, there is NO WAY you can force the image to start with 'not even slightly zoomed-in, but perfectly zoomed-out to the max'. Your own Page, Your own JS and CSS is the way to go guys.
I would like to make screenshots of the receiver application running of the Chromecast device.
I need to have it running on the device to show the video and the application together.
Is there a way to do this ?
Ali Naddaf's answer is technically true, however with a little work I was able to make a faithful reconstruction of the screen, to the point that it is indistinguishable from an actual screenshot.
We will use code from the html2canvas project, see http://html2canvas.hertzen.com/documentation.html . It will render our screen to a canvas. In particular, copy&paste the compiled code from http://html2canvas.hertzen.com/build/html2canvas.js to the Chromecast console. (adding a tag to dom seems not to work) You can access the Chromecast console & developer tools by accessing the ip.ad.dr.ss:9222 port via Chrome.
Issue the following command:
html2canvas(document.body, {onrendered: function(canvas){document.write('');}});
This will destructively replace the screen with the screenshot (I find this convenient but you can easily think of a more polite way if you wish)
In the elements browser, you will have an img, with a base64 url specified as a src. Click on the url, chrome will open the image in a new tab. Hopefully it's the screenshot that you wanted.
You might find that some pictures are missing because of e.g. same origin policy. The javascript have other privileges than accessing images from html. If this happens, work it out somehow (use https for images for example), then goto 1.
You have your screenshot!
No, that is not possible due to many reasons such as media rights and security.
I'm extending zsolt-szatmari's answer into a copy-pastable script that you can use in the Chromecast Developer Tools console:
As he said, copy and paste http://html2canvas.hertzen.com/build/html2canvas.js code into the console
Call the html2canvas method: it will create a new canvas element into the DOM: html2canvas(document.body, { onrendered: function(canvas) { document.body.appendChild(canvas); } });.
Get a base64 string representation of the image currently displayed in the canvas: document.getElementsByTagName('canvas')[0].toDataURL('image/png');
You'll then get a very long base64 string: if you click on it, Chrome will show the image in a new tab. Please note that this image could be far from what is really shown on your Chromecast due to html2canvas limits:
The screenshot is based on the DOM and as such may not be 100%
accurate to the real representation as it does not make an actual
screenshot, but builds the screenshot based on the information
available on the page.
(source)
I was thinking that you could maybe use this to capture the canvas to an image file, which normally works in javascript with canvas:
var canvas = document.getElementById("mycanvas");
var img = canvas.toDataURL("image/png");
Of course then you would need to transfer this image file to somewhere - not exactly sure how to the last bit from the chromecast. Maybe that is not possible.
As a chromecast developer myself I needed screenshots of the app running to show customers. I ended up doing a kind of "simulation" of the chromecast - calling some mockup methods in javascript to display the data and then accessing my receiver app via the cast url on my desktop in the browser. Then I used a screen capture program to capture the browser output. This gave me the same screenshot as from running the receiver app on chromecast on TV, which is essentially just a browser showing your html+css+javascript receiver.
I've got a WebBrowser on my phone UI (from Microsoft.Phone.Controls), showing web page with images. How do I access the html image binary data?
I want to store the image for later rendering, and perhaps do some image transformations for it too.
You cannot do that since WebBrowser control is pretty much sandboxed and you don't have access to DOM or anything inside it.
EDIT: You can at least get the HTML source for the page and you could then parse the source, extract urls for images and then manually download them. You can get the source via the WebBrowser.SaveToString method
I have an application in which I want a webview ( WebBrowser ) to open a site, which I think is one of the, if not exclusive functions of a webbrowser.
But it does not display video's, and some of the other media is scrambled too. Any idea for that?
P.S. I am not talking about the webbrowser app, I am talking about the webview, implemented inside an aplication that is not working properly.
Generally, the media is picked up by the appropriate media handler. If the video doesn't play in the WebBrowser control, it most likely means that its format is simply not supported.
I have a web app I'm building in Dashcode, currently every thing is working as advertised. I'm using the browser template and was able to modify it a bit, got the xml working to connect images and their description. Now I want to add a simple OnClick event that sends the image to fullscreen but I can't find any documentation for that. I'm pretty sure this is easily done so I'm missing something here? Any help greatly appreciated.
Tom
Taking over the screen is a bit complicated (if your talking about a full screen experience like youtube), but full screen in the browser window is defiantly possible. The simplest method is to have the click event open a link to the image location. This would load the image in full resolution in the browser window. A more elegant approach would be to load the image url into the source of a image dashcode object. and have that objects visibility only appear overs the whole web app when the Oncick event occurs. If you are talking about a built in function in dashcode to achieve a full screen/browser image, your out of luck.