Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private async void CreateSaveBitmapAsync(List<Canvas> results)
- {
- Client client = new Client("127.0.0.1", "13000");
- var picker = new FileSavePicker();
- picker.FileTypeChoices.Add("Tiff Image", new string[] { ".tiff" });
- StorageFile file = await picker.PickSaveFileAsync();
- if (file == null)
- {
- return;
- }
- using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
- {
- var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.TiffEncoderId, stream);
- for (int i = 0; i < results.Count; i++)
- {
- Canvas canvas = results[i];
- RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
- await renderTargetBitmap.RenderAsync(canvas);
- if (canvas != null)
- {
- if (file != null)
- {
- var pixels = await renderTargetBitmap.GetPixelsAsync();
- byte[] bytes = pixels.ToArray();
- encoder.SetPixelData(BitmapPixelFormat.Bgra8,
- BitmapAlphaMode.Ignore,
- (uint)canvas.Width, (uint)canvas.Height,
- 96, 96, bytes);
- await encoder.GoToNextFrameAsync();
- }
- }
- }
- }
- client.SendToServer(file);
- }
- public async void SendToServer(byte[] bytes)
- {
- if (!_connected)
- {
- Debug.WriteLine("Must be connected to send!");
- return;
- }
- Int32 len = 0; // Gets the UTF-8 string length.
- //while (true)
- //{
- try
- {
- Debug.WriteLine("Trying to send data ...");
- DataWriter writer = new DataWriter(_clientSocket.OutputStream);
- writer.WriteUInt32((uint)(bytes.Length));
- writer.WriteBytes(bytes);
- // Call StoreAsync method to store the data to a backing stream
- await writer.StoreAsync();
- Debug.WriteLine("Data was sent" + Environment.NewLine);
- // detach the stream and close it
- writer.DetachStream();
- writer.Dispose();
- }
- }
- public Image byteArrayToImage(byte[] byteArrayIn)
- {
- MemoryStream ms = new MemoryStream(byteArrayIn);
- ms.Write(byteArrayIn, 0, byteArrayIn.Length);
- Image returnImage = Image.FromStream(ms);
- return returnImage;}
- An exception of type 'System.ArgumentException' occurred in System.Drawing.dll but was not handled in user code
- Additional information: Parameter is not valid.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement