-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImgBitmap.h
More file actions
60 lines (53 loc) · 1.37 KB
/
ImgBitmap.h
File metadata and controls
60 lines (53 loc) · 1.37 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once
#include <Windows.h>
#include <algorithm>
class ImgBitmap
{
public:
ImgBitmap(const PBITMAPINFO pbitmapinfo, const PBYTE buffer, INT buffersize)
{
Initialize(pbitmapinfo, buffer, buffersize);
}
~ImgBitmap()
{
DeleteBitmap();
}
ImgBitmap(const ImgBitmap&) = delete;
ImgBitmap(ImgBitmap&& other)
{
*this = std::move(other);
}
ImgBitmap& operator=(ImgBitmap&& other)
{
if (this != &other)
{
DeleteBitmap();
bitmap_ = other.bitmap_;
other.bitmap_ = nullptr;
}
return *this;
}
HBITMAP bitmap() const { return bitmap_; }
private:
HBITMAP bitmap_{ nullptr };
private:
void Initialize(const PBITMAPINFO pbitmapinfo, const PBYTE buffer, INT buffersize);
void DeleteBitmap();
};
inline void ImgBitmap::DeleteBitmap()
{
if (bitmap_ != nullptr)
{
DeleteObject(bitmap_);
bitmap_ = nullptr;
}
}
inline void ImgBitmap::Initialize(const PBITMAPINFO pbitmapinfo, const PBYTE buffer, INT buffersize)
{
const auto dc = GetDC(NULL);
const auto usage = pbitmapinfo->bmiHeader.biClrUsed > 0 ? DIB_PAL_COLORS : DIB_RGB_COLORS;
PBYTE bits;
bitmap_ = CreateDIBSection(dc, pbitmapinfo, usage, reinterpret_cast<void**>(&bits), NULL, 0);
ReleaseDC(NULL, dc);
CopyMemory(bits, buffer, buffersize);
}