manipulate binary images in picturebox C#

rotate binary images in picturebox and size images before going into

Page 1 of 1

4 Replies - 8404 Views - Last Post: 13 January 2010 - 08:38 PM Rate Topic: -----

#1 captsisko  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 05-January 10

manipulate binary images in picturebox C#

Post icon  Posted 05 January 2010 - 09:16 PM

string instrPic = comboBox1.SelectedItem.ToString();
			SqlConnection roy1 = new SqlConnection(@"server=CAPTSISKO-PC\SQLEXPRESS;Initial Catalog=cable;Integrated Security=True");
			roy1.Open();
			string newPic = "Select Pic from guidePic WHERE picTitle = '" + instrPic + "'";
			DataSet ds = new DataSet();
			SqlDataAdapter da = new SqlDataAdapter(newPic, roy1);
			da.Fill(ds, "newPic");
			dataGridView1.DataSource = ds;
			dataGridView1.DataMember = "newPic";
			int c = ds.Tables["newPic"].Rows.Count;
			if(c >0)
			   {
				   Byte[] byteRoy = new Byte[0];
				   byteRoy = (Byte[])(ds.Tables["newPic"].Rows[c - 1]["Pic"]);
				  
				   MemoryStream stimRoy = new MemoryStream(byteRoy);
				   
				   pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
				   pictureBox1.Image = Image.FromStream(stimRoy);


Hello, do you have any topics that cover binary images , the code I am showing does what it suppose to do but the image is too big and the view shows the picture sideways, can I manipulate the image before it is viewed in the picturebox or do you have a tutorial on binary images that can be resize or rotated to fit the picturebox.

Is This A Good Question/Topic? 0
  • +

Replies To: manipulate binary images in picturebox C#

#2 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 380
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: manipulate binary images in picturebox C#

Posted 07 January 2010 - 07:28 AM

//this will fit the picture inside a picturebox control
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;

//this will rotate your image
pictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone);
Was This Post Helpful? 1
  • +
  • -

#3 captsisko  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 05-January 10

Re: manipulate binary images in picturebox C#

Posted 10 January 2010 - 07:40 PM

View PostFlashM, on 7 Jan, 2010 - 06:28 AM, said:

//this will fit the picture inside a picturebox control
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;

//this will rotate your image
pictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone);


thanks for the suggestion, it is working but can I ask if I have multiple pictures in that selection process how can I create a button that will move on to the next picture in that catergory?

