1

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

4

4 回答 4

2

你搜索

DateTime.Now.ToString(format);

有关格式,请参阅此链接:http: //msdn.microsoft.com/en-us/library/az4se3k1.aspx

于 2013-01-16T12:17:06.593 回答
0
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);
}

例如,当 DateTime 对象值为 16/1/2013 13:24 时,该方法将返回:“Image_1312013_1324”。您可以将其更改为您的偏好。希望这可以帮助!

于 2013-01-16T12:25:42.593 回答
0

如果您希望您的图像名称是唯一的,请获取以下项目:

  1. 指导
  2. 日期时间.Now

连接这两个并散列整体值。最后将哈希值设置为您的图像名称。这是安全性强的。

于 2014-02-03T06:15:55.940 回答
0

您可以使用Guid.NewGuid()来生成您的图像名称。

于 2013-06-06T14:49:05.783 回答