本文整理汇总了C++中Asset::close方法的典型用法代码示例。如果您正苦于以下问题:C++ Asset::close方法的具体用法?C++ Asset::close怎么用?C++ Asset::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Asset
的用法示例。
在下文中一共展示了Asset::close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: decodeAsset
bool RenderSkinNinePatch::decodeAsset(AssetManager* am, const char* filename, NinePatch* ninepatch) {
Asset* asset = am->open(filename, android::Asset::ACCESS_BUFFER);
if (!asset) {
asset = am->openNonAsset(filename, android::Asset::ACCESS_BUFFER);
if (!asset) {
return false;
}
}
SkImageDecoder::Mode mode = SkImageDecoder::kDecodePixels_Mode;
SkBitmap::Config prefConfig = SkBitmap::kNo_Config;
SkMemoryStream stream(asset->getBuffer(false), asset->getLength());
SkImageDecoder* decoder = SkImageDecoder::Factory(&stream);
if (!decoder) {
asset->close();
ALOGE("RenderSkinNinePatch::Failed to create an image decoder");
return false;
}
decoder->setSampleSize(1);
decoder->setDitherImage(true);
decoder->setPreferQualityOverSpeed(false);
NinePatchPeeker peeker(decoder);
SkAutoTDelete<SkImageDecoder> add(decoder);
decoder->setPeeker(&peeker);
if (!decoder->decode(&stream, &ninepatch->m_bitmap, prefConfig, mode, true)) {
asset->close();
ALOGE("RenderSkinNinePatch::Failed to decode nine patch asset");
return false;
}
asset->close();
if (!peeker.fPatch) {
ALOGE("RenderSkinNinePatch::Patch data not valid");
return false;
}
void** data = &ninepatch->m_serializedPatchData;
*data = malloc(peeker.fPatch->serializedSize());
peeker.fPatch->serialize(*data);
return true;
}
示例2: initTexture
status_t BootAnimation::initTexture(Texture* texture, AssetManager& assets,
const char* name) {
Asset* asset = assets.open(name, Asset::ACCESS_BUFFER);
if (!asset)
return NO_INIT;
SkBitmap bitmap;
SkImageDecoder::DecodeMemory(asset->getBuffer(false), asset->getLength(),
&bitmap, SkBitmap::kNo_Config, SkImageDecoder::kDecodePixels_Mode);
asset->close();
delete asset;
// ensure we can call getPixels(). No need to call unlock, since the
// bitmap will go out of scope when we return from this method.
bitmap.lockPixels();
const int w = bitmap.width();
const int h = bitmap.height();
const void* p = bitmap.getPixels();
GLint crop[4] = { 0, h, w, -h };
texture->w = w;
texture->h = h;
glGenTextures(1, &texture->name);
glBindTexture(GL_TEXTURE_2D, texture->name);
switch (bitmap.getConfig()) {
case SkBitmap::kA8_Config:
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA,
GL_UNSIGNED_BYTE, p);
break;
case SkBitmap::kARGB_4444_Config:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,
GL_UNSIGNED_SHORT_4_4_4_4, p);
break;
case SkBitmap::kARGB_8888_Config:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,
GL_UNSIGNED_BYTE, p);
break;
case SkBitmap::kRGB_565_Config:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB,
GL_UNSIGNED_SHORT_5_6_5, p);
break;
default:
break;
}
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
return NO_ERROR;
}
示例3: XmlBlock
AssetManagerGlue::XmlBlock*
AssetManagerGlue::openXmlAssetNative(int cookie, const NativeString& fileName)
{
Asset* a = cookie
? AssetManager::openNonAsset((void*)cookie, String8(fileName), Asset::ACCESS_BUFFER)
: AssetManager::openNonAsset(String8(fileName), Asset::ACCESS_BUFFER);
if (!a)
return NULL;
XmlBlock* block = new XmlBlock();
status_t err = block->setTo(a->getBuffer(true), a->getLength(), true);
a->close();
delete a;
if (err != NO_ERROR)
return NULL;
return block;
}
示例4: tag
Vector<String8> getNfcAidCategories(AssetManager& assets, String8 xmlPath, bool offHost,
String8 *outError = NULL)
{
Asset* aidAsset = assets.openNonAsset(xmlPath, Asset::ACCESS_BUFFER);
if (aidAsset == NULL) {
if (outError != NULL) *outError = "xml resource does not exist";
return Vector<String8>();
}
const String8 serviceTagName(offHost ? "offhost-apdu-service" : "host-apdu-service");
bool withinApduService = false;
Vector<String8> categories;
String8 error;
ResXMLTree tree;
tree.setTo(aidAsset->getBuffer(true), aidAsset->getLength());
size_t len;
int depth = 0;
ResXMLTree::event_code_t code;
while ((code=tree.next()) != ResXMLTree::END_DOCUMENT && code != ResXMLTree::BAD_DOCUMENT) {
if (code == ResXMLTree::END_TAG) {
depth--;
const char16_t* ctag16 = tree.getElementName(&len);
if (ctag16 == NULL) {
*outError = "failed to get XML element name (bad string pool)";
return Vector<String8>();
}
String8 tag(ctag16);
if (depth == 0 && tag == serviceTagName) {
withinApduService = false;
}
} else if (code == ResXMLTree::START_TAG) {
depth++;
const char16_t* ctag16 = tree.getElementName(&len);
if (ctag16 == NULL) {
*outError = "failed to get XML element name (bad string pool)";
return Vector<String8>();
}
String8 tag(ctag16);
if (depth == 1) {
if (tag == serviceTagName) {
withinApduService = true;
}
} else if (depth == 2 && withinApduService) {
if (tag == "aid-group") {
String8 category = AaptXml::getAttribute(tree, CATEGORY_ATTR, &error);
if (error != "") {
if (outError != NULL) *outError = error;
return Vector<String8>();
}
categories.add(category);
}
}
}
}
aidAsset->close();
return categories;
}