Picture Box size expanded when program runs - c#

i am currently learning on webcam based qr code decoder i have taken an example from https://zxingnet.svn.codeplex.com/svn/trunk/Clients/AForgeDemo/ . i have manage to get it working however i have a problem which baffle me. it is regarding to the picture box in my GUI.
the image above is before i press the start/ continue button. the image after is as below
is there any setting in the picture box property which could prevent the picturebox from expanding or do i need to type a source code to. it would be great if anyone could highlight what i need to do to prevent the expending of the picture box. thank you

Set the MaximumSize property of the picture box to however big you want it to be. You can also set MinimumSize while you're at it.

Hey Try This Code on click of Start Button
private void Button1_Click(System.Object sender, System.EventArgs e)
{
// Set the SizeMode property to the StretchImage value. This
// will enlarge the image as needed to fit into
// the PictureBox.
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}
Hope it will helps you

Seems like you have to set PictureBox.SizeMode to everithing else than AutoSize.

Related

I can't get the correct coordinate of an image with mouse over C#

This is my first question ever on Stackoverflow. So I hope it for the best answer.
I want to get correct X and Y coordinate of an Image with mouse over Event (WFA .NET Framework).
Take a look at my cursor
The coordinate should be somewhere between 500 for X and 427 for Y, but I only get as I posted. I already maxed out the scroll. And I think the image resolution is correct, here's the image properties
Here's my code:
private void pbInput_MouseMove(object sender, MouseEventArgs e) {
mouseX.Text = e.X.ToString();
mouseY.Text = e.Y.ToString();
}
And I have a plan to zooming the image for the future, so I put "auto scroll" panel below the picture box.
Could you help me? Thank you so much.
PS: Sorry for my bad English
Try putting picturebox inside panel
set panel to:
this.panel1.AutoScroll = true;
and picturebox to
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this will allow panel to have scroll bars and picturebox will have its full size adjusted to actual picture size

Faster image paint method

My project consists of a video player and a image viewer, both fullscreen in a panel with only one visible at a time. When the video pauses I capture the frame, display it in the image viewer and swap which control is visible. The problem is, when the image viewer is shown you see the previous image for a brief second before the new image is painted.
Does anyone have any suggestions on how I can prevent this? Ideally I want it to be seemless when the controls swap.
I've already set the image viewer to be double buffered.
Edit:
Code, doesn't really show much here.
private void ShowImageView()
{
this.axWindowsMediaPlayer.Visible = false;
this.imageViewer.Visible = true;
}
private void ShowVideoView()
{
this.axWindowsMediaPlayer.Visible = true;
this.imageViewer.Visible = false;
}
I've managed to solve it, the image viewer had a Image Changed event that I hadn't spotted (I'd tried using the Image Loaded event). Subscribing to the image changed event and only showing the control then, seems to give me the transistion I was looking for.

Position Background Image

I was wondering if there is any possible way to position a background image on a button in C# windows forms? I am using Visual Studio 2013, and I noticed that you can use the BackgroundImageLayout but that is very limited. I would like to move the background image around by pixel position, or relative to the button. Kind of like this:
I have been on google for a while now with no luck. If anyone could point me in the right direction, or show my an article to read it would be greatly appreciated. Thank you.
You could use the Paint event (or subclass Button to override OnPaint) to draw the image yourself:
private void myButton_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage(myImage, myButton.ClientRectangle);
}
You could then use the TextAlign and Padding properties to control the location of the text.
Note that you should not assign the image to the Button's Image or BackgroundImage properties, otherwise .NET will also render the image.

Save Image in PictureBox with overlapping Controls

I am developing an application in which user can select an image in a picture box.
After that he can right click on the image and add a user control which will again display an Image along with some text. This user control can be added any number of times.
User can also re-position the user controls as per need.
All this functionality has been implemented and is working fine.
Now, the requirement is to save the Image along with the user control.
Above you can see the complete image which needs to be saved. Back image is the picture box image and the user control (small images with text).
When user will click on save button the image should get saved on his disk as a single image.
This is a windows application developed in C#.
I want to know that whether this functionality can be achieved or not. If yes, then please guide me in the right direction.
If you create a copy of the bitmap then with the Graphics.DrawImage() you can draw those images onto it. You need to calculate the position of those controls.
Look here for DrawImage: http://msdn.microsoft.com/en-us/library/42807xh1.aspx
example:
Bitmap copy = new Bitmap(OriginalBitmap);
Graphics g = Graphics.FromImage(copy);
g.DrawImage(arrowBitmap, new Point(..));
copy.Save(...);
A very simple and straight forward solution exists, has been thought of by Microsoft and includes these steps:
Instead of PictureBox use a Panel and instead of using the Image property of the PictureBox use the BackgroundImage property of the Panel
note: By using also the BackgroundImageLayout property you can quite easily instruct the Panel to stretch, center or zoom the image (I'm presuming the default value which is tile is not a good option in your case)
Instead of placing the other user controls at higher Z order but alongside the previous PictureBox place them inside the Panel
Use the Control.DrawToBitmap method like so:
private void button1_Click(object sender, EventArgs e) {
var bmp = new Bitmap(this.panel1.Width, this.panel1.Height);
this.panel1.DrawToBitmap(bmp, new Rectangle(Point.Empty, bmp.Size));
bmp.Save(#"D:\test.png", ImageFormat.Png);
}
That will result in your controls begin rendered along with the picture:
Furthermore, and if your scenario allows it, you could simply use the DrawToBitmap method with any control which contains all of the actors you wish to render, for instance the actual Form.

Load image in PictureBox before make control visible

I have a form with black background, with 9 picture boxes.
When the program starts, I want to show 9 images using these picture boxes.
However, the picture boxes take time to load the picture. It is quite ugly that the picture boxes show up first while waiting.
Is there a way I can move from blank black screen to straightaway 9 images, without the visible loading in between?
Thanks.
How are you loading your Form (I guess you are talking about Windows.Forms here)?
You can just create a new Window class and load your pictures and then after all is done call the Show method.
MyForm form = new MyForm ();
form.DoLoadImages ();
form.Show ();
Or you can just set the WaitOnLoad property of the PictureBox to true.
private void startButton_Click(object sender, EventArgs e)
{
// Ensure WaitOnLoad is false.
pictureBox1.WaitOnLoad = false;
// Load the image asynchronously.
pictureBox1.LoadAsync(#"http://localhost/print.gif");
}
Courtesy of MSDN: http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.waitonload(v=VS.100).aspx1

Categories