Lumia imaging crop filter - c#

Hi so I'm making an app for Windows 10 that requires a user to choose an image and it's going to crop the image to 310*128. I got the file picker code already. But I want to know how to actually crop and save the image and display in image box. I already have the xaml page done

With Lumia Imaging SDK you can both crop the selected image and resize the image. In this answer I assume you actually want to crop, but from the text I could just as well guess you really just want to resize.
For crop, use the CropEffect from Lumia.Imaging.Transforms. Set the CropArea property on it to the object, and then render it. If you are rendering straight to the XAML page I recommend using a SwapChainPanel object in XAML and a SwapChainPanelRenderer to render on it.
Given that you are loading a StorageFile and rendering to a SwapChainPanel your code might look like something like this:
StorageFile file = ...
using (var source = new StorageFileImageSource(file))
using (var crop = new CropEffect(source, new Rect(0, 0, 310, 128))
using (var renderer = new SwapChainPanelRenderer(crop, YourSwapChainPanel))
{
await renderer.RenderAsync();
}

Related

Xamarin: How do I place an image on top of another image at a specific pixel location

I have an app I need to build with Xamarin for iOS. I'm using Xamarin.Forms at the moment.
The app is a custom view of a garden that I will need to place plant markers on in the admin at a touch. I cannot find a way to composite these images in a way I can drive the display from a database and make the markers clickable.
Any help or guidance is appreciated.
In this case you need to use AbsoluteLayout
var layout = new AbsoluteLayout();
var image = new Image { Source = "foo.png" };
AbsoluteLayout.SetLayoutBounds (image , new Rectangle (.5, 1, .5, .1));
//("X, Y, Width, Height")
layout.Children.Add (bottomLabel);
Content = layout;
here just a sample of placing image from c#, you can customize this to your requirement

Image smoothing in UWP app

I have a small UWP application that load same image in two ways:
var folder = Package.Current.InstalledLocation;
var file = await folder.GetFileAsync("TestImage.png");
var bitmapImage1 = new BitmapImage();
using (var stream = await file.OpenAsync(FileAccessMode.Read))
{
await bitmapImage1.SetSourceAsync(stream);
}
var bitmapImage2 = new BitmapImage(new Uri(BaseUri, "TestImage.png"));
_image.Source = bitmapImage1;
//_image.Source = bitmapImage2;
The problem is that Image control shows the same image in different ways. For bitmapImage1 image is not smoothed, but for bitmapImage2 it's ok. How it looks like. I need to do some manipulation with image before show (change some pixels) but I also need to have smoothed image after that. Could you please help me with it?
I also used WriteableBitmap to change some pixels and have same result (not smoothed). Looks like I need to tell to Image control how to draw this.
Here is link to project for more information
I tested your code on my side. And you will found if you don't set the Height and Width properties for the image control, the pictures will looks all the same. So the reason for one looks smooth but another looks not is the image control scaling the picture. Without scaling the picture will not looks different. I guess this may be leaded but difference between vector and bitmap image.
You should be able to resolve it by create a smooth picture with the size you just want to show in the app, and set the image control to the same size with the picture or without setting the Height and Width properties, this may resolved.
My result:
I've got solution on another thread.
If change order of code lines it helps:
var folder = Package.Current.InstalledLocation;
var file = await folder.GetFileAsync("TestImage.png");
var bitmapImage1 = new BitmapImage();
_image.Source = bitmapImage1;
using (var stream = await file.OpenAsync(FileAccessMode.Read))
{
await bitmapImage1.SetSourceAsync(stream);
}
So we should assign Image source and than set source stream to Bitmap.
It seems, Image control decodes the picture quite flexibly so that it can suit for acutal UI size. If you set the BitmapImage to Image.Source first, the picture is to be smoothed properly like the second one.

Capturing images with blended images in nokia imaging sdk

I am making windows phone app using nokia imaging sdk and example of app is this real time blend demo
I am trying to capture image with Image overlayed image i.e image with other image in top of it as in above example in live camera stream below is code i am trying to capture image with effect
CameraCaptureSequence cameraCaptureSequence = App.Camera.CreateCaptureSequence(1);
MemoryStream stream = new MemoryStream();
cameraCaptureSequence.Frames[0].CaptureStream = stream.AsOutputStream();
await App.Camera.PrepareCaptureSequenceAsync(cameraCaptureSequence);
await cameraCaptureSequence.StartCaptureAsync();
stream.Seek(0, SeekOrigin.Begin);
MediaLibrary library = new MediaLibrary();
library.SavePictureToCameraRoll("picture1.jpg", stream);
but the above code only saves image without effect, so how to capture images with live blended effects from camera.
Basically what you have to do is attach the same effects/filters that you had in the preview to a new image source taking the captured photo stream instead. And probably use a different renderer too.
Either that or set up a duplicate set of filters for the capture. There are reasons to, you could e.g. configure lower quality effects in the preview to help performance.

TextBlock Rendered On WriteableBitmap on Windows Phone isn't as crisp

I'm working with Windows Phone 8/C# Silverlight and using code similar to this to render text:
TextBlock drawStringInstance = new TextBlock();
drawStringInstance.Text = str;
drawStringInstance.Opacity = 1;
drawStringInstance.Measure(new Size(1000000, 1000000));
WriteableBitmap wb = new WriteableBitmap((int)drawStringInstance.ActualWidth, height);
wb.Render(drawStringInstance, null);
wb.Invalidate();
Notice that I don't save the image and draw it directly so there shouldn't be any saving artifacts. If I just place the text block I get much crisper text with less aliasing as such (left is the "good" rendering):
Is there something I can do to improve this or is this an inherent issue with the approach of WriteableBitmap.Render()?
I think you're not supposed to render elements that are not in the visual tree. In fact , your code does not render anything on my emulator.
Just add the textblock somewhere on the page (perhaps set the margin to -1000 so that it does not show) , then render it.

Save as a image all the content of a grid

So, I'm trying to save an canvas content as an image. I'm using this for it:
var img = new WriteableBitmap(myCanvas, null);
Problem is that the image is not showing all the content inside of the canvas. If there's a button, an image or other similar objects, they do not show.
I can see an ellipse, but if I set an image as background, the background stays empty.
Is there anyway to solve this?
Try to use Image Tools from codeplex and read this and this

Categories