picture result

Cyril Bosselut bosselut at b1project.com
Fri Jul 30 19:58:29 CEST 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,
i've finally found how to add a picture :)

		TagLib::ID3v2::AttachedPictureFrame *p = 0l;
		TagLib::ID3v2::FrameList l= f.ID3v2Tag()->frameListMap()["APIC"];
		if (!l.isEmpty()){
			TagLib::ID3v2::FrameList::ConstIterator it = l.begin();
			while(it != l.end()){
				p =  static_cast<TagLib::ID3v2::AttachedPictureFrame *>(l.front());
				if(p->type() == TagLib::ID3v2::AttachedPictureFrame::FrontCover){
					break; // Search if a pic of the correct type already exist
						  //(in my case FrontCover)
						  // or take the last picture
						  //(in most of case 0x00 cause less programs set the picture type)
				}
				++it;
			}
		}
		else{
			p = new TagLib::ID3v2::AttachedPictureFrame; // Create a new frame if
											      // there's none
		}
		KMimeMagicResult *result = KMimeMagic::self()->findFileType(ncover);
		if(result->mimeType() == "image/png" || result->mimeType() == "image/jpeg"){
			QString format = "JPEG";
			if(result->mimeType() == "image/png"){
				format= "PNG";
			}
			p->setMimeType(QStringToTString(result->mimeType()));
			p->setType(TagLib::ID3v2::AttachedPictureFrame::FrontCover);
			QPixmap file( ncover ); // load pic in QPixmap
			QByteArray data;
			QBuffer buffer( data );
			buffer.open( IO_WriteOnly );
			file.save( &buffer, format ); // save QPixmap in a QByteArray
			p->setPicture(TagLib::ByteVector(data, data.size())); // load data in the 
frame
			if (l.isEmpty()){
				f.ID3v2Tag()->addFrame(p); // add frame if there's none
			}
		}

Ok, i whish this will help :)
Bye,
	Cyril.

- -- 
L'argent ne fait pas le bonheur... de celui qui m'en a prete !
	-- P. Perret
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBCoxF9J4lbJfupC0RAuZZAKCIAHzHnlV17FjHYQ+uZYTDvF+iTQCeJHdE
xW5XfYU+YR9MvYQ6LWA9wpo=
=G7gq
-----END PGP SIGNATURE-----


More information about the taglib-devel mailing list