Как перекрасить пиксель формы в winforms
Перейти к содержимому

Как перекрасить пиксель формы в winforms

Перекрашивание изображений

Перекрашивание — это процесс коррекции цветов изображения. Примерами перекрашивания являются изменение одного цвета на другой, коррекция интенсивности цвета относительно другого цвета, коррекция яркости или контрастности всех цветов и преобразование цветов в оттенки серого.

в этом разделе

Практическое руководство. Преобразование цветов изображения
Описание того, как преобразовывать цвета с помощью цветовой матрицы.

Масштабирование цветов с применением преобразований
Описание того, как масштабировать цвета с помощью цветовой матрицы.

Практическое руководство. Циклический сдвиг цветов
Описание того, как выполнить циклический сдвиг цветов с помощью цветовой матрицы.

Практическое руководство. Сдвиг цветов
Определение сдвига и объяснение того, как сдвигать цвета с помощью цветовой матрицы.

Практическое руководство. Использование таблицы перераспределения цветов
Определение переназначения и описание того, как использовать таблицу переназначения цветов.

Справочник

ColorMatrix
Описание класса и ссылки на разделы с описаниями всех его членов.

ColorMap
Описание класса и ссылки на разделы с описаниями всех его членов.

См. также

Работа с растровыми и векторными изображениями
Список разделов, где показано, как использовать различные типы изображений.

Использование управляемых графических классов
Список разделов, в которых описывается использование управляемых графических классов.

How to Change Pixel Color of an Image in C#.NET

I am working with Images in Java, I have designed more over 100+ images(.png) format, They were all Trasparent and Black Color Drawing.

The problem is, Now I have been asked to change the color of the Drawing (Black -to ).

I have searched many code snipped at google,that changes the Bitmap (pixels) of the Image, but i am not guessing what i have to do to match the exact pixel and replace specially when the images if in Transparent mode. Below is the code in .Net (C#)

but it was not matching at all, I debugged it, throughout the file, there was no value of Red,Green,Blue parameters of Color (originalColor) variable.

Anybody can help?

user avatar

4 Answers 4

Here is the Solution I have done with Pixels.

Attaching the source code so one can try the exact and get the result.

I have sample images of 128×128 (Width x Height).

//Below is the sample image and different results by applying different color enter image description here

Code modifications will be highly appreciated.

user avatar

Before we talk about perfromance let’s check your code:

Here there are two errors:

  1. You do not compare to Color.Black but you assign Color.Black to originalColor .
  2. You do not handle transparency.

To check for transparency you should compare not the Color object but the R, G, B values, let’s change to:

Now you’ll see that it works but it takes a very long time to process each image: GetPixel and SetPixel are pretty slow (primary because they check and calculate everything for each call). It’s much better to handle bitmap data directly. If you know the image format in advance (and it’s fixed for each image) then you can do it much much faster with little bit more code:

Of course this can be further optimized and you may need to handle different formats ( see this list of pixel formats and this article about their layout) but consider it a starting point to work with bitmaps.

For completeness this is equivalent color without direct access to bitmap data. Please note that this should be rarely used because it’s terribly slow.

Also please note that this consider alpha channel in comparison (so 50% transparent green, for example, is not same color as 30% transparent green). To ignore alpha you may use something like this:

Как изменить дизайн windows form в visual studio

Изменить цвет формы из другой формы
Доброго времени суток! Создаю Form1 закидываю на неё Button1. При нажатии на Button1 открывается.

По каждому щелчку мыши изменить цвет формы
Уважаемые, с языком С# сталкиваюсь впервые, и со средой разработки Visual Studio — в частности.

Если введенная дата–выходной, изменить цвет фона формы
В текстовом поле вводится дата. Если введённая дата–выходной (суббота, воскресенье) , то форма.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *