-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathGdiPlusHelper.cpp
More file actions
57 lines (46 loc) · 1.77 KB
/
GdiPlusHelper.cpp
File metadata and controls
57 lines (46 loc) · 1.77 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
#include "stdafx.h"
#include "GdiPlusHelper.h"
#include "ImageHelper.h"
// ********************************************************************
// SaveBitmap
// ********************************************************************
Gdiplus::Status GdiPlusHelper::SaveBitmap(CStringW filename, int width, int height, colour* buffer, CStringW format)
{
return SaveAuto(filename, width, height, buffer, format);
}
// ********************************************************************
// SaveManual
// ********************************************************************
Gdiplus::Status GdiPlusHelper::SaveManual(CStringW filename, int width, int height, colour* buffer, CStringW format)
{
Gdiplus::Bitmap *bmap = new Gdiplus::Bitmap(width, height);
int c = 0;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
Gdiplus::Color newClr(buffer[c].alpha, buffer[c].blue, buffer[c].green, buffer[c].red);
bmap->SetPixel(j, i, newClr);
c++;
}
}
CLSID clsid;
int result = Utility::GetEncoderClsid(format, &clsid);
Gdiplus::Status status = bmap->Save(filename, &clsid);
delete bmap;
return status;
}
// ********************************************************************
// SaveBitmapData
// ********************************************************************
Gdiplus::Status GdiPlusHelper::SaveAuto(CStringW filename, int width, int height, colour* buffer, CStringW format)
{
int bitsPerPixel = 32;
int pad = ImageHelper::GetRowBytePad(width, bitsPerPixel);
int stride = width * bitsPerPixel / 8 + pad;
Gdiplus::Bitmap img(width, height, stride, PixelFormat32bppARGB, reinterpret_cast<BYTE*>(buffer));
CLSID clsid;
int result = Utility::GetEncoderClsid(format, &clsid);
Gdiplus::Status status = img.Save(filename, &clsid);
return status;
}