Color picker image created by .NET?

Are there any algorithms for creating programmatically images, for use as a base for controlling color selection?

If you know some useful sources for a document or code on this topic, they are welcome.

EDIT: my idea is to create a WPF Picker Control, I know that there is already WPF, Sacha one , or one of Microsoft's examples there . The point of this question is not too focused on the technology that I will use later, but on the algorithm for creating the image .

EDIT2: I would like to create something like a gradient image squared, programmatically.

alt text http://patterns.holehan.org/uploads/gimp_color_chooser.png

+3
source share
1 answer

Here are a few possibilities:

  • Create an image using overlapping linear gradient brushes.
  • Create the image as a bitmap.
  • Create an image during rendering using pixel shaders.

Overlapping gradient brushes

For the image that you showed, you can achieve the desired effect using something in this direction:

<Grid>
  <Rectangle>
    <Rectangle.Fill>
      <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
        <GradientStop Offset="0" Color="#FFFF8040" />
        <GradientStop Offset="1" Color="#FFFFFFFF" />
      </LinearGradientBrush>
    </Rectangle.Fill>
  </Rectangle>
  <Rectangle>
    <Rectangle.Fill>
      <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
        <GradientStop Offset="0" Color="#FF000000" />
        <GradientStop Offset="1" Color="#00000000" />
      </LinearGradientBrush>
    </Rectangle.Fill>
  </Rectangle>
</Grid>

The first fill sets the color, and the second fill darkens it. Obviously, this can be done in Drawing or VisualBrush.

This is the simplest solution, but it is limited by what it can produce.

Creating a bitmap image

, . . , . , . , : TransformToDevice , WPF .

, :

uint[] pixels = new uint[width*height];
for(int x=0; x<width; x++)
  for(int y=0; y<height; y++)
    pixels[y*width + x] = ComputeColor(x, y);

var bitmap = new WritableBitmap(width, height, 96, 96, PixelFormat.Pbgra32, null);
bitmap.WritePixels(new Rect(0, 0, width, height), pixels, width*4, 0);

, . , . , # VB.NET: (HLSL), .

- :

WPF

+3

Source: https://habr.com/ru/post/1734911/


All Articles