如何改变图像的色彩在运行时 [英] How to change color of Image at runtime

查看:116
本文介绍了如何改变图像的色彩在运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道有没有什么办法,使我们可以在运行时改变图像色彩。
对于例如让说我有一个JPG绑定到ASP.Net的Image控件。接下来我有一个下拉列表,让我喜欢红色,格力,等各种颜色的选择。我现在想的图像的颜色改变为在droprdown列表中选择一个。

I would like to know is there any way by which we can change the Image color at runtime. for e.g lets say I am having a JPG bind to an Image control of ASP.Net. Next I am having a dropdown List which gives me the various color option like red,gree,etc. I would now like to change the color of the Image to the one selected in the droprdown List.

推荐答案

下面是加载一个JPEG一个code样品,改变任何红色像素的图像中的蓝色,然后显示在图片框的位图:

Here is a code sample that loads a JPEG, changes any red pixels in the image to blue, and then displays the bitmap in a picture box:

Bitmap bmp = (Bitmap)Bitmap.FromFile("image.jpg");
for (int x = 0; x < bmp.Width; x++)
{
    for (int y = 0; y < bmp.Height; y++)
    {
        if (bmp.GetPixel(x, y) == Color.Red)
        {
            bmp.SetPixel(x, y, Color.Blue);
        }
    }
}
pictureBox1.Image = bmp;

警告:GetPixel和是的setPixel缓慢令人难以置信。如果您的图片是大和/或性能是一个问题,还有一个更快的读取和写入。NET方式的像素,但它是多一点点的工作。

Warning: GetPixel and SetPixel are incredibly slow. If your images are large and/or performance is an issue, there is a much faster way to read and write pixels in .NET, but it's a little bit more work.

这篇关于如何改变图像的色彩在运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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