How to rasterize a vector image in C++ Win32 API

423 Views Asked by At

recently I have been trying to experiment with vector graphics in C++. I want to make a Win32 app that reads an svg file and shows it on the screen. The program currently is simple. A window opens using the Win32 API and a .svg file is selected. This svg file's data is then converted to a struct data of my own. The conversion is good. The code of struct is as follows:

#pragma once

#include <vector>
#include "Rect.h"

class VectorTexture
{
public:
    enum ShapeType
    {
        // Circle: x, y, r
        Circle,
        // Line: x1, y1, x2, y2, width
        Line,
        // Rectangle: x, y, width, height
        Rectangle,
        // Square: x, y, a
        Square,
        // Polygon: x[n], y[n]
        Polygon
    };

    struct Shape
    {
    public:
        ShapeType type;
        float data[];
    };

    Rect rect;
    std::vector<Shape> shapes;
};

Now, the next step is show the svg image. How can I rasterize the vector data that I have, to give me HBITMAP that I can show on the screen? If you know any resources, please put up a link.

Thanks in advance.

1

There are 1 best solutions below

1
R. Théo On

I found two very interesting links redirecting to "similar" issues that might help you :

  1. Convert Vector Unsigned char to HBITMAP in C
  2. Creating HBITMAP from Memory Buffer

Also have a look at GDI+ docs.

Keep us in touch.