Click here to Skip to main content
15,905,233 members
Home / Discussions / WPF
   

WPF

 
QuestionWPF - PRism Framework Pin
Muhammed Nigil29-Jun-14 23:36
professionalMuhammed Nigil29-Jun-14 23:36 
AnswerRe: WPF - PRism Framework Pin
Pete O'Hanlon30-Jun-14 0:17
mvePete O'Hanlon30-Jun-14 0:17 
GeneralRe: WPF - PRism Framework Pin
Muhammed Nigil30-Jun-14 1:00
professionalMuhammed Nigil30-Jun-14 1:00 
GeneralRe: WPF - PRism Framework Pin
Pete O'Hanlon30-Jun-14 3:03
mvePete O'Hanlon30-Jun-14 3:03 
GeneralRe: WPF - PRism Framework Pin
Muhammed Nigil30-Jun-14 18:56
professionalMuhammed Nigil30-Jun-14 18:56 
GeneralRe: WPF - PRism Framework Pin
Muhammed Nigil30-Jun-14 19:26
professionalMuhammed Nigil30-Jun-14 19:26 
QuestionHow to display from nested usercontrol another usercontrol class on button click event? Pin
LAPEC29-Jun-14 7:12
LAPEC29-Jun-14 7:12 
QuestionHow to Display .aspx page in SilverlightWeb Application Pin
RavitejaPammi28-Jun-14 5:22
RavitejaPammi28-Jun-14 5:22 
Questionsilverlight Pin
Member 1087962427-Jun-14 19:40
Member 1087962427-Jun-14 19:40 
AnswerRe: silverlight Pin
Pete O'Hanlon29-Jun-14 6:51
mvePete O'Hanlon29-Jun-14 6:51 
GeneralRe: silverlight Pin
Jammer30-Jun-14 23:32
Jammer30-Jun-14 23:32 
GeneralRe: silverlight Pin
Pete O'Hanlon30-Jun-14 23:59
mvePete O'Hanlon30-Jun-14 23:59 
GeneralRe: silverlight Pin
thatraja30-Jun-14 23:52
professionalthatraja30-Jun-14 23:52 
GeneralRe: silverlight Pin
Pete O'Hanlon1-Jul-14 0:10
mvePete O'Hanlon1-Jul-14 0:10 
QuestionRepost from C# forum WPF app Pin
Wesley2026-Jun-14 23:26
Wesley2026-Jun-14 23:26 
AnswerRe: Repost from C# forum WPF app Pin
Mycroft Holmes29-Jun-14 4:55
professionalMycroft Holmes29-Jun-14 4:55 
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 

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.