Last change
on this file since 1114 was 1114, checked in by iritscen, 5 years ago |
Adding OniSplit source code (v0.9.99.0). Many thanks to Neo for all his work over the years.
|
File size:
1.5 KB
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Drawing;
|
---|
3 | using System.Drawing.Imaging;
|
---|
4 | using System.IO;
|
---|
5 | using System.Runtime.InteropServices;
|
---|
6 |
|
---|
7 | namespace Oni.Imaging
|
---|
8 | {
|
---|
9 | internal class SysWriter
|
---|
10 | {
|
---|
11 | public static void Write(Surface surface, string filePath)
|
---|
12 | {
|
---|
13 | Directory.CreateDirectory(Path.GetDirectoryName(filePath));
|
---|
14 |
|
---|
15 | surface = surface.Convert(SurfaceFormat.BGRA);
|
---|
16 |
|
---|
17 | using (var bitmap = new Bitmap(surface.Width, surface.Height, PixelFormat.Format32bppArgb))
|
---|
18 | {
|
---|
19 | var rc = new Rectangle(0, 0, surface.Width, surface.Height);
|
---|
20 |
|
---|
21 | var pixels = bitmap.LockBits(rc, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
|
---|
22 | Marshal.Copy(surface.Data, 0, pixels.Scan0, surface.Data.Length);
|
---|
23 | bitmap.UnlockBits(pixels);
|
---|
24 |
|
---|
25 | switch (Path.GetExtension(filePath))
|
---|
26 | {
|
---|
27 | case ".png":
|
---|
28 | bitmap.Save(filePath, ImageFormat.Png);
|
---|
29 | break;
|
---|
30 | case ".jpg":
|
---|
31 | bitmap.Save(filePath, ImageFormat.Jpeg);
|
---|
32 | break;
|
---|
33 | case ".bmp":
|
---|
34 | bitmap.Save(filePath, ImageFormat.Bmp);
|
---|
35 | break;
|
---|
36 | case ".tif":
|
---|
37 | bitmap.Save(filePath, ImageFormat.Tiff);
|
---|
38 | break;
|
---|
39 | }
|
---|
40 | }
|
---|
41 | }
|
---|
42 | }
|
---|
43 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.