Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 位图中的ttc字体在c++;_C++_Fonts_Bitmap - Fatal编程技术网

C++ 位图中的ttc字体在c++;

C++ 位图中的ttc字体在c++;,c++,fonts,bitmap,C++,Fonts,Bitmap,有没有一种简单的方法可以将字体插入位图图像? 目前,我使用以下类编辑位图: class BitmapImg{ public: BitmapImg(); ~BitmapImg(); void setPixel(int x, int y, int redn, int greenn, int bluen); void getPixel(int x, int y, int& redn, int& greenn, int& bluen); private: unsigne

有没有一种简单的方法可以将字体插入位图图像? 目前,我使用以下类编辑位图:

class BitmapImg{
public:
 BitmapImg();
 ~BitmapImg();
 void setPixel(int x, int y, int redn, int greenn, int bluen);
 void getPixel(int x, int y, int& redn, int& greenn, int& bluen);
private:
 unsigned short int red[1080][1080]; //1080X1080 Pixels
 unsigned short int green[1080][1080];
 unsigned short int blue[1080][1080];
};
但现在我已经开始通过xbm文件将字母导入XCode,然后XCode使用各种循环来更改数组中的RGB值。但这个解决方案非常复杂

此外,我有问题,以获得单一位了。目前,我使用此循环更改位图图像中的像素:

BitmapImg Picture;
// ctor makes is completely blue -> no problem with the whit color below
int counter = 0;
for (int y=0;y<=199;y++)
{
    for (int x = 0; x<=199 ;x++)
    {
        for (int n = 0; n<16;n++)
        {
            bool bit =(A_bits[counter]>>n) & 1U;

            if(bit)
              Picture.setPixel(counter%200,counter%200,255,255,255);
            counter ++;
            std::cout << counter<< std::endl; //for debugging
        }
    }
}
bitmap图片;
//ctor完全是蓝色->下面的白色没有问题
int计数器=0;
对于(int y=0;y
此外,我在获取单个位时遇到问题。目前我使用此循环更改位图图像中的像素:

BitmapImg Picture;
// ctor makes is completely blue -> no problem with the whit color below
int counter = 0;
for (int y=0;y<=199;y++)
{
    for (int x = 0; x<=199 ;x++)
    {
        for (int n = 0; n<16;n++)
        {
            bool bit =(A_bits[counter]>>n) & 1U;

            if(bit)
              Picture.setPixel(counter%200,counter%200,255,255,255);
            counter ++;
            std::cout << counter<< std::endl; //for debugging
        }
    }
}
基本上,你在这里要做的就是把像素从一幅图像复制到另一幅图像上。XBM只是一种非常基本的单声道格式,所以只需要将像素设置为所需的颜色(前景)或保持原样(背景)

这与您所拥有的非常接近。请注意,这将在图像的左上角(0,0)绘制它,并假设目标图像足够大。您应该添加边界检查以安全地剪裁绘制

void draw_A(BitmapImg &picture, unsigned short r, unsigned short g, unsigned short b)
{
    for (int y = 0; y < A_height; ++y)
    {
        for (int x = 0; x < A_width; ++x)
        {
            unsigned bytes_per_row = (A_width + 7) / 8; // divide rounding up
            unsigned row_byte = x / 8; // 8 bits per byte
            unsigned row_bit = x % 8;
            unsigned char src_byte = A_bits[y * bytes_per_row + row_byte]; // row by row, left to right, top to bottom
            bool src_bit = ((src_byte >> row_bit) & 0x1) != 0; // least signifcant bit (1) is first
            if (src_bit)
            {
                picture.setPixel(x, y, r, g, b);
            }
        }
    }
}
请注意,这是一种非常不常见的存储图像数据的方法,通常每个像素都保存在一个数组中,而且2D数组不能动态调整大小(您不能执行
p=new unsigned short[width][height];p[50][40]=10;

例如,8bpp 24位RGB可能存储为
无符号字符像素[width*height*3];像素[50*3+40*width*3+1]=10;/*将绿色设置为(50,40)*/
。在许多库和文件格式中处理图像数据时,您会看到这一点。尽管要注意,某些图像格式尤其是从底部开始,而不是从顶部开始

但现在我已经开始通过xbm文件将字母导入XCode,然后XCode使用各种循环来更改数组中的RGB值。但是这个解决方案非常复杂

直接处理图像会变得非常复杂,尤其是在开始考虑透明度/混合、变换(如缩放、旋转)以及需要处理的所有不同图像格式(索引颜色、16、24、32等位整数像素、自下而上而非自上而下的格式等)时

周围有许多图形库,包括硬件加速和软件、特定平台(例如所有Windows GDI、DirectWrite、Direct2D、Direct3D等)这些库中的许多都支持这种风格的输入和输出图像,对特定像素使用不同的格式,如果需要,还提供了大量的解决方案将一种格式转换为另一种格式