如何使用C#中的方法将RGB转换为HSV [英] How to convert RGB to HSV using method in C#
本文介绍了如何使用C#中的方法将RGB转换为HSV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用c#中的方法将RGB图像转换为hsv,但我仍然不能这样做。
我进行了搜索,但没有发现任何有用的内容。我需要该方法的源代码。任何帮助将不胜感激。谢谢。
我尝试了什么:
我试过这个
I want to convert RGB image to hsv using method in c#, but i still can't do that.
I made a search but found nothing useful. I need a source code for that method. Any help will be appreciated. Thanks.
What I have tried:
I tried this
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace tes_skripsi
{
public partial class Form1 : Form
{
Image File;
public Bitmap Temp;
public Bitmap warna;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog f = new OpenFileDialog();
f.Filter = "(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (f.ShowDialog() == DialogResult.OK)
{
File = Image.FromFile(f.FileName);
pictureBox1.Image = File;
//Temp = (Bitmap)File;
}
}
private void button2_Click(object sender, EventArgs e)
{
Bitmap Temp = new Bitmap(File);
warna = HSVColor(Temp);
pictureBox2.Image = warna;
}
private void HSVColor()
{
//pictureBox2.Image = pictureBox1.Image;
Bitmap con = (Bitmap)pictureBox1.Image;
int width = con.Size.Width;
int height = con.Size.Height;
double hue, saturation, value;
for (int j = 0; j < height; j++)
{
for (int i = 0; i < width; i++)
{
Color col;
col = con.GetPixel(i, j);
//normalisasi RGB
con.SetPixel(i, j, Color.FromArgb((col.R) / 255, (col.G) / 255, (col.B) / 255));
//rgbtohsv
int max = Math.Max(col.R, Math.Max(col.G, col.B));
int min = Math.Min(col.R, Math.Min(col.G, col.B));
hue = col.GetHue();
saturation = (max == 0) ? 0 : 1d - (1d * min / max);
value = max / 255d;
}
}
}
推荐答案
rgb到hsv - Google搜索 [ ^ ]
这篇关于如何使用C#中的方法将RGB转换为HSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文