本文整理汇总了C++中taglib::id3v2::AttachedPictureFrame::setPicture方法的典型用法代码示例。如果您正苦于以下问题:C++ AttachedPictureFrame::setPicture方法的具体用法?C++ AttachedPictureFrame::setPicture怎么用?C++ AttachedPictureFrame::setPicture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类taglib::id3v2::AttachedPictureFrame
的用法示例。
在下文中一共展示了AttachedPictureFrame::setPicture方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: attachPicture
bool MetaDSF::attachPicture(const TagLib::String &path,
const TagLib::String &ptype)
{
// Determine MIME type
TagLib::String mimeType;
TagLib::String ext = path.substr(path.rfind(".") + 1);
transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
if (extToMIMETypeMap.find(ext) == extToMIMETypeMap.end()) {
std::cerr << "Unknown image format " << ext << std::endl;
return false;
}
mimeType = extToMIMETypeMap[ext];
// Load file into memory
TagLib::ByteVector v;
if (loadFileIntoVector(path.toCString(), v) <= 0) {
return false;
}
std::string pt = ptype.toCString();
TagLib::ID3v2::AttachedPictureFrame *apic =
new TagLib::ID3v2::AttachedPictureFrame();
TagLib::ID3v2::AttachedPictureFrame::Type t =
static_cast<TagLib::ID3v2::AttachedPictureFrame::Type>(std::stoi(pt, 0, 16));
apic->setPicture(v);
apic->setMimeType(mimeType);
apic->setType(t);
_i->_file.ID3v2Tag()->addFrame(apic);
_i->_changed = true;
return true;
}
示例2: addImage
bool CTagBase::addImage(wchar_t* s)
{
if (!_tagFile) return false;
TagLib::MPEG::File *pAudioFile = (TagLib::MPEG::File *)_tagFile.get();
CString strFileName = s;
ImageFile imageFile((CW2A)strFileName.GetBuffer());
if (!pAudioFile->isValid() || !imageFile.isValid())
return false;
TagLib::ID3v2::Tag *tag = pAudioFile->ID3v2Tag(true);
TagLib::ID3v2::AttachedPictureFrame *frame = new TagLib::ID3v2::AttachedPictureFrame;
frame->setMimeType(imageFile.mimeType());
frame->setPicture(imageFile.data());
tag->addFrame(frame);
return pAudioFile->save();
}
示例3: buffer
bool
ID3v2TagHelper::setEmbeddedCover( const QImage &cover )
{
QByteArray bytes;
QBuffer buffer( &bytes );
buffer.open( QIODevice::WriteOnly );
if( !cover.save( &buffer, "JPEG" ) )
{
buffer.close();
return false;
}
buffer.close();
TagLib::ByteVector field = fieldName( Meta::valHasCover ).toCString();
TagLib::ID3v2::FrameList apicList = m_tag->frameListMap()[field];
TagLib::ID3v2::AttachedPictureFrame *frontCover = NULL;
// remove covers
TagLib::List<TagLib::ID3v2::AttachedPictureFrame*> backedUpPictures;
for( TagLib::ID3v2::FrameList::ConstIterator it = apicList.begin(); it != apicList.end(); ++it )
{
TagLib::ID3v2::AttachedPictureFrame *currFrame =
dynamic_cast< TagLib::ID3v2::AttachedPictureFrame * >( *it );
m_tag->removeFrame( currFrame, false );
}
// add new cover
frontCover = new TagLib::ID3v2::AttachedPictureFrame( field );
frontCover->setMimeType( "image/jpeg" );
frontCover->setPicture( TagLib::ByteVector( bytes.data(), bytes.count() ) );
frontCover->setType( TagLib::ID3v2::AttachedPictureFrame::FrontCover );
m_tag->addFrame( frontCover );
return true;
}
示例4: if
//.........这里部分代码省略.........
if(nullptr != trackGainFrame)
tag->removeFrame(trackGainFrame);
if(nullptr != trackPeakFrame)
tag->removeFrame(trackPeakFrame);
if(nullptr != albumGainFrame)
tag->removeFrame(albumGainFrame);
if(nullptr != albumPeakFrame)
tag->removeFrame(albumPeakFrame);
if(trackGain) {
SFB::CFString str = CreateStringFromNumberWithFormat(trackGain, kCFNumberDoubleType, CFSTR("%+2.2f dB"));
auto frame = new TagLib::ID3v2::UserTextIdentificationFrame();
frame->setDescription("replaygain_track_gain");
frame->setText(TagLib::StringFromCFString(str));
tag->addFrame(frame);
}
if(trackPeak) {
SFB::CFString str = CreateStringFromNumberWithFormat(trackPeak, kCFNumberDoubleType, CFSTR("%1.8f dB"));
auto frame = new TagLib::ID3v2::UserTextIdentificationFrame();
frame->setDescription("replaygain_track_peak");
frame->setText(TagLib::StringFromCFString(str));
tag->addFrame(frame);
}
if(albumGain) {
SFB::CFString str = CreateStringFromNumberWithFormat(albumGain, kCFNumberDoubleType, CFSTR("%+2.2f dB"));
auto frame = new TagLib::ID3v2::UserTextIdentificationFrame();
frame->setDescription("replaygain_album_gain");
frame->setText(TagLib::StringFromCFString(str));
tag->addFrame(frame);
}
if(albumPeak) {
SFB::CFString str = CreateStringFromNumberWithFormat(albumPeak, kCFNumberDoubleType, CFSTR("%1.8f dB"));
auto frame = new TagLib::ID3v2::UserTextIdentificationFrame();
frame->setDescription("replaygain_album_peak");
frame->setText(TagLib::StringFromCFString(str));
tag->addFrame(frame);
}
// Also write the RVA2 frames
tag->removeFrames("RVA2");
if(trackGain) {
auto relativeVolume = new TagLib::ID3v2::RelativeVolumeFrame();
float f;
CFNumberGetValue(trackGain, kCFNumberFloatType, &f);
relativeVolume->setIdentification(TagLib::String("track", TagLib::String::Latin1));
relativeVolume->setVolumeAdjustment(f, TagLib::ID3v2::RelativeVolumeFrame::MasterVolume);
tag->addFrame(relativeVolume);
}
if(albumGain) {
auto relativeVolume = new TagLib::ID3v2::RelativeVolumeFrame();
float f;
CFNumberGetValue(albumGain, kCFNumberFloatType, &f);
relativeVolume->setIdentification(TagLib::String("album", TagLib::String::Latin1));
relativeVolume->setVolumeAdjustment(f, TagLib::ID3v2::RelativeVolumeFrame::MasterVolume);
tag->addFrame(relativeVolume);
}
// Album art
if(setAlbumArt) {
tag->removeFrames("APIC");
for(auto attachedPicture : metadata.GetAttachedPictures()) {
SFB::CGImageSource imageSource = CGImageSourceCreateWithData(attachedPicture->GetData(), nullptr);
if(!imageSource)
continue;
TagLib::ID3v2::AttachedPictureFrame *frame = new TagLib::ID3v2::AttachedPictureFrame;
// Convert the image's UTI into a MIME type
SFB::CFString mimeType = UTTypeCopyPreferredTagWithClass(CGImageSourceGetType(imageSource), kUTTagClassMIMEType);
if(mimeType)
frame->setMimeType(TagLib::StringFromCFString(mimeType));
frame->setPicture(TagLib::ByteVector((const char *)CFDataGetBytePtr(attachedPicture->GetData()), (TagLib::uint)CFDataGetLength(attachedPicture->GetData())));
frame->setType((TagLib::ID3v2::AttachedPictureFrame::Type)attachedPicture->GetType());
if(attachedPicture->GetDescription())
frame->setDescription(TagLib::StringFromCFString(attachedPicture->GetDescription()));
tag->addFrame(frame);
}
}
return true;
}
示例5: saveFile
void saveFile(string stdPath, DataEditors* editors) {
const char* charPath = stdPath.c_str();
ifstream fileCheck(charPath);
if(!fileCheck.good()) {
QWidget *w = new QWidget();
QLabel *l = new QLabel("Invalid file!", w);
QPushButton *b = new QPushButton("OK", w);
QVBoxLayout *lay = new QVBoxLayout();
lay->addWidget(l);
lay->addWidget(b);
w->setLayout(lay);
QWidget::connect(b, SIGNAL(clicked()), w, SLOT(close()));
w->show();
return;
}
TagLib::FileName name = charPath;
TagLib::FileRef file(name);
if(editors->artist->isEnabled())
file.tag()->setArtist(editors->artist->text().toStdString());
if(editors->album->isEnabled())
file.tag()->setAlbum(editors->album->text().toStdString());
if(editors->track->isEnabled())
file.tag()->setTrack(editors->track->text().toInt());
if(editors->title->isEnabled())
file.tag()->setTitle(editors->title->text().toStdString());
if(editors->year->isEnabled())
file.tag()->setYear(editors->year->text().toInt());
if(editors->genre->isEnabled())
file.tag()->setGenre(editors->genre->currentText().toStdString());
if(editors->comment->isEnabled())
file.tag()->setComment(editors->comment->toPlainText().toStdString());
file.save();
if(editors->picture->isEnabled()) {
TagLib::MPEG::File mpegFile(name);
TagLib::ID3v2::Tag *tag = mpegFile.ID3v2Tag(true);
TagLib::ID3v2::AttachedPictureFrame *frame = new TagLib::ID3v2::AttachedPictureFrame;
QString picture = editors->picture->text();
if(picture == "<Attached picture>") {
TagLib::ID3v2::AttachedPictureFrame *f =
static_cast<TagLib::ID3v2::AttachedPictureFrame *>(editors->mpegFile->ID3v2Tag(true)->frameList("APIC").front());
frame->setMimeType(f->mimeType());
frame->setPicture(f->picture());
tag->removeFrames("APIC");
tag->addFrame(frame);
mpegFile.save();
} else if(picture == "") {
tag->removeFrames("APIC");
mpegFile.save();
} else {
frame->setMimeType("image/jpeg");
string stdPic = picture.toStdString();
const char* charPicture = stdPic.c_str();
ifstream fileCheck(charPicture);
if(!fileCheck.good()) {
QWidget *w = new QWidget();
QLabel *l = new QLabel("Invalid picture!", w);
QPushButton *b = new QPushButton("OK", w);
QVBoxLayout *lay = new QVBoxLayout();
lay->addWidget(l);
lay->addWidget(b);
w->setLayout(lay);
QWidget::connect(b, SIGNAL(clicked()), w, SLOT(close()));
w->show();
delete w;
return;
}
ImageFile imageTagLibFile(charPicture);
frame->setPicture(imageTagLibFile.data());
tag->removeFrames("APIC");
tag->addFrame(frame);
mpegFile.save();
}
}
}