本文整理汇总了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));
}
}
示例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;
}
}