Skip to content

Commit df9b11b

Browse files
committed
Merge pull request #35 from Crulex/wp8
Ported the plugin to WP8
2 parents c9354de + 4f65e9a commit df9b11b

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

plugin.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,16 @@
5151
target-dir="src/org/devgeeks/Canvas2ImagePlugin" />
5252

5353
</platform>
54+
55+
<!-- wp8 -->
56+
<platform name="wp8">
57+
<config-file target="config.xml" parent="/*">
58+
<feature name="Canvas2ImagePlugin">
59+
<param name="wp-package" value="Canvas2ImagePlugin"/>
60+
<param name="onload" value="true" />
61+
</feature>
62+
</config-file>
63+
64+
<source-file src="src/wp8/Canvas2ImagePlugin.cs" />
65+
</platform>
5466
</plugin>

src/wp8/Canvas2ImagePlugin.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Microsoft.Xna.Framework.Media;
2+
using System;
3+
using System.IO;
4+
using System.Text;
5+
using WPCordovaClassLib.Cordova;
6+
using WPCordovaClassLib.Cordova.Commands;
7+
using WPCordovaClassLib.Cordova.JSON;
8+
9+
public class Canvas2ImagePlugin : BaseCommand
10+
{
11+
public Canvas2ImagePlugin()
12+
{
13+
}
14+
15+
public void saveImageDataToLibrary(string jsonArgs)
16+
{
17+
try
18+
{
19+
var options = JsonHelper.Deserialize<string[]>(jsonArgs);
20+
21+
string imageData = options[0];
22+
byte[] imageBytes = Convert.FromBase64String(imageData);
23+
24+
using (var imageStream = new MemoryStream(imageBytes))
25+
{
26+
imageStream.Seek(0, SeekOrigin.Begin);
27+
28+
string fileName = String.Format("c2i_{0:yyyyMMdd_HHmmss}", DateTime.Now);
29+
var library = new MediaLibrary();
30+
var picture = library.SavePicture(fileName, imageStream);
31+
32+
if (picture.Name.Contains(fileName))
33+
{
34+
DispatchCommandResult(new PluginResult(PluginResult.Status.OK,
35+
"Image saved: " + picture.Name));
36+
}
37+
else
38+
{
39+
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR,
40+
"Failed to save image: " + picture.Name));
41+
}
42+
}
43+
}
44+
catch (Exception ex)
45+
{
46+
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, ex.Message));
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)