I'm trying to take a screenshot of a subclassed XNA DrawingSurface element from within a silverlight 5 application. This sl app will run inside an aspx page.
Here's what I've tried so far without success:
WriteableBitmap bmp = new WriteableBitmap(LayoutRoot, null);
testImage.Source = bmp;
with LayoutRoot being the parent control on the silverlight page and testImage is just an Image control on the page to see if the screenshot is correct.
This will render all the silverlight controls on the page just fine, but the drawingsurface part remains empty. In other words the XNA content is not rendered into the image.
I've also tried to render the XNA content to a RenderTarget2D, but the silverlight version of the render target does not seem to have any methods to save the data. I saw some WP7 examples that used a method called SaveAsJpeg(), but that doesn't seem to be available in the SL5 version of the class.
I would appreciate any help with this.
Greets,
Floris
One possibility would be to draw your screen into a RenderTarget2D and then use the method SaveAsPng like:
using (Stream stream = File.OpenWrite("filename.png"))
{
renderTarget2D.SaveAsPng(stream, renderTarget2D.Width, renderTarget2D.Height);
}
Related
I've seen a couple posts about the UIImage automatically loading the filename-568.png image in the new iOS6, but I can't seem to recreate it in the UIImageView class.
I'm using the Storyboard (not my app, just having to do some checks), and I've a simple layout with just the Image View scaled to fit, no code in the view controller, and I've sure the filename.png and filename-568h.png exist (as well as -568#2x.png just in case) but when I load it up in the iOS6 simulator. This has been for iOS 4 and 5, loading the #2x image for retina, doesn't seem to work in iOS6 though. Any ideas?
The image happens to be called Default.png since it is the same as the launch image, could this be the issue?
Thanks for any help in advance
iOS6 does NOT automatically load -568h as it does with the #2x images. The only exception is the default screen, but further than that you have to manually set you 568h image yourself.
I created some code to mimic the loading behavior for -568h images when using the [UIImage imageNamed:#""] method, but from the IB I do not know the way. If you are interested in such a solution, check it out at http://angelolloqui.com/blog/20-iPhone5-568h-image-loading
Typically, you should only use 568h for the launch image. If you notice yourself using different image assets within your app for the new display height, you should consider that you might be making your UI too static.
The most obvious place people want to use 568h for images is for background images. An alternative is to just have one asset that has the largest possible dimensions and align it properly using the contentMode property of UIView.
But perhaps you have something floating in the image at the top and the bottom, so contentMode doesn't solve it. You could consider that the top and bottom floaters should probably be separate views anyway.
Remember, we have always been making apps with variable heights. Every time a keyboard pops up, its as if the size of the screen has shrunk.
I'm working on a module that displays DWG files in WPF. I've managed to use CadLib library but it's working very slowly and I want to make it faster. I found out that if I convert that DWG file to SVG format and then print it to my XPS printer and rename the file to ZIP, I can get .page file which is basically a XAML file that displays the original SVG object in XAML.
I want to display this XAML code on a custom control and be able to pan / zoom it around. I tried to place this XAML code in a Canvas and it did manage to show up there, but now I'm stuck trying to pan / zoom the shape that was drawn there. Also, the mouse events are fired only when you click the actual drawing itself, and not the Canvas, which will be hard for the user to click...
Any help would be highly appreciated :)
You could try creating nested Canvases : One that holds the vectors and is moved on demand, one that is fixed and serves as the viewport. Haven't tried that, but it should be feasible...
I want to convert a xaml canvas to a png image using c#. I used RenderTargetBitmap as described in the second post here. It works quite well if the xaml that's meant to be converted is displayed in a window or a page and you can actually see it on screen. But if the window is closed or hidden or the canvas isn't a child of a window / page / frame, a blank image will be generated. Does anyone know why this happens or how to make it work?
I can't be sure but it may be that WPF is saving time by not rendering anything that isn't currently on screen, therefore when you grab the bitmap from the render target for that object, it hasn't been rendered and so it is blank.
I would suggest putting it on screen for the duration of your capture and then remove it. If the object is small it may even appear and disappear in no more than a flicker.
I would like to build a navigation enabled Silverlight app with a slight difference. I don't want to load the entire screen area just a part of it and only in some scenarios.
For example #/Customer/Cases loads /Customer/Cases.xaml in the entire screen area. But #/Customer/Cases/Orders loads /Customer/Cases/Orders.xaml in an area where a data grid was displayed (slides to the right maybe).
How do I tell the parent navigation frame not to load the entire #URL but just a part of it? And vis versa for the child navigation frame?
Has anyone done anything like this before?
Please let me know if doesn't make any sense, it's quite hard to explain :)
One possibility would be to have two frames.
In the inner-frame you set:
InnerFrame.JournalOwnership = JournalOwnership.OwnsJournal;
The link #/Customer/Cases/Orders loads the page /Customer/Cases.xaml?Orders in the outer-frame. The outer-frame than knows it should navigate the inner frame to /Customer/Cases/Orders.xaml
Check out Ultimate Framework - Silverlight Navigation Framework that supports unlimited parallel and nested frames with Prism
I am working through the above Tutorial from ScottGu located here (http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-6-using-user-controls-to-implement-master-detail-scenarios.aspx) and I am trying to figure how when the UserControl loads, the background page is 'grayed' out like that? Where is that code for that?
I am trying to extract that logic into my own Page / UserControl scenario and when I load the UC, the background is still fully 'visible'. Thanks for any advice!
Under the heading Building a Basic Modal Dialog Using a User Control, Scott's post describes:
"The first control above is configured to stretch to take up all of the available space on the screen. Its background fill color is a somewhat transparent gray (because its Opactity is .765 you can see a little of what is behind it). The second control will then be layered on top of this Rectangle control, and take up a fixed width on the screen."
The Rectangle "grays out" the contents of the screen.