Last change
on this file since 1176 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.1 KB
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Drawing;
|
---|
4 | using System.Drawing.Imaging;
|
---|
5 | using System.Runtime.InteropServices;
|
---|
6 |
|
---|
7 | namespace Oni.Imaging
|
---|
8 | {
|
---|
9 | internal static class SysReader
|
---|
10 | {
|
---|
11 | public static Surface Read(string filePath)
|
---|
12 | {
|
---|
13 | using (Bitmap bmp = new Bitmap(filePath, false))
|
---|
14 | {
|
---|
15 | SurfaceFormat surfaceFormat;
|
---|
16 | PixelFormat pixelFormat;
|
---|
17 |
|
---|
18 | if (bmp.RawFormat == ImageFormat.Jpeg || bmp.RawFormat == ImageFormat.Bmp)
|
---|
19 | {
|
---|
20 | surfaceFormat = SurfaceFormat.BGRX;
|
---|
21 | pixelFormat = PixelFormat.Format32bppRgb;
|
---|
22 | }
|
---|
23 | else
|
---|
24 | {
|
---|
25 | surfaceFormat = SurfaceFormat.BGRA;
|
---|
26 | pixelFormat = PixelFormat.Format32bppArgb;
|
---|
27 | }
|
---|
28 |
|
---|
29 | var surface = new Surface(bmp.Width, bmp.Height, surfaceFormat);
|
---|
30 | var rc = new Rectangle(0, 0, bmp.Width, bmp.Height);
|
---|
31 |
|
---|
32 | var data = bmp.LockBits(rc, ImageLockMode.ReadOnly, pixelFormat);
|
---|
33 | Marshal.Copy(data.Scan0, surface.Data, 0, surface.Data.Length);
|
---|
34 | bmp.UnlockBits(data);
|
---|
35 |
|
---|
36 | return surface;
|
---|
37 | }
|
---|
38 | }
|
---|
39 | }
|
---|
40 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.