C# PictureBox.SizeMode = Zoom does not redraw when assigning new imagesC# Bitmap LockBits/UnlockBits in multi-threadWhat does the [Flags] Enum Attribute mean in C#?When to use static classes in C#Why does C# forbid generic attribute types?Does C# have extension properties?winform picturebox image shows empty c#How to move elements within picturebox?Picturebox getting big red X but I can't detect or fix itVisual Studio Forms: Locate Image File of PictureBox?C# Moving Bitmap Image/Getting PixelsC# Bitmap LockBits/UnlockBits in multi-thread
What is the period/term used describe Giuseppe Arcimboldo's style of painting?
Showing mass murder in a kid's book
Started in 1987 vs. Starting in 1987
Capacitor electron flow
How do you say "Trust your struggle." in French?
What should be the ideal length of sentences in a blog post for ease of reading?
Error in master's thesis, I do not know what to do
New Order #2: Turn My Way
Highest stage count that are used one right after the other?
How to get directions in deep space?
Air travel with refrigerated insulin
Connection Between Knot Theory and Number Theory
Magnifying glass in hyperbolic space
I keep switching characters, how do I stop?
Not hide and seek
Reasons for having MCU pin-states default to pull-up/down out of reset
Center page as a whole without centering each element individually
Can a Knock spell open the door to Mordenkainen's Magnificent Mansion?
Hashing password to increase entropy
Should I warn a new PhD Student?
Why is indicated airspeed rather than ground speed used during the takeoff roll?
Sort with assumptions
Pre-Employment Background Check With Consent For Future Checks
Non-Borel set in arbitrary metric space
C# PictureBox.SizeMode = Zoom does not redraw when assigning new images
C# Bitmap LockBits/UnlockBits in multi-threadWhat does the [Flags] Enum Attribute mean in C#?When to use static classes in C#Why does C# forbid generic attribute types?Does C# have extension properties?winform picturebox image shows empty c#How to move elements within picturebox?Picturebox getting big red X but I can't detect or fix itVisual Studio Forms: Locate Image File of PictureBox?C# Moving Bitmap Image/Getting PixelsC# Bitmap LockBits/UnlockBits in multi-thread
I am working on a CCTV project which employs ONVIF. I use a Winform sample, which is provided by "ONVIF Device Manager" project, to obtain video frames from a camera. (You can find it here)
It was working fine if I connect to one camera. But, if I connect to six cameras some picture box does not redraw when I assign new images in DrawFrame(). Two back rectangles contain a red ellipse in the attached picture are supposed to display an image. This issues only occur when picture box size mode is Zoom. As what I have tried, those picture boxes can only redraw if I call Application.DoEvent() or call PictureBox.Update()/Refresh() every time when I set a new image.
Two red ellipses in the attached picture are supposed to display an image
private void DrawFrame(VideoBuffer videoBuffer, PlaybackStatistics statistics)
Bitmap bmp = img as Bitmap;
BitmapData bd = null;
try
bd = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);//bgra32
using (var md = videoBuffer.Lock())
CopyMemory(bd.Scan0, md.value.scan0Ptr, videoBuff.stride * videoBuff.height);
//bitmap.WritePixels(
// new Int32Rect(0, 0, videoBuffer.width, videoBuffer.height),
// md.value.scan0Ptr, videoBuffer.size, videoBuffer.stride,
// 0, 0
//);
catch (Exception err)
//errBox.Text = err.Message;
Debug.Print("DrawFrame:: " + err.Message);
finally
bmp.UnlockBits(bd);
imageBox.Image = bmp;
/*Application.DoEvent() // not recommended since this method causes the current thread to be suspended
or call imageBox.Update() // causes hanging on UI thread
or imageBox.Refresh() // causes hanging on UI thread
or PictureBox.Invalidate(), do nothing.*/
I create picture boxes and add to a panel following this code.
PictureBox ptBox = new PictureBox();
ptBox.Size = new Size(elementWidth, elementHeight);
ptBox.Name = "PictureBox_" + (j) + (i);
ptBox.Location = new Point(j * elementWidth, i * elementHeight); //relative location
ptBox.BorderStyle = BorderStyle.FixedSingle;
ptBox.SizeMode = PictureBoxSizeMode.Zoom;
mPanel.Controls.Add(ptBox);
After a week, I found that PictureBoxs occurs the error does not trigger OnPaint(PaintEventArgs e) event. It leads to the error that new images are not redrawn.
c# picturebox onvif cctv
|
show 2 more comments
I am working on a CCTV project which employs ONVIF. I use a Winform sample, which is provided by "ONVIF Device Manager" project, to obtain video frames from a camera. (You can find it here)
It was working fine if I connect to one camera. But, if I connect to six cameras some picture box does not redraw when I assign new images in DrawFrame(). Two back rectangles contain a red ellipse in the attached picture are supposed to display an image. This issues only occur when picture box size mode is Zoom. As what I have tried, those picture boxes can only redraw if I call Application.DoEvent() or call PictureBox.Update()/Refresh() every time when I set a new image.
Two red ellipses in the attached picture are supposed to display an image
private void DrawFrame(VideoBuffer videoBuffer, PlaybackStatistics statistics)
Bitmap bmp = img as Bitmap;
BitmapData bd = null;
try
bd = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);//bgra32
using (var md = videoBuffer.Lock())
CopyMemory(bd.Scan0, md.value.scan0Ptr, videoBuff.stride * videoBuff.height);
//bitmap.WritePixels(
// new Int32Rect(0, 0, videoBuffer.width, videoBuffer.height),
// md.value.scan0Ptr, videoBuffer.size, videoBuffer.stride,
// 0, 0
//);
catch (Exception err)
//errBox.Text = err.Message;
Debug.Print("DrawFrame:: " + err.Message);
finally
bmp.UnlockBits(bd);
imageBox.Image = bmp;
/*Application.DoEvent() // not recommended since this method causes the current thread to be suspended
or call imageBox.Update() // causes hanging on UI thread
or imageBox.Refresh() // causes hanging on UI thread
or PictureBox.Invalidate(), do nothing.*/
I create picture boxes and add to a panel following this code.
PictureBox ptBox = new PictureBox();
ptBox.Size = new Size(elementWidth, elementHeight);
ptBox.Name = "PictureBox_" + (j) + (i);
ptBox.Location = new Point(j * elementWidth, i * elementHeight); //relative location
ptBox.BorderStyle = BorderStyle.FixedSingle;
ptBox.SizeMode = PictureBoxSizeMode.Zoom;
mPanel.Controls.Add(ptBox);
After a week, I found that PictureBoxs occurs the error does not trigger OnPaint(PaintEventArgs e) event. It leads to the error that new images are not redrawn.
c# picturebox onvif cctv
MaybePictureBox.Invalidate()
would work as well.
– Olivier Jacot-Descombes
Mar 7 at 2:13
AFAIK picturebox only draw red X for error image, so the graphic is from the source data.
– shingo
Mar 7 at 3:33
@OlivierJacot-Descombes, I have triedPictureBox.Invalidate()
, it did nothing.
– John Pekl
Mar 7 at 5:06
"Causes hanging" is not encouraging of course. Easy to get the UI thread to burn 100% core by slamming it with expensive code like this. It then stops taking care of normal duties, like painting. If you do this in a worker thread, check the Debug > Windows > Threads debugger window since it probably already does, then assigning the Image property is not valid and likely to cause deadlock. Notable is that the CopyMemory() call is wrong, it doesn't copy enough since every pixel takes 4 bytes in 32bppArgb. So good code is 4 times worse, ouch.
– Hans Passant
Mar 7 at 13:55
@HansPassant, yes it is, what is your suggested solution?
– John Pekl
Mar 8 at 0:25
|
show 2 more comments
I am working on a CCTV project which employs ONVIF. I use a Winform sample, which is provided by "ONVIF Device Manager" project, to obtain video frames from a camera. (You can find it here)
It was working fine if I connect to one camera. But, if I connect to six cameras some picture box does not redraw when I assign new images in DrawFrame(). Two back rectangles contain a red ellipse in the attached picture are supposed to display an image. This issues only occur when picture box size mode is Zoom. As what I have tried, those picture boxes can only redraw if I call Application.DoEvent() or call PictureBox.Update()/Refresh() every time when I set a new image.
Two red ellipses in the attached picture are supposed to display an image
private void DrawFrame(VideoBuffer videoBuffer, PlaybackStatistics statistics)
Bitmap bmp = img as Bitmap;
BitmapData bd = null;
try
bd = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);//bgra32
using (var md = videoBuffer.Lock())
CopyMemory(bd.Scan0, md.value.scan0Ptr, videoBuff.stride * videoBuff.height);
//bitmap.WritePixels(
// new Int32Rect(0, 0, videoBuffer.width, videoBuffer.height),
// md.value.scan0Ptr, videoBuffer.size, videoBuffer.stride,
// 0, 0
//);
catch (Exception err)
//errBox.Text = err.Message;
Debug.Print("DrawFrame:: " + err.Message);
finally
bmp.UnlockBits(bd);
imageBox.Image = bmp;
/*Application.DoEvent() // not recommended since this method causes the current thread to be suspended
or call imageBox.Update() // causes hanging on UI thread
or imageBox.Refresh() // causes hanging on UI thread
or PictureBox.Invalidate(), do nothing.*/
I create picture boxes and add to a panel following this code.
PictureBox ptBox = new PictureBox();
ptBox.Size = new Size(elementWidth, elementHeight);
ptBox.Name = "PictureBox_" + (j) + (i);
ptBox.Location = new Point(j * elementWidth, i * elementHeight); //relative location
ptBox.BorderStyle = BorderStyle.FixedSingle;
ptBox.SizeMode = PictureBoxSizeMode.Zoom;
mPanel.Controls.Add(ptBox);
After a week, I found that PictureBoxs occurs the error does not trigger OnPaint(PaintEventArgs e) event. It leads to the error that new images are not redrawn.
c# picturebox onvif cctv
I am working on a CCTV project which employs ONVIF. I use a Winform sample, which is provided by "ONVIF Device Manager" project, to obtain video frames from a camera. (You can find it here)
It was working fine if I connect to one camera. But, if I connect to six cameras some picture box does not redraw when I assign new images in DrawFrame(). Two back rectangles contain a red ellipse in the attached picture are supposed to display an image. This issues only occur when picture box size mode is Zoom. As what I have tried, those picture boxes can only redraw if I call Application.DoEvent() or call PictureBox.Update()/Refresh() every time when I set a new image.
Two red ellipses in the attached picture are supposed to display an image
private void DrawFrame(VideoBuffer videoBuffer, PlaybackStatistics statistics)
Bitmap bmp = img as Bitmap;
BitmapData bd = null;
try
bd = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);//bgra32
using (var md = videoBuffer.Lock())
CopyMemory(bd.Scan0, md.value.scan0Ptr, videoBuff.stride * videoBuff.height);
//bitmap.WritePixels(
// new Int32Rect(0, 0, videoBuffer.width, videoBuffer.height),
// md.value.scan0Ptr, videoBuffer.size, videoBuffer.stride,
// 0, 0
//);
catch (Exception err)
//errBox.Text = err.Message;
Debug.Print("DrawFrame:: " + err.Message);
finally
bmp.UnlockBits(bd);
imageBox.Image = bmp;
/*Application.DoEvent() // not recommended since this method causes the current thread to be suspended
or call imageBox.Update() // causes hanging on UI thread
or imageBox.Refresh() // causes hanging on UI thread
or PictureBox.Invalidate(), do nothing.*/
I create picture boxes and add to a panel following this code.
PictureBox ptBox = new PictureBox();
ptBox.Size = new Size(elementWidth, elementHeight);
ptBox.Name = "PictureBox_" + (j) + (i);
ptBox.Location = new Point(j * elementWidth, i * elementHeight); //relative location
ptBox.BorderStyle = BorderStyle.FixedSingle;
ptBox.SizeMode = PictureBoxSizeMode.Zoom;
mPanel.Controls.Add(ptBox);
After a week, I found that PictureBoxs occurs the error does not trigger OnPaint(PaintEventArgs e) event. It leads to the error that new images are not redrawn.
c# picturebox onvif cctv
c# picturebox onvif cctv
edited Mar 7 at 13:15
John Pekl
asked Mar 7 at 0:55
John PeklJohn Pekl
154
154
MaybePictureBox.Invalidate()
would work as well.
– Olivier Jacot-Descombes
Mar 7 at 2:13
AFAIK picturebox only draw red X for error image, so the graphic is from the source data.
– shingo
Mar 7 at 3:33
@OlivierJacot-Descombes, I have triedPictureBox.Invalidate()
, it did nothing.
– John Pekl
Mar 7 at 5:06
"Causes hanging" is not encouraging of course. Easy to get the UI thread to burn 100% core by slamming it with expensive code like this. It then stops taking care of normal duties, like painting. If you do this in a worker thread, check the Debug > Windows > Threads debugger window since it probably already does, then assigning the Image property is not valid and likely to cause deadlock. Notable is that the CopyMemory() call is wrong, it doesn't copy enough since every pixel takes 4 bytes in 32bppArgb. So good code is 4 times worse, ouch.
– Hans Passant
Mar 7 at 13:55
@HansPassant, yes it is, what is your suggested solution?
– John Pekl
Mar 8 at 0:25
|
show 2 more comments
MaybePictureBox.Invalidate()
would work as well.
– Olivier Jacot-Descombes
Mar 7 at 2:13
AFAIK picturebox only draw red X for error image, so the graphic is from the source data.
– shingo
Mar 7 at 3:33
@OlivierJacot-Descombes, I have triedPictureBox.Invalidate()
, it did nothing.
– John Pekl
Mar 7 at 5:06
"Causes hanging" is not encouraging of course. Easy to get the UI thread to burn 100% core by slamming it with expensive code like this. It then stops taking care of normal duties, like painting. If you do this in a worker thread, check the Debug > Windows > Threads debugger window since it probably already does, then assigning the Image property is not valid and likely to cause deadlock. Notable is that the CopyMemory() call is wrong, it doesn't copy enough since every pixel takes 4 bytes in 32bppArgb. So good code is 4 times worse, ouch.
– Hans Passant
Mar 7 at 13:55
@HansPassant, yes it is, what is your suggested solution?
– John Pekl
Mar 8 at 0:25
Maybe
PictureBox.Invalidate()
would work as well.– Olivier Jacot-Descombes
Mar 7 at 2:13
Maybe
PictureBox.Invalidate()
would work as well.– Olivier Jacot-Descombes
Mar 7 at 2:13
AFAIK picturebox only draw red X for error image, so the graphic is from the source data.
– shingo
Mar 7 at 3:33
AFAIK picturebox only draw red X for error image, so the graphic is from the source data.
– shingo
Mar 7 at 3:33
@OlivierJacot-Descombes, I have tried
PictureBox.Invalidate()
, it did nothing.– John Pekl
Mar 7 at 5:06
@OlivierJacot-Descombes, I have tried
PictureBox.Invalidate()
, it did nothing.– John Pekl
Mar 7 at 5:06
"Causes hanging" is not encouraging of course. Easy to get the UI thread to burn 100% core by slamming it with expensive code like this. It then stops taking care of normal duties, like painting. If you do this in a worker thread, check the Debug > Windows > Threads debugger window since it probably already does, then assigning the Image property is not valid and likely to cause deadlock. Notable is that the CopyMemory() call is wrong, it doesn't copy enough since every pixel takes 4 bytes in 32bppArgb. So good code is 4 times worse, ouch.
– Hans Passant
Mar 7 at 13:55
"Causes hanging" is not encouraging of course. Easy to get the UI thread to burn 100% core by slamming it with expensive code like this. It then stops taking care of normal duties, like painting. If you do this in a worker thread, check the Debug > Windows > Threads debugger window since it probably already does, then assigning the Image property is not valid and likely to cause deadlock. Notable is that the CopyMemory() call is wrong, it doesn't copy enough since every pixel takes 4 bytes in 32bppArgb. So good code is 4 times worse, ouch.
– Hans Passant
Mar 7 at 13:55
@HansPassant, yes it is, what is your suggested solution?
– John Pekl
Mar 8 at 0:25
@HansPassant, yes it is, what is your suggested solution?
– John Pekl
Mar 8 at 0:25
|
show 2 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55034455%2fc-sharp-picturebox-sizemode-zoom-does-not-redraw-when-assigning-new-images%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55034455%2fc-sharp-picturebox-sizemode-zoom-does-not-redraw-when-assigning-new-images%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Maybe
PictureBox.Invalidate()
would work as well.– Olivier Jacot-Descombes
Mar 7 at 2:13
AFAIK picturebox only draw red X for error image, so the graphic is from the source data.
– shingo
Mar 7 at 3:33
@OlivierJacot-Descombes, I have tried
PictureBox.Invalidate()
, it did nothing.– John Pekl
Mar 7 at 5:06
"Causes hanging" is not encouraging of course. Easy to get the UI thread to burn 100% core by slamming it with expensive code like this. It then stops taking care of normal duties, like painting. If you do this in a worker thread, check the Debug > Windows > Threads debugger window since it probably already does, then assigning the Image property is not valid and likely to cause deadlock. Notable is that the CopyMemory() call is wrong, it doesn't copy enough since every pixel takes 4 bytes in 32bppArgb. So good code is 4 times worse, ouch.
– Hans Passant
Mar 7 at 13:55
@HansPassant, yes it is, what is your suggested solution?
– John Pekl
Mar 8 at 0:25