The WriteableBitmap class that was introduced in Silverlight 3 does not allow images to be rendered from a different domain for security reasons and hence it is impossibe to output an image of the Bing Map.
Does anyone have any suggestions for a workaround? I just want to capture a snapshot of the image including the controls and shapes I have drawn on the overlying canvas
Thanks
Paul
There is a workaround - the bing maps silverlight control allows you to specify a custom configuration. In this configuration, you can specify your own URLs for images, and make them so that they are not cross-domain, and hence not "insecure".
However, there is a bug in Silverlight which causes the workaround to fail. See here: https://connect.microsoft.com/VisualStudio/feedback/details/628962/
The sample attached to the bug report in the link above shows how to specify a custom map control configuration.
Did you try Bing's Imagery Service? See
http://msdn.microsoft.com/en-us/library/cc966738.aspx
It would be shame if something that is inplace for good security reasons could then be worked around, wouldn't it?
It may be that your true goal might be achievable using some other approach but you don't state what that is.
For example, you might want to generate some simple image that can then be hosted on a web site to be downloaded. A possible workaround would be to use the Silveright print API to print the desired content. Use a PDF generating printer driver you could then upload the generated PDF to the site
Of course this example may be far from your purpose. State your intent and a more lateral work around may be offered or at least a definitive, "no you can't".
Related
I'm trying to embed/display a PDF in a WPF application. So far, I've tried those solutions, without success:
Display the PDF in a WindowsFormsHost hosting an AxAcroPdf
control, similarly to what's shown here. The problem is that my application sets AllowsTransparency
= True to create a style similar to Modern UI, but
that doesn't blend well with a WindowsFormsHost (the control
becomes invisible).
Display the PDF in a WebBrowser control. The problem is the same.
Set AllowsTransparency = False, but this causes a sluggish feeling in the application. Since I use WPF purposedly to enhance the look and feel of our business applications to the benefit of our end-users, this can't be a solution.
Use a second window with AllowsTransparency = False to display the WindowsFormsHost, and hack it to make it look like a child control of the main window, as it's described here. However, I don't like the code-behind approach since I'm using MVVM.
Find a native PDF control for WPF. However, I only found a couple of commercial ones and that's not an option right now.
What I need is to be able to:
Display a PDF or its representation (i.e. an image or a conversion to another format) in a WPF application.
Keep my style visually intact and fluid (AllowsTransparency must stay True).
Use an approach respecting the principles of MVVM (preferably no code-behind).
Include it in my application for free (for commercial usage).
I'm totally open to hand-made solutions, open-source libraries and even completely different approaches.
I have two solution for this:
Open your .pdf file and then print as an .xps (also you must be able for doint this in code), then this file you can embded this file in your app, and show it as a xps document. See this: Documents in WPF - MSDN - Microsoft (XPS)
To use a free library, I'm not very sure if this allows show pdf, but it generate them, you can take a look at EO-Pdf.
Hope this tips helps to solve the problem.
If you're opened to Open-Source solutions, I would recommend GhostScript. You can convert the PDF (with decent quality, for the most part) to individual image files of most any format you might want to work with.
The other option is to convert the PDF to HTML using pdf2htmlEX, but it will currently only compile for Linux.
I use both of the above solutions in several applications on both Linux and Windows. The advantage to the HTML way is that the text can be copied and pasted. The advantage of the GhostScript way is that the images might be more portable (smaller).
As with any open-source solution, you need to be aware of the terms of the license under which each product is released, and how that may impact your final result.
There is a good solution that I used before is to use CefSharp. It's the Chrome browser engine that supports previewing PDF documents.
Visit quick start page.
It is recommended to visit Troubleshooting page to set appropriate settings if you have problems.
If you want to show PDF files on your local drives you should also use these settings for the browser and then use file:/// protocol:
CefSharp.BrowserSettings browserSettings = new CefSharp.BrowserSettings();
browserSettings.FileAccessFromFileUrls = CefSharp.CefState.Enabled;
browserSettings.UniversalAccessFromFileUrls = CefSharp.CefState.Enabled;
browserSettings.TextAreaResize = CefSharp.CefState.Enabled;
my_bowser.BrowserSettings = browserSettings;
I'm trying to use an invisible WebBrowser control to print a very simple HTML document. Our application requires that we be able to print several documents this way, and that they all can be sent to different printers. Unfortunately, I haven't been very successful in making the output go to the right printer.
The way it works right now is that before printing a document, the application determines which printer is to receive it, and sets the default printer accordingly. To do this it uses SetDefaultPrinter() imported from WinSpool.drv. If I step the code in debug mode I can clearly see that the default printer changes (and this change is reflected in the control panel UI), but the WebBrowser still insists on using the original default printer.
The MSDN documentation, from what I've seen, doesn't really provide a solution for this scenario. I would greatly appreciate some input on how I can accomplish this programmatically.
Given what you've said, perhaps if you restart the process which contains the web browser control (or the process which is the web browser control), after you change the default printer? That's the kind of thing I see happening here, for example.
I suppose it would be possible to fork off a background process that does the actual printing, but I'm really hoping for a simpler solution.
Forking was my first thought towards a probably-simplest solution.
Some other alternatives are as follows.
1). IE, which the webbrowser control is wrapping, exposes APIs via ActiveX. One of its/those APIs might let you specify the destination printer.
2). Some executables (I don't know about IE) have printto entries in the registry. For example, Acrobat Reader has an entry whose value is as follows:
""C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe"" /t "%1" "%2" "%3" "%4"
That's used for specifying the syntax of the command-line which you can use to print and specify a (non-default) printer. You can also Google for printto, see e.g. PrintTo command in the ShellExecute.
3). I have implemented an HTML control for .NET of my own, which doesn't depend on IE. You say that your HTML (and CSS I presume) are simple, so perhaps I can render it, either out of the box or with only a little extra development effort. I don't support printing, but printing is quite easy for a user control to implement. Getting me to implement that for you would cost you several hundred but, who knows, maybe it's worth it to you. It would be quite a light-weight solution, and perhaps well supported. You could email me if you want to discuss that further.
4). You might also find other controls, similar to mine, more or less famous/expensive; or other applications, e.g. OpenOffice etc etc.
5). You could consider converting the HTML (somehow) to another format (e.g. PDF) for which you have an application which gives you better support for printing.
I've had the exact same problem, and incorporated this control instead of the standard .NET WebBrowser to work around it.
This works on .NET 3.5, if not before
this.webBrowser1.ShowPrintDialog();
Basically functionality i need is:
easy integration with ASP.NET application.
user ability to crop image with handle prior to save
image optimization from any image type to jpg (compression levels) during the save
saving images with proper h/w ratios during the save
user ability to rotate the image prior to save
ability to translate application to foreign language as it won't be used on international site
If you know any application which fits my needs even if it costs money, give me a twit...
Our company has implemented a photo cropper in an ASP.Net MVC application using Atalasoft's DotImage. I did not implement this myself, but I currently maintain the whole of that application (and consequently the cropping component).
Based on the way you phrased your question, I feel that I should explicitly point out that Atalasoft's DotImage only provided the functionality to manipulate images. Other answers referenced ImageMagick and GDI+. In the same vein, these libraries also only provide the functionality to manipulate images.
We had to implement the UI and workflow ourselves. This was, while not rocket science, still far from trivial. While we used a pre-built component for fancy, AJAX-y file uploads (for the source photos) - we still had to integrate that into the application and manage persistence of the files and database records associated with them. (Similarly, as a convenience we allow import photo from url - another feature we had to explicitly create)
I would suggest that you will not find any general purpose component to integrate that will give you cropping functionality and a Web UI. I suppose there may be one made by a ASP.Net component vendor, but I am certainly not aware of any off-hand.
The problem tends to involve lots of pieces that span from the client to the server, and consequently I think what you are looking for will involve a fair amount of specific-to-your-application development and integration.
You can try ImageMagick, it supports hundreds of image formats and it comes with a .NET wrapper.
Have found exactly what i was looking for iLoad
Does exactly what i asked and doesn't cost that much compared to other suggested solutions. Haven't tried it yet but demo is impressive.
Have a look at mcImageManager
This is a bit special:
I'm loading some HTML in string form into the WebBrowser control via the DocumentText property.
Now when I print the page with a PDF printer (Bullzip PDF Printer in my case) it always takes the URL as document name which is "about:blank".
Is there any way to change this to another value by either changing the URL property (it's read-only) or by changing the print behaviour to use another text rather than the URL as filename?
There are a couple of options that I am aware of though my knowledge on this subject is a bit dated.
The first is to change the computer settings in Internet Options. Regardless of whether this is done by hand or through a registry change script, it is simple for the developer, but obviously not the best approach from the deployment or compatibility angles.
The next approach is to develop a custom print template. This is not fun, but is probably the most professional approach. As much as I would love to include all of the information needed on this approach in this post, it is too much to cover. Here is a good overview and good luck Googling from there.
My experience with this involved printing from the MS WebControl component used in a .NET 1.1 Winforms application to the Web Super Goo PDF converter component. Your mileage may vary.
You can change the header and footer such that the URL property is not printed.
Try to Navigate to a URL, then cancel that via DWebBrowserEvents::BeforeNavigate
Can anyone provide a good example of IHttpHnalder for handling Image Type. I want to resize the image that's hosted on my server
Problem using iHttpHandler
and
How to know which image has been requested
Both have examples of HTTPHandlers for serving images.
The answers by Zhaph and Ady seem to point in the right direction already, but if you need an additional example...
My article on BlobStreams for the Microsoft.NET Magazine here in Holland includes a very simple example of serving images from database BLOBs. Can't remember if the example used an IHttpHandler or a simple ASP.NET page, but for the code you need it really doesn't matter that much.
How About.
http://blog.jasonnussbaum.com/?p=104
Source is available in the downlaod.
If you are resizing GIF you may also want to look into image quantizing.