Render an image in SurfaceImageSource with direct2D - c#

I'm making a Windows Store Application that display really big images in a ScrollViewer.
The source image is very big and the rendering with the Image is bad (because the Image is really smaller than the source image, so the scaling make the result ugly).
I want to use direct2D to have a better rendering (the project is in c#).
I'm really new to this, so I don't really know how to do... I've found those links that seems interesting:
XAML SurfaceImageSource DirectX interop sample (Windows 8.1)
How to Draw a BitmapSource Using Direct2D
The SurfaceImageSource sample is good, but only shows how to render sharpes...
And I don't know how to use the second links with SurfaceImageSource.
Is there anybody who have a good example about this? Thanks!

I think you can try VirtualSurfaceImageSource.It can render large image.
Learn more:
http://msdn.microsoft.com/en-us/library/windows/apps/hh825871.aspx

Related

Canvas to image in WinRT Code

In Win8 Metro apps i have a canvas it contains images and blocks and i want to save it to be displayed as an image using async, any idea with code?
Can't be done I'm afraid - WinRT has no way to save xaml to an image.
Your best bet would be to handcraft your own bitmap, but it's a lot of work.
Sorry, I could have done with this functionality to!

how to save Canvas as image in WINRT using c# [duplicate]

I am developing a paint like application in metro style with C#/XAML. I want to save whatever content is drawn on canvas as image. I have checked this solutions but it didn't helped me.
Save canvas to bitmap
http://blogs.msdn.com/b/saveenr/archive/2008/09/18/wpf-xaml-saving-a-window-or-canvas-as-a-png-bitmap.aspx
So how can I save the canvas content as image ? Please help me with sample coding.
The accepted answer from Sascha is no longer true for Windows 8.1. There is a new RenderTargetBitmap class that allows Rendered XAML to be converted to a bitmap.
See: http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.media.imaging.rendertargetbitmap.aspx
However I can't seem to render that XAML is Collapsed or otherwise not currently on screen. Any help with that would be appreciated!
It seems it is currently not supported out of the box like we were used to do it with WPF:
http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/dd66c749-efed-4b55-a716-e0aa3a637d28
While when doing HTML5/Javascript Metro apps you can do this:
http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/cf8c17dc-68d4-4777-951f-bb7f0665bd06
The standard approach in other xaml frameworks such as Silverlight and WP7 was to use WriteableBitmap, however the version in WinRT doesn't have a constructor that takes a xaml element which leads me to believe that it's currently impossible against the latest API.
Sorry I couldn't be more help/
One workaround is to use Direct2D with DirectWrite. It is a bit involved, but I might make a library available at some point.

Windows 8 Metro App - Render PNGs

I am needing to render some custom PNGs in a Windows 8 app.
Basically I need to create a custom live tile by putting some drawings made in my app on top of an image for a live tile, and the only way to do this is render a PNG to disk, see here.
What library should I use to do this? My first thought was to use a Xaml UserControl and RenderTargetBitmap, but it is not available in a Metro app.
WinRT XAML Toolkit has some extension methods for WriteableBitmap that you could use too. You could probably use WriteableBitmapLoadExtensions for loading and WriteableBitmapSaveExtensions for saving. It has a fairly limited blitting capability though since that is exposed by WriteableBitmapEx already and simple to write anyway. WriteableBitmapBlitBlockExtensions is only a method to blit a full width block of pixels from bitmaps of same width.
Edit* RenderTargetBitmap is now available in Windows 8.1. It doesn't support some elements though (I think it doesn't render camera previews, media elements and perhaps WebViews).
Currently the only option is to use DirectX (or SharpDX) to create your image. You'll probably have to recreate the drawing using the low-level DirectX APIs.
WritableBitmapEx might also be helpful if your drawings are simple.

Simple component to crop a picture with rectangle box in c#.net windows application

I want a simple component to crop a picture with Rectangle box in c#.net windows application.what component can i use?(free or purchase)
Here's some code I wrote to resize an image. The code will also trim the image if needed.
It provides an example of cropping and could easily be modified to be a more general "cropper" class.
I used ClearImage for image manipulation at a previous job. I found it very easy to use, with good performance and it would serve your purpose perfectly.
There is also AForge, a open source image manipulation library. A little more powerfull, with a lot of features, but also a little more complicated.
Or you could design your own using the PictureBox and the Bitmap class. A lot of work, and probably not very performant if you don't know what you're doing...

Choosing the right image size in Compact Framework

i'm developping an application in CF 3.5 for windows Mobile 6 Pro using C# and i have a little issue requiring the advice of someone that knows better.
Basically, i want my application to run and scale on multiple device sizes and resolutions. Eveything scales properly but the images.
Some images that are for example 16X16 will look very small on a high resolution screen, so I want to display a 32X32 image, but I don't know what's the best way to decide which image size to display.
I have the option to check the dpi and then manually choose which image to display, but it seems like dirty work.
Isn't there any way to do it otherwise or what's the best way to do it?
I recommend that you create a layer between your forms and the images. Create a new class that would be responsible for returning the correct sized image. The code in your forms will rely on that to get the image and would have to know nothing about the sizes. For example:
mypicturebox.Image = ImageFactory.Image01;
The good thing is that you can use any technique you want inside the ImageFactory without affecting the rest of the code. The easiest thing to do is to check the size of the screen (using Screen.PrimaryScreen.WorkingArea) and do a manual decision.

Categories