Scale/Resize very large image in Windows Store Application and save it to jpg stream in C#

public async void PhotoPicked(IReadOnlyList<StorageFile> files)
{
	StorageItemThumbnail resizedImage = await files[0].GetScaledImageAsThumbnailAsync(ThumbnailMode.SingleItem, 1024, ThumbnailOptions.None);
	imageStream = await SaveImageToJpegStream(resizedImage);//resizedImage.AsStreamForRead();
 }

public async static Task<Stream> SaveImageToJpegStream(StorageItemThumbnail resizedImage)
{
	var bm = new WriteableBitmap(1, 1);
	await bm.SetSourceAsync(resizedImage.CloneStream());

	var stream = new InMemoryRandomAccessStream();

	BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream);
	// Get pixels of the WriteableBitmap object 
	Stream pixelStream = bm.PixelBuffer.AsStream();
	byte[] pixels = new byte[pixelStream.Length];
	await pixelStream.ReadAsync(pixels, 0, pixels.Length);
	// Save the image file with jpg extension 
	encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)bm.PixelWidth, (uint)bm.PixelHeight, 96.0, 96.0, pixels);
	await encoder.FlushAsync();

	stream.Seek(0);
	return stream.AsStream();
}