Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create image in C#

Tags:

c#

image

I have to apply a Fourier Transform on an image. For this, I want to create a new image with the transform. It is possible to create an image pixel by pixel? Or do I have to modify my basic image?

like image 480
Alexandre S. Avatar asked Nov 23 '17 14:11

Alexandre S.


People also ask

How can I display image in C?

The C language itself doesn't have any built-in graphics capability. You can use a graphics toolkit like Qt, gtk, wxWidgets, etc. You could also construct an image file (BMP is pretty simple), and then launch (using fork and exec) an application to view it.

Can we do image processing in C?

It should compile fine using commercially available C/C++ compilers. The software works on 8-bit, gray scale images in TIFF and BMP file formats. Inexpensive programs are available to convert almost any image into one of these formats. Chapter 0 introduces the C Image Processing System.

What is Stbi_load?

Function stbi_load returns a pointer to an unsigned char* buffer. The size of this buffer is width * height * channels . The image data is stored in the buffer in row order, i.e., the first width * channels bytes belong to the first row of image. The following code sets the first 10 rows of the input image to black.


1 Answers

Yes, you can do it.

public void Draw()
{
    var bitmap = new Bitmap(640, 480);

    for (var x = 0; x < bitmap.Width; x++)
    {
        for (var y = 0; y < bitmap.Height; y++)
        {
            bitmap.SetPixel(x, y, Color.BlueViolet);
        }
   }

   bitmap.Save("m.bmp");
}

But it may be slowly, if you want draw big bitmaps.

You can draw in the same way on an existing image. You can get it like this:

var bitmap = new Bitmap("source.bmp");

Use this constructor to open images with the following file formats: BMP, GIF, EXIF, JPG, PNG and TIFF.

like image 68
Anton Gorbunov Avatar answered Oct 18 '22 20:10

Anton Gorbunov