Click here to Skip to main content
15,887,343 members
Home / Discussions / WPF
   

WPF

 
QuestionWPF Combo Box SelectedValue = null issue Pin
Mhister Pamakwas25-Jun-14 11:54
Mhister Pamakwas25-Jun-14 11:54 
AnswerRe: WPF Combo Box SelectedValue = null issue Pin
Mycroft Holmes29-Jun-14 5:01
professionalMycroft Holmes29-Jun-14 5:01 
QuestionWPF RichTextBox Document Bind using Binding property Pin
moorthy00724-Jun-14 0:29
moorthy00724-Jun-14 0:29 
AnswerRe: WPF RichTextBox Document Bind using Binding property Pin
Richard Deeming24-Jun-14 0:43
mveRichard Deeming24-Jun-14 0:43 
QuestionDisplaying (Calling) 2 UserControl within a UserControl (WPF) Pin
LAPEC23-Jun-14 23:56
LAPEC23-Jun-14 23:56 
AnswerRe: Displaying (Calling) 2 UserControl within a UserControl (WPF) Pin
Matt T Heffron24-Jun-14 7:09
professionalMatt T Heffron24-Jun-14 7:09 
GeneralRe: Displaying (Calling) 2 UserControl within a UserControl (WPF) Pin
LAPEC24-Jun-14 7:32
LAPEC24-Jun-14 7:32 
QuestionAsync method using RenderTargetBitmap and BitmapEncoder Pin
FlurryKnox18-Jun-14 21:40
FlurryKnox18-Jun-14 21:40 
Hello

I am playing around with the async and await keywords using .net4.5 and windows 7.

The problem is that I would like to use RenderTargetBitmap and System.Windows.Media.Imaging.BitmapEncoder to capture a UI element and return a System.Drawing.Bitmap.

The following is some test code. The problem is that it does a lot of work synchronously (e.g. using FileStream and BitmapEnocder).

For this reason, the UI blocks most of the time e.g. the UI is non-responsive.

I was hoping some of the more experienced programmers here could advise me on where I have gone wrong or how best to proceed with this function?

Many thanks for your time....



private async Task<System.Drawing.Bitmap> GetCaptureBitmap(CaptureFrame captureFrame)
       {
           VisualBrush brush = new VisualBrush(captureFrame);

           brush.Stretch = Stretch.Fill;
           brush.AlignmentX = AlignmentX.Left;
           brush.AlignmentY = AlignmentY.Top;
           brush.TileMode = TileMode.None;

           Rectangle rect = new Rectangle();
           rect.Width = Settings.Instance.Capture.Width;
           rect.Height = Settings.Instance.Capture.Height;
           rect.Fill = brush;

           rect.Measure(new Size(rect.Width, rect.Height));
           rect.Arrange(new Rect(0, 0, rect.Width, rect.Height));

           System.Windows.Media.Imaging.RenderTargetBitmap bmp = new System.Windows.Media.Imaging.RenderTargetBitmap((int)rect.Width, (int)rect.Height, 96, 96, PixelFormats.Pbgra32);

           bmp.Render(rect);

           FileStream stream = new FileStream(System.IO.Path.GetTempFileName(), FileMode.Create, FileAccess.ReadWrite, FileShare.Read, 4096, FileOptions.DeleteOnClose);
           System.Windows.Media.Imaging.BitmapEncoder encoder = new System.Windows.Media.Imaging.BmpBitmapEncoder();
           encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(bmp));
           encoder.Save(stream);
           stream.Flush();

           System.Drawing.Bitmap bitmap = (System.Drawing.Bitmap)System.Drawing.Image.FromStream(stream, true, false);

           return bitmap;
       }

AnswerRe: Async method using RenderTargetBitmap and BitmapEncoder Pin
Gerry Schmitz19-Jun-14 13:39
mveGerry Schmitz19-Jun-14 13:39 
GeneralRe: Async method using RenderTargetBitmap and BitmapEncoder Pin
FlurryKnox20-Jun-14 6:34
FlurryKnox20-Jun-14 6:34 
GeneralRe: Async method using RenderTargetBitmap and BitmapEncoder Pin
Gerry Schmitz20-Jun-14 10:21
mveGerry Schmitz20-Jun-14 10:21 
GeneralRe: Async method using RenderTargetBitmap and BitmapEncoder Pin
Pete O'Hanlon20-Jun-14 10:48
mvePete O'Hanlon20-Jun-14 10:48 
GeneralRe: Async method using RenderTargetBitmap and BitmapEncoder Pin
Gerry Schmitz20-Jun-14 11:10
mveGerry Schmitz20-Jun-14 11:10 
GeneralRe: Async method using RenderTargetBitmap and BitmapEncoder Pin
Pete O'Hanlon20-Jun-14 11:16
mvePete O'Hanlon20-Jun-14 11:16 
GeneralRe: Async method using RenderTargetBitmap and BitmapEncoder Pin
FlurryKnox21-Jun-14 19:35
FlurryKnox21-Jun-14 19:35 
GeneralRe: Async method using RenderTargetBitmap and BitmapEncoder Pin
Gerry Schmitz22-Jun-14 1:51
mveGerry Schmitz22-Jun-14 1:51 
QuestionStarter MVVM Framework Recommendation Pin
cjb11018-Jun-14 2:58
cjb11018-Jun-14 2:58 
AnswerRe: Starter MVVM Framework Recommendation Pin
Pete O'Hanlon18-Jun-14 3:24
mvePete O'Hanlon18-Jun-14 3:24 
GeneralRe: Starter MVVM Framework Recommendation Pin
cjb11018-Jun-14 3:48
cjb11018-Jun-14 3:48 
GeneralRe: Starter MVVM Framework Recommendation Pin
Pete O'Hanlon18-Jun-14 4:09
mvePete O'Hanlon18-Jun-14 4:09 
AnswerRe: Starter MVVM Framework Recommendation Pin
Vincent Beek18-Jun-14 3:30
Vincent Beek18-Jun-14 3:30 
GeneralRe: Starter MVVM Framework Recommendation Pin
cjb11018-Jun-14 3:50
cjb11018-Jun-14 3:50 
AnswerRe: Starter MVVM Framework Recommendation Pin
Mycroft Holmes18-Jun-14 12:53
professionalMycroft Holmes18-Jun-14 12:53 
GeneralRe: Starter MVVM Framework Recommendation Pin
cjb11018-Jun-14 20:40
cjb11018-Jun-14 20:40 
GeneralRe: Starter MVVM Framework Recommendation Pin
Mycroft Holmes18-Jun-14 22:11
professionalMycroft Holmes18-Jun-14 22:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.