File: getbytes.cs

package info (click to toggle)
mapserver 5.0.3-3%2Blenny7
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 13,556 kB
  • ctags: 12,645
  • sloc: ansic: 168,024; cs: 8,534; python: 4,618; sh: 4,213; cpp: 4,059; perl: 2,781; makefile: 787; lex: 564; java: 415; yacc: 334; tcl: 158; ruby: 53
file content (60 lines) | stat: -rw-r--r-- 1,466 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Drawing;
using System.IO;
using OSGeo.MapServer;
	
/**
 * <p>Title: Mapscript getBytes example.</p>
 * <p>Description: A C# based mapscript example to show the usage of imageObj.getBytes.</p>
 * @author Tamas Szekeres	szekerest@gmail.com
 * @version 1.0  
*/

/// <summary>
/// A C# based mapscript example to show the usage of imageObj.getBytes.
/// </summary>
class GetBytes
{
    public static void usage() 
    { 
	    Console.WriteLine("usage: getbytes {mapfile} {outfile}");
	    System.Environment.Exit(-1);
    }
    		  
    public static void Main(string[] args)
    {
        if (args.Length < 2) usage();
        
        try 
        {
			mapObj map = new mapObj(args[0]);

			using(imageObj image = map.draw())
			{
				// solution 1
				Console.WriteLine ("Drawing map: '" + map.name + "' using imageObj.getBytes");
				
				byte[] img = image.getBytes();
				using (MemoryStream ms = new MemoryStream(img))
				{
					Image mapimage = Image.FromStream(ms);
					mapimage.Save(args[1]);
				}
				
				// solution 2
				Console.WriteLine ("Drawing map: '" + map.name + "' using imageObj.write");

				using (FileStream fs = File.Open("_" + args[1], FileMode.OpenOrCreate, FileAccess.ReadWrite))
				{
					image.write(fs);
				}
			}
        } 
        catch (Exception ex) 
        {
            Console.WriteLine( "GetBytes: ", ex.Message );
        }
    }

}