【问题标题】:I want to add current datetime for a image which is taken from camera API using phonegap我想为使用 phonegap 从相机 API 拍摄的图像添加当前日期时间
【发布时间】:2013-08-20 16:28:00
【问题描述】:

我正在为 ios/andorid/windows 开发一个应用程序,它具有捕获图像并将其保存在我们的应用程序中的功能。 我的图像正在捕获并保存到文件夹并显示在 div 中。但我想为我拍摄的那张照片添加日期时间。假设是否在 2013 年 8 月 25 日拍摄照片。我想在右上角的图片中显示这个日期时间。

我们如何在 phonegap 中实现这一点。我听说过一些 canvas html5 功能,但我不知道如何在 canvas 标签中使用拍摄的图像。

function capturePhoto() {
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
      destinationType: destinationType.FILE_URI });
 }

function onFail(message) {
      alert('Failed because: ' + message);
}

function onPhotoDataSuccess(imageData) {
  console.log("Image Property-->");

  var smallImage = document.getElementById('smallImage');

  smallImage.style.display = 'block';

 // smallImage.src = "data:image/jpeg;base64," + imageData;
  smallImage.src = imageData;
}

<div data-role="page">

<div data-role="header" data-theme="b">
    <h1>DATE !T</h1>
</div><!-- /header -->

<div data-role="content">
    <button onclick="capturePhoto();">Capture Photo</button><br>
    <img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
</div><!-- /content -->

<div data-role="footer" data-position="fixed" data-theme="b">
    <h4>Footer</h4>
</div><!-- /footer -->

【问题讨论】:

    标签: html jquery-mobile cordova html5-canvas


    【解决方案1】:

    你可以通过这段代码使用 c# 来做到这一点

     FileStream fs = new FileStream(@"c:\myImage.jpg", FileMode.Open, FileAccess.Read);//or .jpg, etc...
            Image image = Image.FromStream(fs);
            fs.Close();
    
            Bitmap b = new Bitmap(image);
            Graphics graphics = Graphics.FromImage(b);
            var date = Convert.ToString(DateTime.Now);
            graphics.DrawString(date, this.Font, Brushes.Black, image.Width - (date.Length*5), 0);
    
            b.Save(@"c:\myImage.jpg", image.RawFormat);
    
            image.Dispose();
            b.Dispose();
    

    如果这对我没有帮助,请通知我搜索其他方法

    【讨论】:

    • 我正在 phonegap 中开发需要支持多平台的应用程序。不仅在 c# 中。
    猜你喜欢
    • 2012-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-15
    • 1970-01-01
    • 1970-01-01
    • 2014-01-18
    • 1970-01-01
    相关资源
    最近更新 更多