protected override void OnPictureReceived(object sender, PictureReceivedEventArgs e) { // Override OnPictureReceived so that only one instance of the PictureView is used. }
// Handler for when a picture arrives from a connected device. protected async virtual void OnPictureReceived(object sender, PictureReceivedEventArgs e) { await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { this.Frame.Navigate(typeof(PictureView), this.AlbumName); }); }
void EyeFiServerInstance_OnPictureReceived(object sender, PictureReceivedEventArgs e) { using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream imageStream = store.OpenFile(e.ImagePath, FileMode.Open)) { BitmapImage bm = new BitmapImage(); bm.SetSource(imageStream); WriteableBitmap wb = new WriteableBitmap(bm); int originalHeight = wb.PixelHeight; int originalWidth = wb.PixelWidth; int height, width; string thumbPath = e.ImagePath.Replace(viewModel.DownloadLocation,viewModel.ThumbnailLocation); if (originalHeight > originalWidth) { height = 1000; width = 1000 * originalWidth / originalHeight; } else { width = 1000; height = 1000 * originalHeight / originalWidth; } using (IsolatedStorageFileStream thumbStream = store.OpenFile(thumbPath, FileMode.Create)) { wb.SaveJpeg(thumbStream, width, height, 0, 80); BitmapImage tBm = new BitmapImage(); tBm.SetSource(thumbStream); if (viewModel.IsImagesLoaded) { viewModel.ImageCollection.Add(new ImageItem { FileDate = DateTime.Now, FullImagePath = e.ImagePath, ThumbSource = tBm, IsFavorite = false }); } } } } }
async void StartReceivePic(DataReader socketReader) { try { uint bytesRead = await socketReader.LoadAsync(sizeof(uint)); if (bytesRead > 0) { uint strLength = (uint)socketReader.ReadUInt32(); bytesRead = await socketReader.LoadAsync(strLength); if (bytesRead > 0) { byte[] bytesIn = new byte[bytesRead]; Debug.WriteLine("ReadBytes"); socketReader.ReadBytes(bytesIn); Debug.WriteLine("ReadBytes End"); // Raise PicReceived event if (PictureReceived != null) { PictureReceivedEventArgs args = new PictureReceivedEventArgs(); args.Bytes = bytesIn; PictureReceived(this, args); } StartReceivePic(socketReader); // Start another reader } else { SocketError("The remote side closed the socket"); socketReader.Dispose(); UpdateConnectionStatus(ConnectionStatus.Disconnected); } } else { SocketError("The remote side closed the socket"); socketReader.Dispose(); UpdateConnectionStatus(ConnectionStatus.Disconnected); } } catch (Exception e) { if (!_socketClosed) { SocketError("Reading from socket failed: " + e.Message); } socketReader.Dispose(); } }