1

I can't show the real name of my photos of my picture library in windows phone 8. I have a there photos whose original names are: chucktodd-einstein-2010-1.jpg, chucktodd-einstein-2010-2.jpg,chucktodd-einstein-2010-3.jpg.

I execute this code:

MediaLibrary m = new MediaLibrary();        
for (int j = 0; j < m.Pictures.Count; j++)
{
     var r = m.Pictures[j];
     MessageBox.Show(r.Name);
}

And MessageBox show always this name : "Einstein writing on a blackboard with chalk illustration by chuck Todd 2010".

How can you Obtain the original name?

crm27
  • 73
  • 9

4 Answers4

2

I found this Library and fixed this issue:

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.media.phoneextensions.medialibraryextensions.getpath(v=xnagamestudio.42).aspx

using Microsoft.Xna.Framework.Media.PhoneExtensions;

MediaLibrary m = new MediaLibrary();        
for (int j = 0; j < m.Pictures.Count; j++)
{
  var r = m.Pictures[j];
  MessageBox.Show(MediaLibraryExtensions.GetPath(r));
}

With this code I obtain the full path of file with the original name.

crm27
  • 73
  • 9
0

You can try this:

r.getPath();

and then strip the folder in the path.

goda87
  • 31
  • 5
  • the method r.getPath(); doesn't exist in 'r'. – crm27 Jul 16 '13 at 09:25
  • http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.media.phoneextensions.medialibraryextensions.getpath(v=xnagamestudio.42).aspx – crm27 Jul 23 '13 at 21:49
0

As the official documentation shows, when accessing the MediaLibrary and looping through the resulting Picture list, there is no relative path, absolute path or filename for each image.

But there is access to date, name (description, if any) and a few other properties - so the solution is to generate your own filename when needed.

If we look at how the built-in Windows Phone Camera app and auto-upload to Skydrive feature works, my Skydrive camera roll has the following filenames:

  • WP_20130716_001.jpg
  • WP_20130716_002.jpg
  • WP_20130716_003.jpg

The pattern above is very easy to see an reproduce (and replace WP with the name of your app):

  • WP (underscore) ISO date format (underscore) image number

You may be tempted to use the name property (ie. description) to generate a desktop-like filename but name appears to be optional so it's blank most of the time, in my experience.

Neil Turner
  • 2,712
  • 2
  • 18
  • 37
  • The problem is transfer the image the computer to my phone, the name show in MessageBox is a title of photo, no original name. – crm27 Jul 16 '13 at 14:13
  • why do you need an original name? the filename is invisible to the user, the user picks photos based on a) how they look or b) how they're sorted (by date, by person, by place) – Neil Turner Jul 16 '13 at 15:03
  • I need original name for compare to name of the server cloud. – crm27 Jul 16 '13 at 16:15
  • Ah, your question doesn't say that. One method would be to get the CRC of the image (via the data stream) and compare that to images already uploaded (store the CRC as part of the image meta data) - using the filename would be a very unreliable way of comparing files anyway... http://stackoverflow.com/questions/800463/c-sharp-create-a-hash-for-a-byte-array-or-image – Neil Turner Jul 16 '13 at 17:58
  • The server only provides the checksum of file and Calculate the full checksum of images is very slow, because the media libray returns a pointer of stream and I converter stream to bytes to calculate the checksum. – crm27 Jul 17 '13 at 10:51
0

The MediaLibrary API does not provide access to the original file name.

Picture.Name seems to have the name given by the application that saved the picture. For example, for images downloaded from web by IE, it contains something like C:\Data\Users\DefApps\AppData\INTERNETEXPLORER\Temp\Saved Images\image.jpg. If image is saved by SkyDrive app, the name does not contain the .jpg extension at all.

sast
  • 478
  • 4
  • 8