-
Notifications
You must be signed in to change notification settings - Fork 12
/
wxPNGResource.cpp
65 lines (51 loc) · 1.63 KB
/
wxPNGResource.cpp
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
61
62
63
64
65
#include <wx/mstream.h>
#include "wxPNGResource.h"
wxImage wxPNGResource::GetImage(const wxString& t_name, int width, int height)
{
wxImage r_imagePtr;
char* a_data = 0;
DWORD a_dataSize = 0;
if(LoadDataFromResource(a_data, a_dataSize, t_name))
{
r_imagePtr = GetImageMemory(a_data, a_dataSize);
// only scale if width and height is set and if the resource image is not the same size!
if (width != 0 && height != 0 && (r_imagePtr.GetWidth() != width || r_imagePtr.GetHeight() != height))
r_imagePtr = r_imagePtr.Scale(width, height);
}
return r_imagePtr;
}
wxImage wxPNGResource::GetImage(const wxString& t_name, wxPoint size)
{
return GetImage(t_name, size.x, size.y);
}
wxBitmap wxPNGResource::GetBitmap(const wxString& t_name, int width, int height)
{
return wxBitmap(GetImage(t_name, width, height));
}
wxBitmap wxPNGResource::GetBitmap(const wxString& t_name, wxPoint size)
{
return GetBitmap(t_name, size.x, size.y);
}
bool wxPNGResource::LoadDataFromResource(char*& t_data, DWORD& t_dataSize, const wxString& t_name)
{
bool r_result = false;
HGLOBAL a_resHandle = 0;
HRSRC a_resource;
a_resource = FindResource(0, t_name.wchar_str(), RT_RCDATA);
if(0 != a_resource)
{
a_resHandle = LoadResource(NULL, a_resource);
if (0 != a_resHandle)
{
t_data = (char*)LockResource(a_resHandle);
t_dataSize = SizeofResource(NULL, a_resource);
r_result = true;
}
}
return r_result;
}
wxImage wxPNGResource::GetImageMemory(const char* t_data, const DWORD t_size)
{
wxMemoryInputStream a_is(t_data, t_size);
return wxImage(a_is, wxBITMAP_TYPE_PNG, -1);
}