当前位置: 首页>>代码示例>>C++>>正文


C++ TImage::data方法代码示例

本文整理汇总了C++中TImage::data方法的典型用法代码示例。如果您正苦于以下问题:C++ TImage::data方法的具体用法?C++ TImage::data怎么用?C++ TImage::data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TImage的用法示例。


在下文中一共展示了TImage::data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SaveImage

// store image inside png
void SaveImage(const TImage& image, const string& destFile) {
    vector<unsigned char> result(image.width() * image.height() * 4);
    unsigned char* d;
    const unsigned char* r = image.data(0, 0, 0, 0);
    const unsigned char* g = image.data(0, 0, 0, 1);
    const unsigned char* b = image.data(0, 0, 0, 2);
    int sp = image.spectrum();
    if (sp == 4) {
        const unsigned char* a = image.data(0, 0, 0, 3);
        for (d = result.data(); d < result.data() + result.size();) {
            *(d++) = *(r++);
            *(d++) = *(g++);
            *(d++) = *(b++);
            *(d++) = *(a++);
        }
    } else if (sp == 3) {
        for (d = result.data(); d < result.data() + result.size();) {
            *(d++) = *(r++);
            *(d++) = *(g++);
            *(d++) = *(b++);
            *(d++) = 255;
        }
    } else {
        throw UException("failed to save image - wrong type");
    }
    size_t err = lodepng::encode(destFile, result, image.width(), image.height());
    if (err) {
        throw UException(lodepng_error_text(err));
    }
}
开发者ID:GoBudokai,项目名称:ozifi,代码行数:31,代码来源:thumb_generator.cpp

示例2: DrawText

void TThumbGeneratorImpl::DrawText(TImage& image, size_t x, size_t y, const wstring& wtext, size_t size) {
    float scale = stbtt_ScaleForPixelHeight(&Font, size);

    int w, h, xo, yo;
    unsigned char* r = image.data(0, 0, 0, 0);
    unsigned char* g = image.data(0, 0, 0, 1);
    unsigned char* b = image.data(0, 0, 0, 2);

    size_t pos = x;
    for (size_t i = 0; i < wtext.size(); i++) {
        if (iswspace(wtext[i])) {
            pos += size * 0.3;
            continue;
        }
        unsigned char* d = stbtt_GetCodepointBitmap(&Font, 0, scale, wtext[i], &w, &h, &xo, &yo);
        for (size_t wx = 0; wx < w; wx++) {
            for (size_t wy = 0; wy < h; wy++) {
                size_t cx = pos + wx + xo;
                size_t cy = y + wy + yo + size;
                if (cy >= image.height() ||
                        cx >= image.width())
                {
                    continue;
                }
                size_t dcord = image.width() * cy + cx;
                size_t scord = wy * w + wx;
                r[dcord] = d[scord];
                g[dcord] = d[scord];
                b[dcord] = d[scord];
            }
        }
        pos += w;
    }
}
开发者ID:GoBudokai,项目名称:ozifi,代码行数:34,代码来源:thumb_generator.cpp


注:本文中的TImage::data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。