Hi,
ich habe folgenden Code:
Alles anzeigen
Ich konvertiere ein NSImage zu NSData, erstelle daraus NSData vom Typ PNG und erzeuge einen neuen BytesVector. Allerdings klappt das gar nicht.
NSLog(@"%s", (const char *)pngData.bytes); liefert: "âPNG
"
Und NSLog(@"%@", pngData); liefter mir ganz normal die Daten, also das Objekt ist nicht leer oder so. DIe Konvertierung von void* zu const char* scheint das Problem zu sein. Wo liegt der Fehler?
Viele Grüße
ich habe folgenden Code:
Quellcode
- if (_artwork) {
- //Init data to png transformer
- NSBitmapImageRep *bits = [[NSBitmapImageRep alloc] initWithCGImage:[_artwork CGImageForProposedRect:NULL
- context:nil
- hints:nil]];
- //Art work as png data
- NSData *pngData = [bits representationUsingType:NSPNGFileType properties:nil];
- //Set artwork with TagLib
- //Init TagLib audio object
- TagLib::MPEG::File audioFile(_filePath.UTF8String);
- //Enable neccessary tag type
- TagLib::ID3v2::Tag *tag = audioFile.ID3v2Tag(true);
- //Init artwoork frame
- TagLib::ID3v2::AttachedPictureFrame *frame = new TagLib::ID3v2::AttachedPictureFrame;
- //Configure artwork frame
- frame->setMimeType("image/png");
- TagLib::ByteVector *bytes = new TagLib::ByteVector((const char *)pngData.bytes);
- frame->setPicture(*bytes);
- //Add artwork to audio file
- tag->addFrame(frame);
- audioFile.save();
- }
Ich konvertiere ein NSImage zu NSData, erstelle daraus NSData vom Typ PNG und erzeuge einen neuen BytesVector. Allerdings klappt das gar nicht.
NSLog(@"%s", (const char *)pngData.bytes); liefert: "âPNG
"
Und NSLog(@"%@", pngData); liefter mir ganz normal die Daten, also das Objekt ist nicht leer oder so. DIe Konvertierung von void* zu const char* scheint das Problem zu sein. Wo liegt der Fehler?
Viele Grüße