c# - Draw directly to PictureBox -


im developing screen-sharing app runs loop , receives small frames socket. next step draw them picturebox. of course use thread because dont want freeze ui.

this code:

 bitmap frame = bytearraytoimage(buff) bitmap;//a praticular bitmap im getting socket.  bitmap current =  (bitmap)picturebox1.image;  var graphics = graphics.fromimage(current);  graphics.drawimage(frame, left, top);//left , top 2 int variables of course.  picturebox1.image = current; 

but im getting error:

object in use elsewhere.

in line var graphics = graphics.fromimage(current);

tried clone it, create new bitmap(current).. still no sucess..

invalidate() picturebox redraws itself:

bitmap frame = bytearraytoimage(buff) bitmap; using (var graphics = graphics.fromimage(picturebox1.image)) {     graphics.drawimage(frame, left, top); } picturebox1.invalidate(); 

if need thread safe, then:

picturebox1.invoke((methodinvoker)delegate {     bitmap frame = bytearraytoimage(buff) bitmap;     using (var graphics = graphics.fromimage(picturebox1.image))     {         graphics.drawimage(frame, left, top);     }     picturebox1.invalidate(); }); 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -