diditel

hi..

i need help on my application.....with the zoom function.

currently, i have 5picbox that captures 5images in an interval of 1sec per frame.

my application can either capture a single image...which means on picbox1 only

and....multiple image capture...which means on picbox1 to picbox5.

i have stored the single image capture as: m_Bitmap

multiple image capture as: Bitmap[] bmp5frames; <a bitmap array>

now i am trying to make a zooming function that can work on either a singlecapturing or, multiplecapturing. zooming values shud varies from 50% to 500%. making the initial image shown on picboxes as 100%



Re: Windows Forms General zoom function on images

Yu Guo – MSFT

Hi, diditel,

Based on my understanding, you want to Zoom your PictureBoxes, don't you

This could be done with the zoom function of PictureBoxes.

First, please set the SizeMode to Zoom, for example

Code Block

pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;

//...Other PictureBoxes

Then, you can add the Image to the PictureBox with its original size.

Code Block

pictureBox1.Size = m_Bitmap.Size;

pictureBox1.Image = m_Bitmap;

//...Other PictureBoxes

After that, the Zoom function could be something like this

Code Block

PictureBox[] PBs; //PictureBoxes Array

//......

PBs = new PictureBox[1];

PBs[0] = pictureBox1;

//...Other PictureBoxes

private void ZoomPic(float percentage)

{

if (percentage >= 50 && percentage <= 500)

{

if (single) //If it is a single picture

{

pictureBox1.Width = Convert.ToInt32(pictureBox1.Width * percentage / 100);

pictureBox1.Height = Convert.ToInt32(pictureBox1.Height * percentage / 100);

}

else //If it is a Image array

{

for (int i = 0; i < PBs.Length; i++)

{

PBs[i].Width = Convert.ToInt32(PBs[i].Width * percentage / 100);

PBs[i].Height = Convert.ToInt32(PBs[i].Height * percentage / 100);

}

}

}

else

{

MessageBox.Show("We can only zoom pictures between 50 to 500");

}

}

More info

http://msdn2.microsoft.com/en-us/library/system.windows.forms.picturebox.sizemode.aspx

Hope this helps,

Regards






Re: Windows Forms General zoom function on images

diditel

hi.thanks for the codes...

but im a little confuse..

the thing is, i haf two types of bitmaps. [m_Bitmap & bmp5frames(a bitmap array)]

so, how do i write the codes out for both





Re: Windows Forms General zoom function on images

diditel

hi there,

i understood ur codes.

thanks very much.

but i dun relly know this part...

Code Block

private void ZoomPic(float percentage)

{

if (percentage >= 50 && percentage <= 500)

{

if (single) //If it is a single picture

{

pictureBox1.Width = Convert.ToInt32(pictureBox1.Width * percentage / 100);

pictureBox1.Height = Convert.ToInt32(pictureBox1.Height * percentage / 100);

}

else //If it is a Image array

{

for (int i = 0; i < PBs.Length; i++)

{

PBs[i].Width = Convert.ToInt32(PBs[i].Width * percentage / 100);

PBs[i].Height = Convert.ToInt32(PBs[i].Height * percentage / 100);

}

}

}

else

{

MessageBox.Show("We can only zoom pictures between 50 to 500");

}

}





Re: Windows Forms General zoom function on images

Yu Guo – MSFT

Hi, diditel,

I will give you some more explainations of my answer.

Code Block

private void ZoomPic(float percentage) //This line is the definition of the method.

{

if (percentage >= 50 && percentage <= 500) //If the resize argument is in this range, then do zoom method

{

if (single) //If it is a single picture

{

pictureBox1.Width = Convert.ToInt32(pictureBox1.Width * percentage / 100);

pictureBox1.Height = Convert.ToInt32(pictureBox1.Height * percentage / 100);

//Say we want to zoom with 80%, the percentage is 80, then the width will be old width*(80/100)

//The Height uses the same algorithm.

}

else //If it is a Image array

{

for (int i = 0; i < PBs.Length; i++) //We loop through all the PictureBoxes

{

PBs[i].Width = Convert.ToInt32(PBs[i].Width * percentage / 100);

PBs[i].Height = Convert.ToInt32(PBs[i].Height * percentage / 100);

//Please see the above algorithm

}

}

}

else

{

MessageBox.Show("We can only zoom pictures between 50 to 500");

}

}

Hope this helps to understand my codes.

Regards






Re: Windows Forms General zoom function on images

diditel

then....what buttons must i press if i wana zoom it from 100% to 200%

this will be the funtion on zooming right

so how do i call it





Re: Windows Forms General zoom function on images

Yu Guo – MSFT

Hi, diditel,

You can put the codes in the Click event of your button.

For example

Code Block

private void button1_Click(object sender, EventArgs e)

{

ZoomPic(200);

}

But you should decide to zoom a single image or a Image array by setting the "single" value.

Hope this helps,

Regards






Re: Windows Forms General zoom function on images

diditel

ok....

then what should i write in ...

Code Block

if (single)// if it is a single image

can i write in

Code Block

if (m_Bitmap != 0) //if it is a single image

,but there was an error.




Re: Windows Forms General zoom function on images

Yu Guo – MSFT

Hi, diditel,

You cannot write that, because m_Bitmap is an image array.

The single is a boolean variable, you can set it to true when you are processing single image and set it to false when you are processing the m_Bitmap array.

Hope this helps,

Regards






Re: Windows Forms General zoom function on images

diditel

hmm....so, should i write it...

Code Block

if (single == true)

{

}

return false;

i apologise as i am a new beginner in this language.





Re: Windows Forms General zoom function on images

Yu Guo – MSFT

Hi, diditel,

In fact,

if(single==true) equals if(single)

because single is a Boolean value.

http://msdn2.microsoft.com/en-us/library/5011f09h(VS.80).aspx

http://msdn2.microsoft.com/en-us/library/c8f5xwh7(VS.80).aspx

Regards






Re: Windows Forms General zoom function on images

diditel

what should i write in there, then




Re: Windows Forms General zoom function on images

Yu Guo – MSFT

Hi, diditel,

It depends on where do you call this function.

Before you call the function,i f you are showing a single image, set single to true, if not, set single to false.

If you are still not clear of what to do next, post more codes of your application please.

Regards






Re: Windows Forms General zoom function on images

diditel

i am using the codes u gave....




Re: Windows Forms General zoom function on images

Yu Guo – MSFT

Hi, diditel,

My codes should work for zooming.

But you should tell me where do you call it.

Regards