Raj
Raj

Reputation: 204

Image name generation

I am working on a window phone application where I am capturing image from the primary camera and want to generate the image name based on different parameter like date ,time etc. For that I am defining a method:

private string fnGenerate()
        {
            string fileName = "";

            // Logic to be put later.
            fileName = "testImage5.jpg";
            return fileName;
        }

image will come from this:

public void fnSaveImage(Stream imgStream, out string imageName)
        {
            imageName = fnGenerateFileName();

            BitmapImage appCapImg = new BitmapImage();
            appCapImg.SetSource(imgStream);
            IsolatedStorageFile appImgStore = IsolatedStorageFile.GetUserStoreForApplication();
            IsolatedStorageFileStream appNewStream = appImgStore.CreateFile(imageName);

            WriteableBitmap appWrtBmp = new WriteableBitmap(appCapImg);
            appWrtBmp.SaveJpeg(appNewStream, appWrtBmp.PixelWidth, appWrtBmp.PixelHeight, 0, 10);
            appNewStream.Close();       

        }

But as of now I have hard coded the image name, but I want to generate the image name on the above parameter. Can any one help how to generate the name for image

Upvotes: 1

Views: 152

Answers (4)

Shafiq Abbas
Shafiq Abbas

Reputation: 492

If you want your Image name to be Unique, then get the following items :

  1. Guid
  2. DateTime.Now

Concatenate these two and hash the overall value. An finally set the hash value as your image name. This is Security-Strong.

Upvotes: 0

Pavel Saniuk
Pavel Saniuk

Reputation: 788

You can use Guid.NewGuid() to generate your image name.

Upvotes: 0

Abbas
Abbas

Reputation: 14432

private string GenerateImageName()
{
    var fileName = "Image_{0}{1}{2}_{3}{4}";
    var date = DateTime.Now;

    return String.Format(filename, date.Day, date.Month, day.Year, day.Hour, day.Minute);
}

When the DateTime object value is for example 16/1/2013 13:24, the method wil return: "Image_1312013_1324". You can change this to your preferences. Hope this helps!

Upvotes: 0

looper
looper

Reputation: 1989

You search for

DateTime.Now.ToString(format);

See this link for format: http://msdn.microsoft.com/en-us/library/az4se3k1.aspx

Upvotes: 2

Related Questions