private void WriteScreenShot() { var format = System.Drawing.Imaging.PixelFormat.Format32bppRgb; RecalcCanvas(format); this.Dispatcher.BeginInvoke((Action) delegate() { Bitmap screen = UtilDrawing.TakeScreen(format).TransformImage2(_width, _height); // saves file //var fileName = tmpPath + "filename2.jpeg"; //var fileName2 = tmpPath + "filename3.jpeg"; //newImg.Save(fileName, ImageFormat.Png); // opens explorer and selects file //string argument = "/select, \"" + fileName + "\""; //Process.Start("explorer.exe", argument); // write bitmap to writablebitmap //var bpp = Utilities.GetBytesPerPixel(format); //int stride = Utilities.GetStride(_bpp, _width); byte[] pixels = new byte[UtilDrawing.GetSize(_stride, screen.Height)]; BitmapSource baseLayer = UtilDrawing.CreateBitmapSourceFromBitmap(screen, System.Drawing.Imaging.ImageFormat.Bmp); baseLayer.CopyPixels(pixels, _stride, 0); _writablebitmap.WritePixels(_rect, pixels, _stride, 0); }, DispatcherPriority.Render); }
public void WriteOnlinePicture() { PrepareCanvas(); //Uri uri = new Uri(TextBoxURL.Text); //BitmapImage bitmapImage = new BitmapImage(); //bitmapImage.CreateOptions = BitmapCreateOptions.None; ////bitmapImage.ImageOpened += ImageOpened; //bitmapImage.UriSource = uri; //ImageTest.Source = new WriteableBitmap(bitmapImage); try { WebClient client = new WebClient(); Bitmap bitmap; using (Stream BitmapStream = client.OpenRead(TextBoxURL.Text)) { Image img = Image.FromStream(BitmapStream); img = img.CopyWithTransparency(); bitmap = new Bitmap(img); } //Stream stream = client.OpenRead(TextBoxURL.Text); //var bitmap = new Bitmap(stream); //stream.Flush(); //stream.Close(); //var fileName = tmpPath + "filename.jpeg"; //bitmap.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg); //Console.WriteLine("Image written as " + fileName); var baseLayer = UtilDrawing.CreateBitmapSourceFromBitmap(bitmap, System.Drawing.Imaging.ImageFormat.Bmp); //var format = System.Drawing.Imaging.PixelFormat.Format32bppArgb; var format = System.Drawing.Imaging.PixelFormat.Format32bppRgb; //var format = baseLayer.Format; var bpp = UtilDrawing.GetBytesPerPixel(format); var stride = UtilDrawing.GetStride(bpp, bitmap.Width); var pixels = new byte[UtilDrawing.GetSize(stride, bitmap.Height)]; baseLayer.CopyPixels(pixels, stride, 0); _writablebitmap.WritePixels(new Int32Rect(0, 0, baseLayer.PixelWidth, baseLayer.PixelHeight), pixels, stride, 0); } catch (Exception e) { Console.WriteLine(e.Message); } }