public void button1_Click(object sender, EventArgs e)
		{
		   
			string instrPic = comboBox1.SelectedItem.ToString();
			SqlConnection roy1 = new SqlConnection(@"server=CAPTSISKO-PC\SQLEXPRESS;Initial Catalog=cable;Integrated Security=True");
			roy1.Open();
			string newPic = "Select Pic from guidePic WHERE picTitle = '" + instrPic + "'";
			DataSet ds = new DataSet();
			SqlDataAdapter da = new SqlDataAdapter(newPic, roy1);
			da.Fill(ds, "newPic");
			Binding guiPhoto = new Binding("Image", ds, " newPic");
		   // pictureBox1.DataBindings.Add(guiPhoto);
			_guidePic = this.BindingContext[ds, "newPic"];
		   
			int c = ds.Tables["newPic"].Rows.Count;
		   
			if(c >0)
			   {
				   Byte[] byteRoy = new Byte[0];
				   byteRoy = (Byte[])(ds.Tables["newPic"].Rows[c - 1]["Pic"]);
				  
				   MemoryStream stimRoy = new MemoryStream(byteRoy);

				  // pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
				   int originalW = Image.FromStream(stimRoy).Width;
				   int orignalH = Image.FromStream(stimRoy).Height;
				   int resizedW = (int)(originalW * .370  );
				   int resizedH = (int)(orignalH * .370);
				   Bitmap bmp = new Bitmap(resizedW, resizedH);
				  
				   Graphics graphic = Graphics.FromImage((Image)bmp);
				   graphic.DrawImage(Image.FromStream(stimRoy), 0, 0, resizedW, resizedH);
				   graphic.Dispose();
				   bmp.RotateFlip(RotateFlipType.Rotate90FlipNone);

				   bmp.Save("RoyNew");
				   
				pictureBox1.Image = ((Image)bmp);

this is the code that produces the image from the database, if the drop down selection has more then one picture I need for a user to push a button that will go to the next button. Any suggestions?
Was This Post Helpful? 0
  • +
  • -

#4 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 380
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: manipulate binary images in picturebox C#

Posted 11 January 2010 - 02:08 AM

Use the comboBox1.SelectedIndex to set the next item selected in combobox, something like this:

comboBox1.SelectedIndex += 1;

also check if there is next index available or is the picture shown the last one in combobox.
Was This Post Helpful? 0
  • +
  • -

#5 captsisko  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 05-January 10

Re: manipulate binary images in picturebox C#

Posted 13 January 2010 - 08:38 PM

View PostFlashM, on 11 Jan, 2010 - 01:08 AM, said:

Use the comboBox1.SelectedIndex to set the next item selected in combobox, something like this:

comboBox1.SelectedIndex += 1;

also check if there is next index available or is the picture shown the last one in combobox.


Been trying to figure this out but the combobox select doesn't work with what I am using or trying to do, each time a user selects from the drop down list they have a category, the category may have multiple pictures in it but don't want to hit the entire database, it works with an sql query and I sorta of got it to work builing an image class but only if I hard code the selection into the query then it will do what it is suppose to . here is the code
public class Images
	{  
		String instrPic ="";
		SqlDataReader imageReader = null;
		byte[] imageBytes = null;
		public Images()
		{
		   
			SqlConnection roy2 = new SqlConnection(@"server=CAPTSISKO-PC\SQLEXPRESS;Initial Catalog=cable;Integrated Security=True");
		   SqlCommand imageCommand = new SqlCommand(@"Select picTitle, Pic from guidePic WHERE picTitle = '" +  instrPic + "'", roy2);
			roy2.Open();
			 imageReader = imageCommand.ExecuteReader();
			
		}
		
		public Bitmap GetImage()
		{
			Byte[] imageBytes = null;
			MemoryStream ms = new MemoryStream(imageBytes);
			int originalW = Image.FromStream(ms).Width;
			int orignalH = Image.FromStream(ms).Height;
			int resizedW = (int)(originalW * .370);
			int resizedH = (int)(orignalH * .370);
			Bitmap bmp = new Bitmap(resizedW, resizedH);

			Graphics graphic = Graphics.FromImage((Image)bmp);
			graphic.DrawImage(Image.FromStream(ms), 0, 0, resizedW, resizedH);
			graphic.Dispose();
			bmp.RotateFlip(RotateFlipType.Rotate90FlipNone);
			 //Bitmap bmp = new Bitmap(ms);
			bmp.Save("RoyNew");
		   
			return bmp;
		 }
		public string GetFileName()
		{
			return instrPic;
		}
		public bool GetRow()
		{
			if (imageReader.Read())
			{
				instrPic = (string)imageReader.GetValue(0);
				imageBytes = (byte[])imageReader.GetValue(1);
				return true;

			}
			else
			{
				return false;
			}
		}
		public void EndIamges()
		{
			imageReader.Close();
			
		}

	}
		  
}
This is pulled into the form like here
private void button1_Click(object sender, EventArgs e)
		{
			if (images.GetRow())
			{
				//string instrPic = comboBox1.SelectedItem.ToString();
			   // instrPic = images.GetFileName();
				this.pictureBox1.Image = (Image)images.GetImage();
			}

			else
			{
				MessageBox.Show("This is not working");
			}
The code I am getting my value from is here in this part of the form
SqlConnection con = new SqlConnection();
			con.ConnectionString = "Data Source=CAPTSISKO-PC\\SQLEXPRESS;Initial Catalog=cable;Integrated Security=True";
			con.Open();
			{
				string roySetup1 = @"Select picTitle from GuideFeatures";
		  SqlCommand   cmd = new SqlCommand(roySetup1, con);
		  cmd.CommandType = CommandType.Text;
			   
					SqlDataReader drr = cmd.ExecuteReader();
					ArrayList setup1 = new ArrayList();
					while (drr.Read())
					{ 
					 setup1.Add( comboBox1.Items.Add(drr.GetString(0)));
					}
					drr.Close();
			}
I should be able to take the value of the combo box and place it in the class which will go to the form button click in the selection process but i can't seem to pass the value back to the class , any thoughts?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1