Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
hauerCodes committed Dec 17, 2014
1 parent 74fc561 commit 98aec07
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion NumberRecognizer/NumberRecognizer.App/Help/LabelingHelperRT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
//-----------------------------------------------------------------------


using Windows.Graphics.Imaging;
using Windows.Storage;
using Windows.Storage.Streams;

namespace NumberRecognizer.App.Help
{
using System;
Expand Down Expand Up @@ -38,7 +42,9 @@ public static async Task ConnectedComponentLabelingForInkCanvasRT(InkCanvasRT in
inkCanvas.RefreshCanvas();
var renderTargetBitmap = new RenderTargetBitmap();
await renderTargetBitmap.RenderAsync(inkCanvas);


await SaveVisualElementToFile(renderTargetBitmap, await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync("testimage.png", CreationCollisionOption.ReplaceExisting));

byte[] canvasRGBABytes = (await renderTargetBitmap.GetPixelsAsync()).ToArray();
byte[] canvasBytes = ImageHelperRT.GetByteArrayFromRGBAByteArray(canvasRGBABytes, inkCanvas.ForegroundColor, inkCanvas.BackgroundColor);

Expand Down Expand Up @@ -100,5 +106,25 @@ public static async Task ConnectedComponentLabelingForInkCanvasRT(InkCanvasRT in
}
}
}

async static Task SaveVisualElementToFile(RenderTargetBitmap bitmap, StorageFile file)
{

var pixels = await bitmap.GetPixelsAsync();

using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
var encoder = await
BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream);
byte[] bytes = pixels.ToArray();
encoder.SetPixelData(BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Ignore,
(uint)bitmap.PixelWidth, (uint)bitmap.PixelHeight,
96, 96, bytes);

await encoder.FlushAsync();
}
}

}
}

0 comments on commit 98aec07

Please sign in to comment.