如何在C#中调用class to button [英] How to call class to button in C#

查看:61
本文介绍了如何在C#中调用class to button的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着打电话给这堂课:



 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;

命名空间 tes_skripsi
{
class RGB2HSV
{
public int [] ApplyFilter( int red, int green, int blue)
{
int [] Results = new int [ 3 ];
int HSV_H = 0 ;
int HSV_S = 0 ;
int HSV_V = 0 ;

double MaxHSV =( double )(Math.Max(红色,数学) .Max(绿色,蓝色)));
double MinHSV =( double )(Math.Min(红色,Math.Min(绿色) , 蓝色)));

// V
HSV_V =( INT )(MaxHSV);



// S
HSV_S = 0 ;
if (MaxHSV!= 0 )HSV_S =( int )( 255 - 255 *(MinHSV / MaxHSV));



// H
if (MaxHSV!= MinHSV)
{
int IntegerMaxHSV =(< span class =code-keyword> int
)(MaxHSV);

if (IntegerMaxHSV == red&& green > =蓝色)
{
HSV_H =( int )( 60 *(绿色 - 蓝色)/(MaxHSV - MinHSV));
}

else if (IntegerMaxHSV == red& & green < blue)
{
HSV_H =( int )( 359 + 60 *(绿色 - 蓝色)/(MaxHSV - MinHSV));
}
else if (IntegerMaxHSV == green)
{
HSV_H =( int )( 119 + 60 *(蓝色 - 红色)/(MaxHSV - MinHSV));
}
else if (IntegerMaxHSV == blue)
{
HSV_H =( int )( 239 + 60 *(红 - 绿)/(MaxHSV - MinHSV));
}


}
其他 HSV_H = 0 ;

结果[ 0 ] = HSV_H;
结果[ 1 ] = HSV_S;
结果[ 2 ] = HSV_V;

return (结果);
}
}
}





到这个按钮:



  private   void  button2_Click( object  sender,EventArgs e)
{

Bitmap Temp = new 位图(文件);
// warna = RGB2HSV(Temp);
// pictureBox2.Image = warna;
if (pictureBox2.Image!= null
return ;
else
HSVColor();
}





我该怎么办?任何帮助将不胜感激。谢谢。



我尝试了什么:



我试过这个。但仍然无法工作



 private void button2_Click(object sender,EventArgs e)
{
Bitmap Temp = new Bitmap (文件);
RGB2HSV warna = new RGB2HSV();
warna = RGB2HSV();
pictureBox2.Image = warna;
}

解决方案

当你从RGB转换为HSV时,你不会以任何方式影响图像,你是当您更改像素时,只需使用不同的颜色空间表示 - 窗口(以及您的图形卡/显示器/打印机)专门用于所有输出的RGB工作。



HSV是一种表示单一颜色值的​​不同方式,而不是图像的转换。它用于选择和调整颜色,而不是显示图像。这就是你找到的转换代码:接受一个像素值的RGB颜色值,并返回该颜色的HSV替代值。



你不要转换一个piel值,整个图像神奇地变为HSV! (即使它确实如此,你需要将其更改回ARGB才能让Windows显示它...)


你不要打电话给班级而是你创建一个类的对象,并使用该对象调用它的方法。



如果你想调用<$,你应该尝试类似的东西c $ c> ApplyFilter()方法。



 tes_skripsi.RGB2HSV warna =  new  tes_skripsi.RGB2HSV(); 
var result = warna.ApplyFilter(redValue,greenValue,blueValue); // 将适当的值作为参数传递





如果有任何混淆,请告诉我。



希望,这有帮助。感谢。


I try to call this class :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tes_skripsi
{
    class RGB2HSV
    {
        public int[] ApplyFilter(int red, int green, int blue)
        {
            int[] Results = new int[3];
            int HSV_H = 0;
            int HSV_S = 0;
            int HSV_V = 0;

            double MaxHSV = (double)(Math.Max(red, Math.Max(green, blue)));
            double MinHSV = (double)(Math.Min(red, Math.Min(green, blue)));

            // V 
            HSV_V = (int)(MaxHSV);



            // S
            HSV_S = 0;
            if (MaxHSV != 0) HSV_S = (int)(255 - 255 * (MinHSV / MaxHSV));



            // H
            if (MaxHSV != MinHSV)
            {
                int IntegerMaxHSV = (int)(MaxHSV);

                if (IntegerMaxHSV == red && green >= blue)
                {
                    HSV_H = (int)(60 * (green - blue) / (MaxHSV - MinHSV));
                }

                else if (IntegerMaxHSV == red && green < blue)
                {
                    HSV_H = (int)(359 + 60 * (green - blue) / (MaxHSV - MinHSV));
                }
                else if (IntegerMaxHSV == green)
                {
                    HSV_H = (int)(119 + 60 * (blue - red) / (MaxHSV - MinHSV));
                }
                else if (IntegerMaxHSV == blue)
                {
                    HSV_H = (int)(239 + 60 * (red - green) / (MaxHSV - MinHSV));
                }


            }
            else HSV_H = 0;

            Results[0] = HSV_H;
            Results[1] = HSV_S;
            Results[2] = HSV_V;

            return (Results);
        }
    }
}



into this button :

private void button2_Click(object sender, EventArgs e)
        {
             
            Bitmap Temp = new Bitmap(File);
            //warna = RGB2HSV(Temp);
            //pictureBox2.Image = warna;
            if (pictureBox2.Image != null)
                return;
            else
                HSVColor();
        }



what should i do? Any help will be appreciated. Thanks.

What I have tried:

i have tried this. but still not work

private void button2_Click(object sender, EventArgs e)
        {
            Bitmap Temp = new Bitmap(File);
            RGB2HSV warna = new RGB2HSV();
            warna = RGB2HSV();
            pictureBox2.Image = warna;
        }

解决方案

When you convert from RGB to HSV, you don't affect the image in any way, you are just working with a different representation of the colour space when you change pixels - windows (and your graphics card / monitor / printer) works in RGB exclusively for all output.

HSV is a different way of representing a single colour value, not a "transformation" of an image. It's used to select and adjust colours, not to "display an image". And that's what the conversion code you have found does: accepts a single RGB colour value for a pixel value, and returns the HSV alternative value for that colour.

You don't transform a piel value and the whole image magically changes to HSV! (And even if it did, you'd need to change it back to ARGB in order to get Windows to display it...)


You don't call a class rather you create an object of a class and call its method using that object.

You should try something like following if you want to call the ApplyFilter() method.

tes_skripsi.RGB2HSV warna = new tes_skripsi.RGB2HSV();
var result = warna.ApplyFilter(redValue, greenValue, blueValue); //pass the appropriate value as parameters



In case of any confusion, please let me know.

Hope, it helps. Thanks.


这篇关于如何在C#中调用class to button的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