2018-09-06 23:26:32 +08:00
|
|
|
|
#include "..\e2dobject.h"
|
2018-09-05 13:33:39 +08:00
|
|
|
|
#include "..\e2dmodule.h"
|
|
|
|
|
|
#include "..\e2dtool.h"
|
2017-10-18 22:13:20 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
std::map<size_t, ID2D1Bitmap*> e2d::Image::bitmap_cache_;
|
2017-10-18 22:13:20 +08:00
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
e2d::Image::Image()
|
2018-09-04 22:42:34 +08:00
|
|
|
|
: bitmap_(nullptr)
|
|
|
|
|
|
, crop_rect_()
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-08 02:41:44 +08:00
|
|
|
|
e2d::Image::Image(const Resource& res)
|
2018-09-04 22:42:34 +08:00
|
|
|
|
: bitmap_(nullptr)
|
|
|
|
|
|
, crop_rect_()
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->Open(res);
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
e2d::Image::Image(const Resource& res, const Rect& crop_rect)
|
|
|
|
|
|
: bitmap_(nullptr)
|
|
|
|
|
|
, crop_rect_()
|
2018-04-27 00:16:14 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->Open(res);
|
|
|
|
|
|
this->Crop(crop_rect);
|
2018-04-27 00:16:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
e2d::Image::Image(const String & file_name)
|
|
|
|
|
|
: bitmap_(nullptr)
|
|
|
|
|
|
, crop_rect_()
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->Open(file_name);
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
e2d::Image::Image(const String & file_name, const Rect & crop_rect)
|
|
|
|
|
|
: bitmap_(nullptr)
|
|
|
|
|
|
, crop_rect_()
|
2018-04-27 00:16:14 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->Open(file_name);
|
|
|
|
|
|
this->Crop(crop_rect);
|
2018-04-27 00:16:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
e2d::Image::~Image()
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-07 00:28:54 +08:00
|
|
|
|
SafeRelease(bitmap_);
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
bool e2d::Image::Open(const Resource& res)
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (!Image::Preload(res))
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-05-24 12:24:39 +08:00
|
|
|
|
WARN("Load Image from file failed!");
|
2018-04-27 00:16:14 +08:00
|
|
|
|
return false;
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->SetBitmap(bitmap_cache_.at(res.name));
|
2018-04-27 00:16:14 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
bool e2d::Image::Open(const String & file_name)
|
2018-04-27 00:16:14 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
WARN_IF(file_name.IsEmpty(), "Image Open failed! Invalid file name.");
|
2018-08-19 20:40:44 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (file_name.IsEmpty())
|
2018-08-19 20:40:44 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (!Image::Preload(file_name))
|
2018-08-19 20:40:44 +08:00
|
|
|
|
{
|
|
|
|
|
|
WARN("Load Image from file failed!");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->SetBitmap(bitmap_cache_.at(file_name.GetHash()));
|
2018-08-19 20:40:44 +08:00
|
|
|
|
return true;
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Image::Crop(const Rect& crop_rect)
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (bitmap_)
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
crop_rect_.origin.x = std::min(std::max(crop_rect.origin.x, 0.f), this->GetSourceWidth());
|
|
|
|
|
|
crop_rect_.origin.y = std::min(std::max(crop_rect.origin.y, 0.f), this->GetSourceHeight());
|
|
|
|
|
|
crop_rect_.size.width = std::min(std::max(crop_rect.size.width, 0.f), this->GetSourceWidth() - crop_rect.origin.x);
|
|
|
|
|
|
crop_rect_.size.height = std::min(std::max(crop_rect.size.height, 0.f), this->GetSourceHeight() - crop_rect.origin.y);
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|
2018-02-03 22:04:43 +08:00
|
|
|
|
}
|
2017-10-18 22:13:20 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
float e2d::Image::GetWidth() const
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return crop_rect_.size.width;
|
2018-02-03 22:04:43 +08:00
|
|
|
|
}
|
2017-10-18 22:13:20 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
float e2d::Image::GetHeight() const
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return crop_rect_.size.height;
|
2018-02-03 22:04:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
e2d::Size e2d::Image::GetSize() const
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return crop_rect_.size;
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
float e2d::Image::GetSourceWidth() const
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (bitmap_)
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return bitmap_->GetSize().width;
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
float e2d::Image::GetSourceHeight() const
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (bitmap_)
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return bitmap_->GetSize().height;
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
e2d::Size e2d::Image::GetSourceSize() const
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (bitmap_)
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return Size(GetSourceWidth(), GetSourceHeight());
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-02-07 16:37:12 +08:00
|
|
|
|
return Size();
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
float e2d::Image::GetCropX() const
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return crop_rect_.origin.x;
|
2018-02-03 22:04:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
float e2d::Image::GetCropY() const
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return crop_rect_.origin.y;
|
2018-02-03 22:04:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
e2d::Point e2d::Image::GetCropPos() const
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return crop_rect_.origin;
|
2018-02-03 22:04:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
bool e2d::Image::Preload(const Resource& res)
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (bitmap_cache_.find(res.name) != bitmap_cache_.end())
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
IWICImagingFactory *pImagingFactory = Renderer::GetImagingFactory();
|
|
|
|
|
|
ID2D1HwndRenderTarget* pRenderTarget = Renderer::GetInstance()->GetRenderTarget();
|
2017-10-18 22:13:20 +08:00
|
|
|
|
IWICBitmapDecoder *pDecoder = nullptr;
|
|
|
|
|
|
IWICBitmapFrameDecode *pSource = nullptr;
|
|
|
|
|
|
IWICStream *pStream = nullptr;
|
|
|
|
|
|
IWICFormatConverter *pConverter = nullptr;
|
|
|
|
|
|
ID2D1Bitmap *pBitmap = nullptr;
|
2018-08-19 20:40:44 +08:00
|
|
|
|
HRSRC imageResHandle = nullptr;
|
|
|
|
|
|
HGLOBAL imageResDataHandle = nullptr;
|
|
|
|
|
|
void *pImageFile = nullptr;
|
|
|
|
|
|
DWORD imageFileSize = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>λ<EFBFBD><CEBB>Դ
|
|
|
|
|
|
imageResHandle = ::FindResourceW(
|
|
|
|
|
|
HINST_THISCOMPONENT,
|
2018-09-04 22:42:34 +08:00
|
|
|
|
MAKEINTRESOURCE(res.name),
|
|
|
|
|
|
(LPCWSTR)res.type
|
2018-08-19 20:40:44 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT hr = imageResHandle ? S_OK : E_FAIL;
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
|
|
|
|
|
|
imageResDataHandle = ::LoadResource(HINST_THISCOMPONENT, imageResHandle);
|
|
|
|
|
|
|
|
|
|
|
|
hr = imageResDataHandle ? S_OK : E_FAIL;
|
|
|
|
|
|
}
|
2017-10-18 22:13:20 +08:00
|
|
|
|
|
2018-08-19 20:40:44 +08:00
|
|
|
|
if (SUCCEEDED(hr))
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-08-19 20:40:44 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD>ļ<EFBFBD>ָ<EFBFBD>룬<EFBFBD><EBA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
|
|
|
|
|
|
pImageFile = ::LockResource(imageResDataHandle);
|
2017-10-18 22:13:20 +08:00
|
|
|
|
|
2018-08-19 20:40:44 +08:00
|
|
|
|
hr = pImageFile ? S_OK : E_FAIL;
|
2018-04-27 00:16:14 +08:00
|
|
|
|
}
|
2018-08-19 20:40:44 +08:00
|
|
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
|
|
|
|
|
imageFileSize = ::SizeofResource(HINST_THISCOMPONENT, imageResHandle);
|
|
|
|
|
|
|
|
|
|
|
|
hr = imageFileSize ? S_OK : E_FAIL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD> WIC <20><>
|
|
|
|
|
|
hr = pImagingFactory->CreateStream(&pStream);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
|
|
|
|
|
hr = pStream->InitializeFromMemory(
|
|
|
|
|
|
reinterpret_cast<BYTE*>(pImageFile),
|
|
|
|
|
|
imageFileSize
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
2018-04-27 00:16:14 +08:00
|
|
|
|
{
|
2018-08-19 20:40:44 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
hr = pImagingFactory->CreateDecoderFromStream(
|
|
|
|
|
|
pStream,
|
2018-05-17 15:22:14 +08:00
|
|
|
|
nullptr,
|
2018-04-27 00:16:14 +08:00
|
|
|
|
WICDecodeMetadataCacheOnLoad,
|
|
|
|
|
|
&pDecoder
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
hr = pDecoder->GetFrame(0, &pSource);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ͼƬ<CDBC><C6AC>ʽת<CABD><D7AA><EFBFBD><EFBFBD>
|
2018-07-08 02:41:44 +08:00
|
|
|
|
hr = pImagingFactory->CreateFormatConverter(&pConverter);
|
2018-04-27 00:16:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
|
|
{
|
|
|
|
|
|
// ͼƬ<CDBC><C6AC>ʽת<CABD><D7AA><EFBFBD><EFBFBD> 32bppPBGRA
|
|
|
|
|
|
hr = pConverter->Initialize(
|
|
|
|
|
|
pSource,
|
|
|
|
|
|
GUID_WICPixelFormat32bppPBGRA,
|
|
|
|
|
|
WICBitmapDitherTypeNone,
|
2018-05-17 15:22:14 +08:00
|
|
|
|
nullptr,
|
2018-04-27 00:16:14 +08:00
|
|
|
|
0.f,
|
|
|
|
|
|
WICBitmapPaletteTypeMedianCut
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><> WIC λͼ<CEBB><CDBC><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> Direct2D λͼ
|
2018-08-19 20:40:44 +08:00
|
|
|
|
hr = pRenderTarget->CreateBitmapFromWicBitmap(
|
|
|
|
|
|
pConverter,
|
|
|
|
|
|
nullptr,
|
|
|
|
|
|
&pBitmap
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
bitmap_cache_.insert(std::make_pair(res.name, pBitmap));
|
2018-08-19 20:40:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// <20>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
|
|
|
|
|
|
SafeRelease(pDecoder);
|
|
|
|
|
|
SafeRelease(pSource);
|
|
|
|
|
|
SafeRelease(pStream);
|
|
|
|
|
|
SafeRelease(pConverter);
|
|
|
|
|
|
|
|
|
|
|
|
return SUCCEEDED(hr);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
bool e2d::Image::Preload(const String & file_name)
|
2018-08-19 20:40:44 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
String actualFilePath = File(file_name).GetPath();
|
|
|
|
|
|
if (actualFilePath.IsEmpty())
|
2018-08-19 20:40:44 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
size_t hash = actualFilePath.GetHash();
|
|
|
|
|
|
if (bitmap_cache_.find(hash) != bitmap_cache_.end())
|
2018-08-19 20:40:44 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
IWICImagingFactory *pImagingFactory = Renderer::GetImagingFactory();
|
|
|
|
|
|
ID2D1HwndRenderTarget* pRenderTarget = Renderer::GetInstance()->GetRenderTarget();
|
2018-08-19 20:40:44 +08:00
|
|
|
|
IWICBitmapDecoder *pDecoder = nullptr;
|
|
|
|
|
|
IWICBitmapFrameDecode *pSource = nullptr;
|
|
|
|
|
|
IWICStream *pStream = nullptr;
|
|
|
|
|
|
IWICFormatConverter *pConverter = nullptr;
|
|
|
|
|
|
ID2D1Bitmap *pBitmap = nullptr;
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
HRESULT hr = pImagingFactory->CreateDecoderFromFilename(
|
|
|
|
|
|
(LPCWSTR)actualFilePath,
|
|
|
|
|
|
nullptr,
|
|
|
|
|
|
GENERIC_READ,
|
|
|
|
|
|
WICDecodeMetadataCacheOnLoad,
|
|
|
|
|
|
&pDecoder
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
hr = pDecoder->GetFrame(0, &pSource);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ͼƬ<CDBC><C6AC>ʽת<CABD><D7AA><EFBFBD><EFBFBD>
|
|
|
|
|
|
hr = pImagingFactory->CreateFormatConverter(&pConverter);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
|
|
{
|
|
|
|
|
|
// ͼƬ<CDBC><C6AC>ʽת<CABD><D7AA><EFBFBD><EFBFBD> 32bppPBGRA
|
|
|
|
|
|
hr = pConverter->Initialize(
|
|
|
|
|
|
pSource,
|
|
|
|
|
|
GUID_WICPixelFormat32bppPBGRA,
|
|
|
|
|
|
WICBitmapDitherTypeNone,
|
|
|
|
|
|
nullptr,
|
|
|
|
|
|
0.f,
|
|
|
|
|
|
WICBitmapPaletteTypeMedianCut
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><> WIC λͼ<CEBB><CDBC><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> Direct2D λͼ
|
|
|
|
|
|
hr = pRenderTarget->CreateBitmapFromWicBitmap(
|
2018-04-27 00:16:14 +08:00
|
|
|
|
pConverter,
|
2018-05-17 15:22:14 +08:00
|
|
|
|
nullptr,
|
2018-04-27 00:16:14 +08:00
|
|
|
|
&pBitmap
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
bitmap_cache_.insert(std::make_pair(hash, pBitmap));
|
2018-04-27 00:16:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// <20>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
|
2018-05-22 12:24:43 +08:00
|
|
|
|
SafeRelease(pDecoder);
|
|
|
|
|
|
SafeRelease(pSource);
|
|
|
|
|
|
SafeRelease(pStream);
|
|
|
|
|
|
SafeRelease(pConverter);
|
2018-04-27 00:16:14 +08:00
|
|
|
|
|
|
|
|
|
|
return SUCCEEDED(hr);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Image::ClearCache()
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (bitmap_cache_.empty())
|
2018-07-21 22:57:21 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
for (const auto& bitmap : bitmap_cache_)
|
2018-04-27 00:16:14 +08:00
|
|
|
|
{
|
2018-07-21 22:57:21 +08:00
|
|
|
|
bitmap.second->Release();
|
2018-04-27 00:16:14 +08:00
|
|
|
|
}
|
2018-09-04 22:42:34 +08:00
|
|
|
|
bitmap_cache_.clear();
|
2018-05-14 00:36:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Image::SetBitmap(ID2D1Bitmap * bitmap)
|
2018-05-14 00:36:01 +08:00
|
|
|
|
{
|
2018-09-07 00:28:54 +08:00
|
|
|
|
if (bitmap_ == bitmap)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (bitmap_)
|
|
|
|
|
|
{
|
|
|
|
|
|
bitmap_->Release();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-14 00:36:01 +08:00
|
|
|
|
if (bitmap)
|
|
|
|
|
|
{
|
2018-09-07 00:28:54 +08:00
|
|
|
|
bitmap->AddRef();
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
bitmap_ = bitmap;
|
|
|
|
|
|
crop_rect_.origin.x = crop_rect_.origin.y = 0;
|
|
|
|
|
|
crop_rect_.size.width = bitmap_->GetSize().width;
|
|
|
|
|
|
crop_rect_.size.height = bitmap_->GetSize().height;
|
2018-05-14 00:36:01 +08:00
|
|
|
|
}
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
ID2D1Bitmap * e2d::Image::GetBitmap()
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return bitmap_;
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|