File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments