本文整理汇总了C++中BTranslatorRoster::Translate方法的典型用法代码示例。如果您正苦于以下问题:C++ BTranslatorRoster::Translate方法的具体用法?C++ BTranslatorRoster::Translate怎么用?C++ BTranslatorRoster::Translate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BTranslatorRoster
的用法示例。
在下文中一共展示了BTranslatorRoster::Translate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _changeBackground
void MediaRoutingView::_changeBackground(
entry_ref *ref)
{
D_METHOD(("MediaRoutingView::_changeBackground()\n"));
status_t error;
BBitmap *background = 0;
BFile file(ref, B_READ_ONLY);
error = file.InitCheck();
if (!error)
{
BTranslatorRoster *roster = BTranslatorRoster::Default();
BBitmapStream stream;
error = roster->Translate(&file, NULL, NULL, &stream, B_TRANSLATOR_BITMAP);
if (!error)
{
stream.DetachBitmap(&background);
setBackgroundBitmap(background);
Invalidate();
// [e.moon 1dec99] persistence, yay
m_backgroundBitmapEntry.SetTo(ref);
}
}
delete background;
}
示例2: stream
void
ImageView::SaveImageAtDropLocation(BMessage *pmsg)
{
// Find the location and name of the drop and
// write the image file there
BBitmapStream stream(fpbitmap);
StatusCheck chk;
// throw an exception if this is assigned
// anything other than B_OK
try {
entry_ref dirref;
chk = pmsg->FindRef("directory", &dirref);
const char *filename;
chk = pmsg->FindString("name", &filename);
BDirectory dir(&dirref);
BFile file(&dir, filename, B_WRITE_ONLY | B_CREATE_FILE);
chk = file.InitCheck();
BTranslatorRoster *proster = BTranslatorRoster::Default();
chk = proster->Translate(&stream, NULL, NULL, &file, B_TGA_FORMAT);
} catch (StatusNotOKException) {
BAlert *palert = new BAlert(NULL,
B_TRANSLATE("Sorry, unable to write the image file."),
B_TRANSLATE("OK"));
palert->Go();
}
stream.DetachBitmap(&fpbitmap);
}
示例3: file
status_t
SlideShowSaver::SetImage(const entry_ref *pref)
{
entry_ref ref;
if (!pref)
ref = fCurrentRef;
else
ref = *pref;
BTranslatorRoster *proster = BTranslatorRoster::Default();
if (!proster)
return B_ERROR;
if (ent_is_dir(pref) != B_OK)
// if ref is erroneous or a directory, return error
return B_ERROR;
BFile file(&ref, B_READ_ONLY);
translator_info info;
memset(&info, 0, sizeof(translator_info));
BMessage ioExtension;
//if (ref != fCurrentRef)
// if new image, reset to first document
// fDocumentIndex = 1;
if (ioExtension.AddInt32("/documentIndex", 1 /*fDocumentIndex*/) != B_OK)
return B_ERROR;
if (proster->Identify(&file, &ioExtension, &info, 0, NULL,
B_TRANSLATOR_BITMAP) != B_OK)
return B_ERROR;
// Translate image data and create a new ShowImage window
BBitmapStream outstream;
if (proster->Translate(&file, &info, &ioExtension, &outstream,
B_TRANSLATOR_BITMAP) != B_OK)
return B_ERROR;
BBitmap *newBitmap = NULL;
if (outstream.DetachBitmap(&newBitmap) != B_OK)
return B_ERROR;
// Now that I've successfully loaded the new bitmap,
// I can be sure it is safe to delete the old one,
// and clear everything
delete fBitmap;
fBitmap = newBitmap;
newBitmap = NULL;
fCurrentRef = ref;
// Get path to use in caption
fCaption = "<< Unable to read the path >>";
BEntry entry(&fCurrentRef);
if (entry.InitCheck() == B_OK) {
BPath path(&entry);
if (path.InitCheck() == B_OK) {
fCaption = path.Path();
}
}
return B_OK;
}
示例4: spath
status_t
ThemeManager::SetThemeScreenShot(int32 id, BBitmap *bitmap)
{
FENTRY;
status_t err;
BMessage msg;
BString name;
BString themepath;
BMessage *theme;
if (id < 0)
return EINVAL;
theme = (BMessage *)fThemeList.ItemAt(id);
if (!theme)
return EINVAL;
// TODO
err = theme->FindMessage(Z_THEME_INFO_MESSAGE, &msg);
if (err) {
msg.MakeEmpty();
theme->AddMessage(Z_THEME_INFO_MESSAGE, &msg);
}
err = ThemeLocation(id, themepath);
if (err)
return err;
err = msg.FindString(Z_THEME_SCREENSHOT_FILENAME, &name);
if (!err) {
BPath spath(themepath.String());
spath.Append(name.String());
BEntry ent(spath.Path());
if (ent.InitCheck() == B_OK)
ent.Remove();
}
name = "screenshot.png";
err = msg.ReplaceString(Z_THEME_SCREENSHOT_FILENAME, name);
if (err)
err = msg.AddString(Z_THEME_SCREENSHOT_FILENAME, name);
if (err)
return err;
// save the BBitmap to a png
BPath spath(themepath.String());
spath.Append(name.String());
BFile shotfile(spath.Path(), B_WRITE_ONLY|B_CREATE_FILE);
if (shotfile.InitCheck() != B_OK)
return shotfile.InitCheck();
BTranslatorRoster *troster = BTranslatorRoster::Default();
BBitmapStream bmstream(bitmap);
err = troster->Translate(&bmstream, NULL, NULL, &shotfile, 'PNG '/* XXX: hack, should find by mime type */);
if (err)
return err;
err = theme->ReplaceMessage(Z_THEME_INFO_MESSAGE, &msg);
msg.PrintToStream();
return err;
}
示例5: path
BBitmap * RBitmapLoader::TranslateBitmap(const char *name)
{
BPath path(&mAppDir, name);
BFile file(path.Path(), B_READ_ONLY);
BTranslatorRoster *roster;
BBitmapStream stream;
BBitmap *result = NULL;
roster = BTranslatorRoster::Default();
if (roster->Translate(&file, NULL, NULL, &stream, B_TRANSLATOR_BITMAP) < B_OK)
result = NULL;
else stream.DetachBitmap(&result);
return result;
}
示例6: file
/*=============================================================================================*\
| FetchBitmap |
+-----------------------------------------------------------------------------------------------+
| Effet: Converie une image en un BBitmap. La couleur de transparence est celle du pixel dans |
| le coin superieur gauche. |
| Entree: |
| char *pzFileName: Le path du fichier image a convertir. |
| bool bTran: True si on utilise la transparence, false sinon. |
| Sortie: |
| BBitmap *: Le pointeur le bitmap de l'image. NULL si la conversion a echouer. |
\*=============================================================================================*/
BBitmap*
BitmapCatalog::FetchBitmap(char* pzFileName, bool bTrans)
{
BFile file(pzFileName, B_READ_ONLY);
BTranslatorRoster *roster = BTranslatorRoster::Default();
BBitmapStream stream;
BBitmap *result = NULL;
if (roster->Translate(&file, NULL, NULL, &stream, B_TRANSLATOR_BITMAP) < B_OK)
return NULL;
stream.DetachBitmap(&result);
// OliverESP: 7 x 1 so -> #include <TranslationUtils.h> //OliverESP:
// less code and works
//BBitmap *result = BTranslationUtils::GetBitmapFile(pzFileName);
if (result == NULL)
return NULL;
if(!bTrans)
return result;
int32 iLenght = result->BitsLength() / 4;
int32 i;
int32 * cBit = (int32*)result->Bits();
int32 backColor = cBit[result->Bounds().IntegerWidth() - 1];
int32 iTrans = 0;
//Determine le mode de definition de couleur
switch(result->ColorSpace())
{
case B_RGB32: iTrans = B_TRANSPARENT_MAGIC_RGBA32; break;
case B_RGB32_BIG: iTrans = B_TRANSPARENT_MAGIC_RGBA32_BIG; break;
default: break; //TODO: Major screwup here!
}
if (iTrans)
{
for(i = 0; i < iLenght; i++)
{
if(cBit[i] == backColor)
cBit[i] = iTrans;
}
}
return result;
}
示例7: sizeof
status_t
PictureView::_LoadPicture(const entry_ref* ref)
{
BFile file;
status_t status = file.SetTo(ref, B_READ_ONLY);
if (status != B_OK)
return status;
off_t fileSize;
status = file.GetSize(&fileSize);
if (status != B_OK)
return status;
// Check that we've at least some data to translate...
if (fileSize < 1)
return B_OK;
translator_info info;
memset(&info, 0, sizeof(translator_info));
BMessage ioExtension;
BTranslatorRoster* roster = BTranslatorRoster::Default();
if (roster == NULL)
return B_ERROR;
status = roster->Identify(&file, &ioExtension, &info, 0, NULL,
B_TRANSLATOR_BITMAP);
BBitmapStream stream;
if (status == B_OK) {
status = roster->Translate(&file, &info, &ioExtension, &stream,
B_TRANSLATOR_BITMAP);
}
if (status != B_OK)
return status;
BBitmap* picture = NULL;
if (stream.DetachBitmap(&picture) != B_OK
|| picture == NULL)
return B_ERROR;
// Remember image format so we could store using the same
fPictureMIMEType = info.MIME;
fPictureType = info.type;
_SetPicture(picture);
return B_OK;
}
示例8: file
void
PersonView::Save()
{
BFile file(fRef, B_READ_WRITE);
if (file.InitCheck() != B_NO_ERROR)
return;
fSaving = true;
int32 count = fControls.CountItems();
for (int32 i = 0; i < count; i++) {
AttributeTextControl* control = fControls.ItemAt(i);
const char* value = control->Text();
file.WriteAttr(control->Attribute().String(), B_STRING_TYPE, 0,
value, strlen(value) + 1);
control->Update();
}
// Write the picture, if any, in the person file content
if (fPictureView) {
// Trim any previous content
file.Seek(0, SEEK_SET);
file.SetSize(0);
BBitmap* picture = fPictureView->Bitmap();
if (picture) {
BBitmapStream stream(picture);
// Detach *our* bitmap from stream to avoid its deletion
// at stream object destruction
stream.DetachBitmap(&picture);
BTranslatorRoster* roster = BTranslatorRoster::Default();
roster->Translate(&stream, NULL, NULL, &file,
fPictureView->SuggestedType(), B_TRANSLATOR_BITMAP,
fPictureView->SuggestedMIMEType());
}
fPictureView->Update();
}
file.GetModificationTime(&fLastModificationTime);
fSaving = false;
}
示例9: fileNameString
/*!
Save the screenshot to the file with the specified filename and type.
Note that any existing file with the same filename will be overwritten
without warning.
*/
status_t
Utility::Save(BBitmap** screenshot, const char* fileName, uint32 imageType)
const
{
BString fileNameString(fileName);
// Generate a default filename when none is given
if (fileNameString.Compare("") == 0) {
BPath homePath;
if (find_directory(B_USER_DIRECTORY, &homePath) != B_OK)
return B_ERROR;
BEntry entry;
int32 index = 1;
BString extension = GetFileNameExtension(imageType);
do {
fileNameString.SetTo(homePath.Path());
fileNameString << "/" << B_TRANSLATE(sDefaultFileNameBase) << index++
<< extension;
entry.SetTo(fileNameString.String());
} while (entry.Exists());
}
// Create the file
BFile file(fileNameString, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY);
if (file.InitCheck() != B_OK)
return B_ERROR;
// Write the screenshot bitmap to the file
BBitmapStream stream(*screenshot);
BTranslatorRoster* roster = BTranslatorRoster::Default();
roster->Translate(&stream, NULL, NULL, &file, imageType,
B_TRANSLATOR_BITMAP);
*screenshot = NULL;
// Set the file MIME attribute
BNodeInfo nodeInfo(&file);
if (nodeInfo.InitCheck() != B_OK)
return B_ERROR;
nodeInfo.SetType(_GetMimeString(imageType));
return B_OK;
}
示例10: file
/*=============================================================================================*\
| FetchBitmap |
+-----------------------------------------------------------------------------------------------+
| Effet: Converie une image en un BBitmap. La couleur de transparence est celle du pixel dans |
| le coin superieur gauche. |
| Entree: |
| char *pzFileName: Le path du fichier image a convertir. |
| bool bTran: True si on utilise la transparence, false sinon. |
| Sortie: |
| BBitmap *: Le pointeur le bitmap de l'image. NULL si la conversion a echouer. |
\*=============================================================================================*/
BBitmap * BeNetBitmapCatalog::FetchBitmap(char *pzFileName, bool bTrans)
{
BFile file(pzFileName, B_READ_ONLY);
BTranslatorRoster *roster = BTranslatorRoster::Default();
BBitmapStream stream;
BBitmap *result = NULL;
if (roster->Translate(&file, NULL, NULL, &stream,
B_TRANSLATOR_BITMAP) < B_OK)
return NULL;
stream.DetachBitmap(&result);
if(!bTrans) return result;
int32 iLenght = result->BitsLength() / 4;
int32 i;
int32 * cBit = (int32)result->Bits();
int32 backColor = cBit[result->Bounds().IntegerWidth() - 1];
int32 iTrans = 0;
//Determine le mode de definition de couleur
switch(result->ColorSpace())
{
case B_RGB32:{
iTrans = B_TRANSPARENT_MAGIC_RGBA32;
}break;
case B_RGB32_BIG:{
iTrans = B_TRANSPARENT_MAGIC_RGBA32_BIG;
}break;
}
if(iTrans)
{
for(i = 0; i < iLenght; i++)
{
if(cBit[i] == backColor)
{
cBit[i] = B_TRANSPARENT_MAGIC_RGBA32_BIG;
}
}
}
return result;
}//Fin de FetchBitmap.
示例11:
ImageView::ImageView(BPositionIO *image)
:
BView(BRect(0, 0, 1, 1), "image_view", B_FOLLOW_NONE, B_WILL_DRAW),
fSuccess(true)
{
if (!image) {
fSuccess = false;
return;
}
// Initialize and translate the image
BTranslatorRoster *roster = BTranslatorRoster::Default();
BBitmapStream stream;
if (roster->Translate(image, NULL, NULL, &stream, B_TRANSLATOR_BITMAP)
< B_OK) {
fSuccess = false;
return;
}
stream.DetachBitmap(&fImage);
}
示例12: Load
void PDocument::Load(void)
{
TRACE();
status_t err = B_OK;
BFile *file = new BFile(entryRef,B_READ_ONLY);
BMessage *node = NULL;
BTranslatorRoster *roster = NULL;
BMallocIO *output = new BMallocIO();
BMessage *loaded = new BMessage();
int32 i = 0;
translator_info *indentifed = new translator_info;
bool locked = Lock();
if (file->InitCheck() == B_OK)
{
roster = BTranslatorRoster::Default();
roster->Identify(file,NULL,indentifed,P_C_DOCUMENT_RAW_TYPE );
err = roster->Translate(file,indentifed,NULL,output,P_C_DOCUMENT_RAW_TYPE);
//buffer = (void *)output->Buffer();
if (err == B_OK)
{
err = loaded->Unflatten(output);
printf("%s",strerror(err));
loaded->PrintToStream();
ResetModified();
}
}
else
//**error handling
;
//docloader handles the Format and Stuff also the input translation
PDocLoader *docLoader = new PDocLoader(this,loaded);
delete allNodes;
delete allConnections;
delete printerSetting;
delete selected;
allNodes = docLoader->GetAllNodes();
for (i = 0; i<allNodes->CountItems(); i++)
{
node=((BMessage*)allNodes->ItemAt(i));
node->AddPointer("ProjectConceptor::doc",this);
valueChanged->AddItem(node);
}
allConnections = docLoader->GetAllConnections();
for (i = 0; i<allConnections->CountItems(); i++)
{
node= (BMessage *)allConnections->ItemAt(i);
node->AddPointer("ProjectConceptor::doc",this);
valueChanged->AddItem(node);
}
selected = docLoader->GetSelectedNodes();
delete commandManager;
commandManager= new PCommandManager(this);
commandManager->SetMacroList(docLoader->GetMacroList());
commandManager->SetUndoList(docLoader->GetUndoList());
commandManager->SetUndoIndex(docLoader->GetUndoIndex());
// commandManager->LoadMacros(docLoader->GetCommandManagerMessage());
// commandManager->LoadUndo(docLoader->GetCommandManagerMessage());
SetPrintSettings( docLoader->GetPrinterSetting());
editorManager->BroadCast(new BMessage(P_C_VALUE_CHANGED));
if (locked)
Unlock();
}
示例13: stream
void
PictureView::_HandleDrop(BMessage* msg)
{
entry_ref dirRef;
BString name, type;
bool saveToFile = msg->FindString("be:filetypes", &type) == B_OK
&& msg->FindRef("directory", &dirRef) == B_OK
&& msg->FindString("name", &name) == B_OK;
bool sendInMessage = !saveToFile
&& msg->FindString("be:types", &type) == B_OK;
if (!sendInMessage && !saveToFile)
return;
BBitmap* bitmap = fPicture;
if (bitmap == NULL)
return;
BTranslatorRoster* roster = BTranslatorRoster::Default();
if (roster == NULL)
return;
BBitmapStream stream(bitmap);
// find translation format we're asked for
translator_info* outInfo;
int32 outNumInfo;
bool found = false;
translation_format format;
if (roster->GetTranslators(&stream, NULL, &outInfo, &outNumInfo) == B_OK) {
for (int32 i = 0; i < outNumInfo; i++) {
const translation_format* formats;
int32 formatCount;
roster->GetOutputFormats(outInfo[i].translator, &formats,
&formatCount);
for (int32 j = 0; j < formatCount; j++) {
if (strcmp(formats[j].MIME, type.String()) == 0) {
format = formats[j];
found = true;
break;
}
}
}
}
if (!found) {
stream.DetachBitmap(&bitmap);
return;
}
if (sendInMessage) {
BMessage reply(B_MIME_DATA);
BMallocIO memStream;
if (roster->Translate(&stream, NULL, NULL, &memStream,
format.type) == B_OK) {
reply.AddData(format.MIME, B_MIME_TYPE, memStream.Buffer(),
memStream.BufferLength());
msg->SendReply(&reply);
}
} else {
BDirectory dir(&dirRef);
BFile file(&dir, name.String(), B_WRITE_ONLY | B_CREATE_FILE
| B_ERASE_FILE);
if (file.InitCheck() == B_OK
&& roster->Translate(&stream, NULL, NULL, &file,
format.type) == B_OK) {
BNodeInfo nodeInfo(&file);
if (nodeInfo.InitCheck() == B_OK)
nodeInfo.SetType(type.String());
} else {
BString text = B_TRANSLATE("The file '%name%' could not "
"be written.");
text.ReplaceFirst("%name%", name);
BAlert* alert = new BAlert(B_TRANSLATE("Error"), text.String(),
B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
alert->Go();
}
}
// Detach, as we don't want our fPicture to be deleted
stream.DetachBitmap(&bitmap);
}
示例14: mkstemp
status_t
OptiPNGTranslator::DerivedTranslate(BPositionIO *source,
const translator_info *info, BMessage *ioExtension,
uint32 outType, BPositionIO *target, int32 baseType)
{
if(baseType == 1 && outType == OPTIPNG_PNG_FORMAT) {
// create temp file
int tempFileFD;
BPath tempDir;
BString tempFilePath;
if(find_directory(B_SYSTEM_TEMP_DIRECTORY, &tempDir) != B_OK )
return B_ERROR;
tempFilePath.Append(tempDir.Path())
.Append("/OptiPNGTranslator.XXXXXX");
tempFileFD = mkstemp(tempFilePath.LockBuffer(0));
tempFilePath.UnlockBuffer();
if(tempFileFD == -1)
return B_ERROR;
close(tempFileFD);
BFile tempFile = BFile(tempFilePath, O_WRONLY);
// write PNG to file
off_t sourceSize;
source->GetSize(&sourceSize);
unsigned char sourceChars[sourceSize];
BTranslatorRoster *roster = BTranslatorRoster::Default();
roster->Translate(source, NULL, NULL, &tempFile, (uint32)B_PNG_FORMAT);
// optimize file
BString optipng;
if(system("optipng &> /dev/null") == 0) {
optipng = "optipng";
} else if(system("optipng-x86 &> /dev/null") == 0) {
optipng = "optipng-x86";
} else {
return B_ERROR;
}
// optipng -clobber -out (file) (file)
BString command;
command = optipng;
if(!fSettings->SetGetBool(OPTIPNG_SETTING_BIT_DEPTH_REDUCTION))
command += " -nb"; // no bit-depth reduction
if(!fSettings->SetGetBool(OPTIPNG_SETTING_COLOR_TYPE_REDUCTION))
command += " -nc";
if(!fSettings->SetGetBool(OPTIPNG_SETTING_PALETTE_REDUCTION))
command += " -np";
command.Append(" -o")
.Append((char)(fSettings->
SetGetInt32(OPTIPNG_SETTING_OPTIMIZATION_LEVEL)+'0'),1);
// rest of command
command.Append(" -clobber -out ")
.Append(tempFilePath)
.Append(" ")
.Append(tempFilePath)
;
if(system(command) != 0) {
return B_ERROR;
}
// read the file
tempFile = BFile(tempFilePath, O_RDONLY);
off_t fileSize;
tempFile.GetSize(&fileSize);
unsigned char *buffer;
buffer = new unsigned char[fileSize];
if(buffer == NULL)
return B_ERROR;
tempFile.ReadAt(0, buffer, fileSize);
target->Write(buffer, fileSize);
delete [] buffer;
// delete the file
BEntry entry = BEntry(tempFilePath);
entry.Remove();
return B_OK;
}
return B_NO_TRANSLATOR;
}
示例15: OnSaveGraph
void AppWindow::OnSaveGraph(BMessage *msg) {
entry_ref dir;
BString name, extension;
uint32 type; int i;
msg->FindRef("directory", &dir);
msg->FindString("name", &name);
GetExtension(name, extension);
for (i = 0; (file_types[i].extension != NULL) &&
(extension != file_types[i].extension); i++);
type = file_types[i].type;
if (type != 0) {
BDirectory dir2(&dir);
BEntry file(&dir2, name.String());
BPath path;
file.GetPath(&path);
BRect rect;
BBitmap *bitmap = GetGraph(rect, B_CMAP8);
if (bitmap != NULL) {
BTranslatorRoster *roster = BTranslatorRoster::Default();
BBitmapStream stream(bitmap);
BFile file(path.Path(), B_CREATE_FILE | B_WRITE_ONLY);
if (B_OK != roster->Translate(&stream, NULL, NULL, &file, type)) {
BAlert *alert = new BAlert("Error", "Error in translator!\nCould not write file", "Ok");
BEntry e(path.Path());
e.Remove();
alert->Go();
}
stream.DetachBitmap(&bitmap);
delete bitmap;
}
} else {
BAlert *alert = new BAlert("Error", "Unknown file format!", "Ok");
alert->Go();
}
/* // print output translators to stdout
translator_id *translators;
int32 num_translators;
BTranslatorRoster *roster = BTranslatorRoster::Default();
roster->GetAllTranslators(&translators, &num_translators);
for (int32 i = 0; i < num_translators; i++) {
const translation_format *fmts;
int32 num_fmts;
const char *tname, *tinfo;
int32 tversion;
roster->GetTranslatorInfo(translators[i], &tname, &tinfo, &tversion);
printf("%s: %s (%.2f)\n", tname, tinfo, tversion/100.0);
roster->GetOutputFormats(translators[i], &fmts, &num_fmts);
for (int32 j = 0; j < num_fmts; j++) {
if (fmts[j].group == B_TRANSLATOR_BITMAP) {
if (fmts[j].type == B_TRANSLATOR_BITMAP) continue;
printf("%d %d [%s] %s \"%4.4s\"\n", i, j, fmts[j].MIME, fmts[j].name,
&fmts[j].type);
break;
}
}
}
delete [] translators;
fflush(stdout);
*/
}