Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I try to call this class :

C#
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 :

C#
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;
        }
Posted
Updated 29-Mar-19 20:50pm
v2

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...)
 
Share this answer
 
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.

C#
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.
 
Share this answer
 
Comments
gnjr97 30-Mar-19 1:29am    
i try what you comment, and this the code:

private void button2_Click(object sender, EventArgs e)        
{            
int redValue, greenValue, blueValue;            
redValue = 0;            
greenValue = 0;            
blueValue = 0;            
tes_skripsi.RGB2HSV warna = new tes_skripsi.RGB2HSV();            
var result = warna.ApplyFilter(redValue, greenValue, blueValue); //pass the appropriate value as parameters            
pictureBox2.Image = warna();


how to apply that into pictureBox2.Image?
because i want to change my RGB image to HSV.
sorry if i ask too many quiestion :D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900