-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPictureBitmap.cs
More file actions
44 lines (40 loc) · 1.23 KB
/
PictureBitmap.cs
File metadata and controls
44 lines (40 loc) · 1.23 KB
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
using System;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
namespace raw_streams.cs
{
public class PictureBitmap : IDisposable
{
public void SetPixels(int width, int height, byte[] pixels)
{
if (width != width_ || height != height_ || bitmap_ == null)
{
width_ = width;
height_ = height;
bitmap_ = new Bitmap(width_, height_, PixelFormat.Format32bppRgb);
}
if (pixels != null && bitmap_ != null)
{
BitmapData bitmap_data = bitmap_.LockBits(new Rectangle(0, 0, width_, height_), ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb);
Marshal.Copy(pixels, 0, bitmap_data.Scan0, width_ * height_ * 4);
bitmap_.UnlockBits(bitmap_data);
}
}
public Bitmap GetBitmap()
{
return bitmap_;
}
public void Dispose()
{
if (bitmap_ != null)
{
bitmap_.Dispose();
bitmap_ = null;
}
}
private int width_ = 0;
private int height_ = 0;
private Bitmap bitmap_ = null;
}
}