-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImgItemFactory.h
31 lines (29 loc) · 985 Bytes
/
ImgItemFactory.h
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
#pragma once
#include "ImgItem.h"
#include "ImgItemHelper.h"
#include "ImgJPEGItem.h"
#include "ImgGDIItem.h"
#include <string>
#include <memory>
class ImgItemFactory
{
public:
static std::shared_ptr<ImgItem> Create(const std::wstring& filepath, INT targetwidth, INT targetheight)
{
const auto imgformat = ImgItemHelper::GetImgFormatFromExtension(filepath);
switch (imgformat)
{
case ImgItem::Format::JPEG:
return std::make_shared<ImgJPEGItem>(filepath, targetwidth, targetheight);
break;
case ImgItem::Format::PNG:
return std::make_shared<ImgGDIItem>(filepath, targetwidth, targetheight);
break;
case ImgItem::Format::Other:
return std::make_shared<ImgGDIItem>(filepath, targetwidth, targetheight);
break;
default:
throw std::runtime_error("ImgItemFactory::Create(): the specified image format is not supported.");
}
}
};