Monty
Monty

Reputation: 11

Getting PNG of currently playing iPod artwork at defined size

I'm trying to get a PNG representation of the currently playing iPod artwork at a size of 250x250. However I keep getting a 640x640 image instead. Code is below. Can anybody point out the doubtless bone-headed mistake I'm making?

- (NSData *) getNowPlayingPng
{
// Assume that there is no artwork for the media item.
UIImage *artworkImage = [[UIImage alloc]init];

// Get the artwork from the current media item, if it has artwork.
MPMediaItemArtwork *artwork = [iPodController.nowPlayingItem valueForProperty: MPMediaItemPropertyArtwork];

// Obtain a UIImage object from the MPMediaItemArtwork object
if (artwork) {
    artworkImage = [artwork imageWithSize:CGSizeMake(250.00, 250.00)];
}
NSData *pngimage = UIImagePNGRepresentation(artworkImage);
return pngimage;

}

Upvotes: 0

Views: 555

Answers (1)

John G
John G

Reputation: 128

i'm doing something similar and using the same code for the artworkImage. Is there a specific reason you are needing to convert to PNG? I'm just using an UIImageView component to display the artwork.

     MPMediaItemArtwork *artwork = [self.nowPlaying valueForProperty: MPMediaItemPropertyArtwork];

   self.audioImageView.image = [artwork imageWithSize:(CGSizeMake(320, 320))]; 

Upvotes: 1

Related Questions