public bool Open() { if (m_fileStream == null) { BasePath = Properties.Settings.Default.PrefDownloadDir; if (String.IsNullOrWhiteSpace(BasePath)) { BasePath = ReceiveFilesManager.GetDefaultDownloadDirectory(); } TempFilePath = BasePath + Path.DirectorySeparatorChar + FileName + ".part"; for (int i = 1; File.Exists(TempFilePath); i++) { TempFilePath = BasePath + Path.DirectorySeparatorChar + FileName + i.ToString() + ".part"; } try { Directory.CreateDirectory(BasePath); m_fileStream = new FileStream(TempFilePath, FileMode.CreateNew, FileAccess.Write, FileShare.Read); Log.d(TAG, "Created new file for receiving: " + TempFilePath); return(true); } catch (Exception e) { Log.w(TAG, "Error opening file (creating directory or file) " + TempFilePath + " - " + e.Message); return(false); } } else { return(false); } }
public async Task SaveScreenCapAsync(String strPath = null, String strFileName = null) { if (CurrentScreenCap == null) { return; } String strFullPath; if (strPath == null) { strPath = Properties.Settings.Default.PrefDownloadDir; if (String.IsNullOrWhiteSpace(strPath)) { strPath = ReceiveFilesManager.GetDefaultDownloadDirectory(); } } if (strFileName == null) { String strName = "wireboard-" + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Hour + "h" + DateTime.Now.Minute + "m"; strFullPath = strPath + Path.DirectorySeparatorChar + strName + ".png"; for (int i = 2; File.Exists(strFullPath); i++) { strFullPath = strPath + Path.DirectorySeparatorChar + strName + "-" + i + ".png"; } } else { strFullPath = strPath + Path.DirectorySeparatorChar + strFileName; } try { await Task.Run(() => { BitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(CurrentScreenCap)); using (var fileStream = new FileStream(strFullPath, FileMode.Create)) { encoder.Save(fileStream); } }); Log.i(TAG, "Saved screen capture as " + strFullPath, true); } catch (Exception e) { Log.e(TAG, "Failed to save screen capture. Error: " + e.Message, true); } }
public async Task SaveScreenCapAsync(String strPath = null, String strFileName = null) { WriteableBitmap writeableBitmap; lock (m_decoderLock) { if (m_lastDecodedFrame == null || State != EState.ACTIVE) { return; } TransformParameters transformParameters = new TransformParameters(RectangleF.Empty, new System.Drawing.Size(m_lastDecodedFrame.Parameters.Width, m_lastDecodedFrame.Parameters.Height), ScalingPolicy.RespectAspectRatio, PixelFormat.Bgra32, ScalingQuality.Bicubic); writeableBitmap = new WriteableBitmap( m_lastDecodedFrame.Parameters.Width, m_lastDecodedFrame.Parameters.Height, ScreenInfo.DpiX, ScreenInfo.DpiY, PixelFormats.Pbgra32, null); m_lastDecodedFrame.TransformTo(writeableBitmap.BackBuffer, writeableBitmap.BackBufferStride, transformParameters); writeableBitmap.Freeze(); } String strFullPath; if (strPath == null) { strPath = Properties.Settings.Default.PrefDownloadDir; if (String.IsNullOrWhiteSpace(strPath)) { strPath = ReceiveFilesManager.GetDefaultDownloadDirectory(); } } if (strFileName == null) { String strName = "wireboard-" + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Hour + "h" + DateTime.Now.Minute + "m"; strFullPath = strPath + Path.DirectorySeparatorChar + strName + ".png"; for (int i = 2; File.Exists(strFullPath); i++) { strFullPath = strPath + Path.DirectorySeparatorChar + strName + "-" + i + ".png"; } } else { strFullPath = strPath + Path.DirectorySeparatorChar + strFileName; } try { await Task.Run(() => { BitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(writeableBitmap)); using (var fileStream = new FileStream(strFullPath, FileMode.Create)) { encoder.Save(fileStream); } }); Log.i(TAG, "Saved screen capture as " + strFullPath, true); } catch (Exception e) { Log.e(TAG, "Failed to save screen capture. Error: " + e.Message, true); } }