Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

WriteableBitmap - Any to way use it for printing, at le... RSS

25 replies

Last post May 20, 2010 05:04 AM by vijay.gonela

(0)
  • GA30

    GA30

    Member

    33 Points

    57 Posts

    WriteableBitmap - Any to way use it for printing, at least indirectly

    May 11, 2009 08:08 PM | LINK

    Hello All,

    I am taking a look at this WriteableBitmap class and am trying to figure out whether I can somehow use it for client side printing. At a very high level I was thinking about rendering UI elements on it and then somehow place the resulting image on a plane old web page. That's where I am stuck. How would I go about placing the resulting image in a web page. I was thinking about using the "data URL scheme" but it does not appear IE7 and below support this whereas other browsers do. Anyone have any insight? Thanks in advance

  • SharpGIS

    SharpGIS

    Contributor

    4825 Points

    832 Posts

    Re: WriteableBitmap - Any to way use it for printing, at least indirectly

    May 12, 2009 02:54 AM | LINK

    I'm actually just think I found a way to do this today, but currently working out the kinks. Keep an eye on my blog (www.sharpgis.net) the next couple of days. However, it will have limitations in the current beta (a limitation that should be gone with the RTW version).
    --
    /Morten | Silverlight MVP | blog - twitter
    Please click on "Mark as Answer" if this answered your question.
  • GA30

    GA30

    Member

    33 Points

    57 Posts

    Re: WriteableBitmap - Any to way use it for printing, at least indirectly

    May 12, 2009 03:46 AM | LINK

    I'll be waiting! [:D]

  • SharpGIS

    SharpGIS

    Contributor

    4825 Points

    832 Posts

    Re: Re: WriteableBitmap - Any to way use it for printing, at least indirectly

    May 12, 2009 05:47 AM | LINK

    Been tinkering some more and getting closer, however this approach doesn't seem to work for IE6 and 7, without an extra serverside component. Are you cool with that?
    And as I mentioned this will require SL3 RTW which isn't out yet, unless you can do with either Joe Stegmans bitmap API (http://blogs.msdn.com/jstegman/archive/2008/04/27/updated-png-generator-sample.aspx) for SL2 or the current SL3 Writeable bitmap WITHOUT using render*, meaning that for both cases, you can only use the lowlevel SetPixel(x,y,color).
    I should have this written up nicely by tomorrow night (PST), but to give you a hint, this is what I'm using: http://www.websiteoptimization.com/speed/tweak/inline-images/

    *calling Render() prevents you from getting to the individual pixels in the current beta, but the SL team promised that that limitation is being removed.
    --
    /Morten | Silverlight MVP | blog - twitter
    Please click on "Mark as Answer" if this answered your question.
  • ksleung

    ksleung

    Contributor

    6680 Points

    1265 Posts

    Re: Re: WriteableBitmap - Any to way use it for printing, at least indirectly

    May 12, 2009 06:34 AM | LINK

    SharpGIS,

    Are you sure Data URL will work?  I have tried it in the past, and besides from the fact that IE didn't support it (don't know about IE8), there may be some limitations posed by FF et al, in that they may choke if the Data URL is longer than a certain length.   If I rememberr correctly one browser puts a limit of 64KB data.  I actually looked into using Data URL a while back in SL2 timeframe, mainly to work around the absense of SaveFileDialog.  Wasn't very successful then for various reasons (Javascript hacking not my forte to begin with).

    Anyway, another approach that I know will definitely work on FF is to use Addons screen capture, bounce the image to a server and back to the client to be printed.  An example screen capture utility is Pixlr.  Since FF addons are nothing more than zipped Javascripts + XUL, it is easy to reverse-engineer and fit it to your need.  The advantage of addon-based screen capture is that there is no "Render()" restriction.  Moreover, if Data URL works for you, you don't need server roundtrip to print, which is nice.

    Anyway just fruit for thought.

    Visit http://www.tagxedo.com, a Silverlight-based word cloud generator. If you like it, please help me spread the word!
  • SharpGIS

    SharpGIS

    Contributor

    4825 Points

    832 Posts

    Re: Re: Re: WriteableBitmap - Any to way use it for printing, at least indirectly

    May 12, 2009 06:47 AM | LINK

    This image is 2mb base64 encoded (it's essentially an uncompressed PNG) and seems to work just fine in FireFox and Chrome. Should work with IE8 but haven't tested that yet.

    However I think I just hit a MAJOR future roadblock. If what they discuss in this post (http://silverlight.net/forums/t/88783.aspx) is true, I'm pretty much screwed, since I'm merging cross domain images.
    --
    /Morten | Silverlight MVP | blog - twitter
    Please click on "Mark as Answer" if this answered your question.
  • ksleung

    ksleung

    Contributor

    6680 Points

    1265 Posts

    Re: Re: Re: WriteableBitmap - Any to way use it for printing, at least indirectly

    May 12, 2009 07:07 AM | LINK

    That explained why you said that the security restriction will be "removed" in RTW, when the better term would be "relaxed"...

    I was on several of those threads, and I think the SL team's concern was legit and they were right to disable it until they figure out the correct formula.

    I thought about how Adobe handles this, and it probably boils down to the difference between printing (allowed) and screen capture (not allowed, I presume?).  This is anologous to why we can "Render()" for display purpose but not "Render()" for access purpose.  Since your route to printing goes through screen capture, it is indeed a major roadblock...

    Perhaps the FF addon based solution is the only way to go then, but then it is doing nothing more than exposing a backdoor.  Hmm, make me think twice about addons...

    P.S. Actually, if it is possible to render ANY control to a WriteableBitmap, isn't printing a trivial thing to support?  Just have a special PrintableBitmap that you can render anything into, but that image can only be printed by user-triggered "print" action and is unreadable otherwise.  Am I missing something?

    Visit http://www.tagxedo.com, a Silverlight-based word cloud generator. If you like it, please help me spread the word!
  • SharpGIS

    SharpGIS

    Contributor

    4825 Points

    832 Posts

    Re: Re: Re: Re: WriteableBitmap - Any to way use it for printing, at least indirectly

    May 12, 2009 07:14 AM | LINK

    Not all browsers print the plugin correctly. That's why I want to go into HTML instead for that, or for more advanced stuff generate a PDF using a round-trip.

    Can you elaborate what the security concern is? As I see it, it's just a set of dumb bytes generated by the Silverlight API (not the original bytes), so I fail to see why an int array can be so dangerous. Not that I'm doubting it, only that I absolutely don't get it :)
    --
    /Morten | Silverlight MVP | blog - twitter
    Please click on "Mark as Answer" if this answered your question.
  • ksleung

    ksleung

    Contributor

    6680 Points

    1265 Posts

    Re: Re: Re: Re: WriteableBitmap - Any to way use it for printing, at least indirectly

    May 12, 2009 07:27 AM | LINK

    Supposedly if the content of certain controls is from some secured source (the example cited was image of your bank cheque), you don't want other controls to have access to them.  But if the content is generated by the application itself (say direction API manipulation or in the clear Uri), it shouldn't be disallowed.  Right now everything is disallowed.

    Despite what I just said, I'm not sure whether I get it either :)  But that's not important, since for Silverlight to be successful (as in adoption rate), it NEEDS to be secure.  At least it needs to give people the impression of being secure :D

    Visit http://www.tagxedo.com, a Silverlight-based word cloud generator. If you like it, please help me spread the word!
  • SharpGIS

    SharpGIS

    Contributor

    4825 Points

    832 Posts

    Re: Re: Re: Re: Re: WriteableBitmap - Any to way use it for printing, at least indirectly

    May 12, 2009 08:46 AM | LINK

    OK that makes sense, although in that case the cross domain policy file could solve this.
    --
    /Morten | Silverlight MVP | blog - twitter
    Please click on "Mark as Answer" if this answered your question.