One of the things I was working on today was trying to get an actual image from the library was that initially I was expecting to get a PublishingImage. All the samples on MSDN and the ones strewn about the web refer to using the ImageFieldValue and getting it from a field in the SPListItem. Like outlined on MSDN :
// Retrieve the current value from an SPListItem with a // column of the ImageField type with the name imageFieldName ImageFieldValue currentFieldValue = listItemWithImageField[imageFieldName] as ImageFieldValue;
The problem is this only works for images that are in a list, like the PublishingRollupImage of a page that links to an image in the Site Collection Images library. The actual images in the library are stored as documents (Referenced using SPFile) so in order utilize them I need to extract the information out and create an image tag for it...like so:
ImageFieldValue imageValue = new ImageFieldValue(
string.Format("<img src=\"{0}\" alt=\"{1}\" />",
file.Url, file.Title == null ? string.Empty : file.Title));
Now that I had the ImageFieldValue it was easy to work with. I could manipulate many aspects of the image using this object and then save it for rendering using ToString(). Funny thing is for my purposes (ImageGallery xml generation) I didn't even end up needing this code after all...frustrating but a good learning experience.
Props to Phanat Chan as he did the initial development on this.
