本文整理汇总了C++中CAImage::initWithRawData方法的典型用法代码示例。如果您正苦于以下问题:C++ CAImage::initWithRawData方法的具体用法?C++ CAImage::initWithRawData怎么用?C++ CAImage::initWithRawData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CAImage
的用法示例。
在下文中一共展示了CAImage::initWithRawData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getEmojiImage
CAImage* CAEmojiFont::getEmojiImage(unsigned int codepoint, unsigned long nFontSize)
{
int best_match = 0;
int diff = std::abs((int)(nFontSize - m_CurFontFace->available_sizes[0].width));
for (int i = 1; i < m_CurFontFace->num_fixed_sizes; ++i) {
int ndiff = std::abs((int)(nFontSize - m_CurFontFace->available_sizes[i].width));
if (ndiff < diff) { best_match = i; diff = ndiff; }
}
FT_Select_Size(m_CurFontFace, best_match);
uint32_t glyph_index = FT_Get_Char_Index(m_CurFontFace, codepoint);
if (glyph_index == 0)
return NULL;
FT_Error error = FT_Load_Glyph(m_CurFontFace, glyph_index, FT_LOAD_COLOR);
if (error)
return NULL;
error = FT_Render_Glyph(m_CurFontFace->glyph, FT_RENDER_MODE_NORMAL);
if (error)
return NULL;
int w = (m_CurFontFace->glyph->advance.x >> 6);
int h = static_cast<uint32_t>(m_CurFontFace->glyph->metrics.height >> 6);
int size = w * h * 4;
std::vector<uint8_t> bitmap;
bitmap.resize(size);
bitmap.assign(size, 0x00);
FT_GlyphSlot slot = m_CurFontFace->glyph;
uint8_t* src = slot->bitmap.buffer;
// FIXME: Should use metrics for drawing. (e.g. calculate baseline)
int yoffset = h - slot->bitmap.rows;
for (int y = 0; y < slot->bitmap.rows; ++y) {
uint8_t* dest = &bitmap[((y + yoffset) * w) * 4];
for (int x = 0; x < slot->bitmap.width; ++x) {
uint8_t b = *src++, g = *src++, r = *src++, a = *src++;
*dest++ = r; *dest++ = g; *dest++ = b; *dest++ = a;
}
}
CAImage* image = new CAImage();
if (!image->initWithRawData(&bitmap[0], CAImage::PixelFormat_RGBA8888, w, h))
{
delete image;
return NULL;
}
image->autorelease();
return image;
}
示例2: getWebViewImage
CAImageView* CAWebViewImpl::getWebViewImage()
{
getWebViewImageJNI(_viewTag);
if (!s_cszWebViewImageData.empty())
{
DSize size = _webView->getBounds().size;
CAImage* pImage = new CAImage();
if (!pImage->initWithRawData((const unsigned char*)&s_cszWebViewImageData[0], CAImage::PixelFormat_RGBA8888, size.width, size.height))
{
delete pImage;
return NULL;
}
pImage->autorelease();
return CAImageView::createWithImage(pImage);
}
return NULL;
}