I am trying to write a code for changing contrast.
I create a class for this but I should get the value from texbox and write the value for the process in Contrast.cs
but I could not get that.
How can I send the value to the Contrast.cs
when I click to the btn_contrast
?
Here is the code for Form1:
using AForge.Video.DirectShow;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace imageprocessing
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public FilterInfoCollection devices;
public VideoCaptureDevice camera;
private void Form1_Load(object sender, EventArgs e)
{
devices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo item in devices)
{
cb_show.Items.Add(item.Name);
}
camera = new VideoCaptureDevice();
cb_show.SelectedIndexChanged = cb_show_SelectedIndexChanged;
}
private void cb_show_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (camera.IsRunning == false)
{
camera = new VideoCaptureDevice(devices[cb_show.SelectedIndex].MonikerString);
camera.NewFrame = Camera_NewFrame;
camera.Start();
}
}
catch (Exception exc)
{
MessageBox.Show(exc.Message "");
}
}
List<byte> alldata = new List<byte>();
public void Camera_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
{
Bitmap image = (Bitmap)eventArgs.Frame.Clone();
byte[] maindata = new byte[image.Width * 3];
if (btn_grayWasClicked == true)
{
alldata.Clear();
for (int i = 0; i < image.Height; i )
{
int count = 0;
for (int j = 0; j < image.Width; j )
{
Color color = image.GetPixel(j, i);
maindata[count] = color.R;
maindata[count 1] = color.G;
maindata[count 2] = color.B;
count = 3;
}
byte[] processGray = Gray.GrayFilter(maindata, image.Width);
alldata.AddRange(processGray);
}
}
}
private bool btn_contrastWasClicked = false;
private void btn_contrast_Click(object sender, EventArgs e)
{
btn_contrastWasClicked = true;
}
Here is the code for Contrast.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace imageprocessing
{
class Contrast
{
public static byte[] Contrast(byte[] data, int width)
{
List<byte> alldataa = new List<byte>();
double cont =(100.0 (Convert.ToInt32()-100))/100.0)*(100.0 (Convert.ToInt32() - 100)) / 100.0);
for (int i = 0; i < width - 1; i = 3)
{
data[i]=((((data[i]/255)-0.5)*cont) 0.5)*255;
if (data[i]<0)
{
data[i] = 0;
}
if(data[i]>255)
{
data[i] = 255;
}
}
return data;
}
}
}
I need the value that is coming from tb_contrast in this code:
double cont =(100.0 (Convert.ToInt32()-100))/100.0)*(100.0 (Convert.ToInt32() - 100)) / 100.0);
CodePudding user response:
Keep the value in Session
, then use it wherever you want.
CodePudding user response:
First Make your class public
and the create a object for your class in Form1 like below:
Contrast con = new Contrast();
now you can call your class methods wherever you wan.
private void btn_contrast_Click(object sender, EventArgs e)
{
btn_contrastWasClicked = true;
con.Contrast('SomeVal','Your Required TextBoxValue');
}