C# How to create Color spectrum (bitmap) - c#

How can I create a bitmap that looks something like this?
Rectangle picture. Bottom is for dark colors. Top is for bright colors. Colors are changing from left to right.
I need to create my own color spectrum bitmap because (external)image files are often compressed and not showing the correct colors in particular pixels.

Related

Giving a Material two different colors using a png Mask

I am trying the put a logo onto my object. I have a png image I want to use as a mask and two colors, one for the logo and one for the background.
So far I have managed to create two Materials for the same submesh, with one being the transparent image and the other being the background:
The color of the logo isn't changable though, as it is the image that is being displayed.
Is there a way to use the png as a mask, but change the color that is used?
Will I need to write a shader, or have I missed something in the material inspector?
Thanks in advance :)
Using two materials for the same submesh is a terrible idea, it has very low performance, it is not like having two passes in the same shader.
What you can do is creating a new shader that receives two textures:
One texture will have only 0 in the space for the logo and white in the other places
The other texture will be white in the logo and have 0 in the other pixels
Then you will have two color properties:
One will multiply with your "background" texture
The other will multiply with your "Logo" texture
Then Add both textures and assign them to the Albedo node.
You can do the same using a blend mask:
You will have a mask Map (basically it`s the Alpha channel) and put 0 in all places but where the logo pixels are.
Also you will need 2 colors properties.
Then use the blend node in the ShaderGraph to merge both textures.
Using the Blend mask you don't need the other two textures, only the mask and you can create maps in the ShaderGraph with the color properties.

How to draw half a pixel in C#?

I work with bitmap images in pictureBoxes, and color some pixels. I wonder if it is possible to fill just half of pixel? If yes, how to perform it in C# ?
You can't set color of just half of a pixel in bitmap.
You may be looking for sub-pixel rendering where RGB colors of individual pixels on a LCD screen are adjusted separately or anti-aliasing where the color of pixels of single object essentially bleeds to nearby pixels to provide smoother edges.

Get Black Pixels of Writablebitmap using c# WP8.1 Silverlight

I have a black & white writable bitmap.
What I would like to do is get all the pixels that have black color and I also want their location in form of coordinates e.g. inside arrays x[] and y[].
How can search pixels in an image in c#?

How can I draw legible text on a bitmap (Winforms)?

I've written a photo viewer, and I want to superimpose text over the photo. I want the font or font color to make the text as legible as possible on top of the bitmap, no matter what the underlying bitmap looks like.
My current thinking is to take the region of the bitmap where the text will appear, and make some kind of "overall color" calculation for that area, and then set the font color to be something correspondingly contrasting.
However, this math is way over my head. Has anybody seen a method for making this type of "what's the average color of all of these pixels" calculation? Or is that not even the best approach?
EDIT: I'm moving the second portion of this to another question.
You can use this to calculate average color of a region of bitmap:
How to calculate the average rgb color values of a bitmap
Do you store your image as a Bitmap?
You can also draw an outlined text. For example, white text with black outline. This will make text visible on most of backgrounds:
How to Drawing Text with Outline onto Images?

How to resolve anti-aliasing when changing color of an image in C#?

I am processing images to change their color from black to red, blue, green etc based on the requirement. I use SetPixel methods to change color of each pixel of the image from black to say red.
It works mostly fine except the borders and some curves within the image. Let's say I've circled image filled with black color. Circled image color is changed but still when I zoom, I can see blackish dots around border which is not completely replaced with red color. I tried to dig around and found that it has something to do with anti-aliasing.
Has anything faced similar problem or have thoughts/suggestions on how to fix this issue?
Many thanks in advnace for your help!
Regards,
Tanush
It can be related with anti-aliasing. Anti-aliasing essence is that the more pixel is closer to the edge (boundary of something) the more pixel color is blended with background color (or we can say that it is more 'transparent').
So the problem may be that you need not only to replace source color to destination color, but also pixels which were blended from source color to background color.
To achieve this you need:
1) Run edge detection algorithm of some kind - it may be simple or advanced as you want.
2) If pixel is near edge and pixel is near other pixel of your source color, then calculate it's opacity (1-transparency) factor- which will be
opacity = (pixel_color-background_color)/(source_color-background_color)
3) Now calculate your color to which you must replace current anti-aliased pixel:
new_color = background_color * (1-opacity) + opacity * target_color
And put this new_color instead of antialiased pixel.
In summary:
You need to detect antialiased pixels and replace them with your version of antialiased pixels.
Hardest part of algorithm is detection of antialiased pixels - because you can't be sure that you found all edge pixels with 100% probability. Also you can't be sure was pixel antialiased or was just made initially of such color). Because of this you may get some color noise in final product. But in any case it should be better than just sit and wait :)
good luck

Categories