📄 wincebitmap.cpp
字号:
/*
This file is part of SWAIN (http://sourceforge.net/projects/swain).
Copyright (C) 2006 Daniel Lindstr鰉 and Daniel Nilsson
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "StdAfx.h"
#include "WinCEBitmap.h"
#include "wince_drawing.h" // needed for g_hWndDrawingWindow
#include <imaging.h>
#include <initguid.h>
#include <imgguids.h>
WinCEBitmap::WinCEBitmap(WCHAR *filename, bool rotate) {
IImagingFactory *pImgFactory = NULL;
IImage *pImage = NULL, *pImageRot = NULL;
ImageInfo imageInfo;
RECT rc;
IBitmapImage *bm = NULL, *bmrot = NULL;
IBasicBitmapOps *bbo = NULL;
bool success = false;
CoInitializeEx(NULL, COINIT_MULTITHREADED);
// Create the imaging factory.
if (FAILED(CoCreateInstance (CLSID_ImagingFactory,
NULL,
CLSCTX_INPROC_SERVER,
IID_IImagingFactory,
(void **)&pImgFactory))) {
goto create_instance_failed;
}
// Load the image from the JPG file.
if (FAILED(pImgFactory->CreateImageFromFile(filename, &pImage))) {
goto create_image_failed;
}
if (FAILED(pImgFactory->CreateBitmapFromImage(pImage, 0, 0, 0, InterpolationHintDefault, &bm))) {
goto create_bitmap_failed;
}
if (FAILED(bm->QueryInterface(IID_IBasicBitmapOps, (void **)&bbo))) {
goto query_interface1_failed;
}
if (FAILED(bbo->Rotate((rotate ? 90.0f : 0.0f), InterpolationHintDefault, &bmrot))) {
goto rotate_failed;
}
if (FAILED(bmrot->QueryInterface(IID_IImage, (void **)&pImageRot))) {
goto query_interface2_failed;
}
// Find the size of the image
if (FAILED(pImageRot->GetImageInfo(&imageInfo))) {
goto image_info_failed;
}
rc.left = rc.top = 0;
rc.right = width = imageInfo.Width;
rc.bottom = height = imageInfo.Height;
// Create a offscreen bitmap and device context
HDC winhdc = GetDC(g_hWndDrawingWindow);
hdc = CreateCompatibleDC(winhdc);
bitmap = CreateCompatibleBitmap(winhdc, imageInfo.Width, imageInfo.Height);
SelectObject(hdc, bitmap);
// Draw the image.
pImageRot->Draw(hdc, &rc, NULL);
success = true;
image_info_failed:
pImageRot->Release();
query_interface2_failed:
bmrot->Release();
rotate_failed:
bbo->Release();
query_interface1_failed:
bm->Release();
create_bitmap_failed:
pImage->Release();
create_image_failed:
pImgFactory->Release();
create_instance_failed:
CoUninitialize();
if (!success) {
throw "Image loading failed!";
}
}
WinCEBitmap::~WinCEBitmap(void) {
DeleteDC(hdc);
DeleteObject(bitmap);
}
HDC WinCEBitmap::getHDC() {
return hdc;
}
int WinCEBitmap::getWidth() {
return width;
}
int WinCEBitmap::getHeight() {
return height;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -