本文整理汇总了C++中gdiplus::Image类的典型用法代码示例。如果您正苦于以下问题:C++ Image类的具体用法?C++ Image怎么用?C++ Image使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Image类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
// description: load image from file using gdi+
NaImage * NaImage::Load(const wchar_t * filename)
{
NaImage *pImage = new NaImage;
HDC hDC = NaScreenModule::GetDesktopDC();
pImage->m_hMemoryDC = ::CreateCompatibleDC(hDC);
// initialize gdi+
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
// load image
Gdiplus::Image* pGdiImage = new Gdiplus::Image(filename);
// converting to bitmap
Gdiplus::Bitmap* pGdiBitmap = static_cast<Gdiplus::Bitmap*>(pGdiImage);
pGdiBitmap->GetHBITMAP(Gdiplus::Color(0, 0, 0), &pImage->m_hBitmap);
pImage->m_rc.left = 0;
pImage->m_rc.top = 0;
pImage->m_rc.right = pGdiImage->GetWidth();
pImage->m_rc.bottom = pGdiImage->GetHeight();
// shutdown gdi+
delete pGdiImage;
Gdiplus::GdiplusShutdown(gdiplusToken);
return pImage;
}
示例2: ChangeSubPic
BOOL COBSButton::ChangeSubPic(STATE index, LPCTSTR lpszImage)
{
if (m_hWnd == NULL || lpszImage == NULL)
{
return FALSE;
}
Gdiplus::Image* pImage = Gdiplus::Image::FromFile(lpszImage);
if ((pImage == NULL) || (pImage->GetLastStatus() != Gdiplus::Ok))
{
if (pImage)
{
delete pImage;
pImage = NULL;
}
return FALSE;
}
int nPos = pImage->GetWidth()*index;//¼ÆËã4ÕÅͼƬÐèÒª¶àÉÙÏñËØ
Gdiplus::Graphics graph(m_hdcMemory);
graph.SetSmoothingMode(Gdiplus::SmoothingModeNone);
graph.DrawImage(pImage, nPos, 0, pImage->GetWidth(), pImage->GetHeight());
return TRUE;
}
示例3: bkimg
static Gdiplus::Image* bkimg(int rcid) {
HRSRC hrsc = ::FindResource(hInst, MAKEINTRESOURCE(rcid), TEXT("PNG"));
DWORD size = ::SizeofResource(hInst, hrsc);
LPVOID hg = ::LoadResource(hInst, hrsc);
HGLOBAL mem = ::GlobalAlloc(GMEM_MOVEABLE, size);
Gdiplus::Image* img = 0;
if (mem) {
LPVOID pmem = ::GlobalLock(mem);
if (pmem) {
::CopyMemory(pmem, hg, size);
LPSTREAM is;
if (::CreateStreamOnHGlobal(pmem, FALSE, &is) == S_OK) {
Gdiplus::Image* m = new Gdiplus::Image(is);
is->Release();
if (m->GetLastStatus() != Gdiplus::Ok) {
delete m;
return img;
}
img = m;
}
::GlobalUnlock(mem);
}
::GlobalFree(mem);
}
return img;
}
示例4: BlendSelSign
/**
Blend 'A''B''C''D' sign onto the image.
*/
static void BlendSelSign( Gdiplus::Graphics *g, const Gdiplus::RectF &render_rect, int sel )
{
CFileListManager &file_manager = GetInst( CFileListManager );
Gdiplus::Image *img = CreateImgFromBuffer( file_manager.GetSelSign( sel ) );
Gdiplus::PointF render_pos = GetRandPosInULRect( img->GetWidth(), img->GetHeight(), render_rect );
img_alpha( g, img, render_pos.X, render_pos.Y, 255 );
delete img;
}
示例5: Save
bool Image::Save(const wchar_t* path, const wchar_t* mime) {
Gdiplus::Image* gdiBitmap = reinterpret_cast<Gdiplus::Image*>(_private);
CLSID formatClsid;
if(GetEncoderClsid(mime, &formatClsid)>0) {
if(gdiBitmap->Save(path, &formatClsid, NULL)==Gdiplus::Ok) {
return true;
}
}
return false;
}
示例6: GetImageSize
cgSize cgGdiplusRender::GetImageSize( cgID image )
{
cgSize size;
Gdiplus::Image* pkImage = m_kImageStorage.Find(image);
if (pkImage)
{
size.w = pkImage->GetWidth();
size.h = pkImage->GetHeight();
}
return size;
}
示例7: SHLoadImageFile
HBITMAP SHLoadImageFile( LPCTSTR pszFileName )
{
if ( !pszFileName || !*pszFileName )
return 0;
String strFileName = convertToStringA(pszFileName);
if ( String_endsWith(strFileName, ".bmp") )
{
return (HBITMAP)::LoadImage(NULL, pszFileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
}
if ( !String_endsWith(strFileName, ".png") )
return 0;
static bool s_GDIInit = false;
if ( !s_GDIInit)
{
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
s_GDIInit = true;
}
Gdiplus::Image* image = new Gdiplus::Image(convertToStringW(strFileName).c_str());
SizeF sizePng;
Status res = image->GetPhysicalDimension(&sizePng);
HDC hDC = GetDC(getMainWnd());
HDC hdcMem = CreateCompatibleDC(hDC);
HBITMAP hBitmap = ::CreateCompatibleBitmap(hDC, (int)sizePng.Width, (int)sizePng.Height);
HBITMAP hbmOld = SelectBitmap(hdcMem, hBitmap);
CRect rc(0,0,(int)sizePng.Width, (int)sizePng.Height);
COLORREF clrOld = ::SetBkColor(hdcMem, RGB(255,255,255));
::ExtTextOut(hdcMem, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
::SetBkColor(hdcMem, clrOld);
Gdiplus::Graphics grpx(hdcMem);
res = grpx.DrawImage(image, 0, 0, (int)sizePng.Width, (int)sizePng.Height);
SelectBitmap(hdcMem, hbmOld);
DeleteDC(hdcMem);
DeleteDC(hDC);
delete image;
return hBitmap;
}
示例8: CreateThumbnail
BOOL GdiplusUtilities::CreateThumbnail(LPCTSTR srcFile, LPCTSTR thumbnailFile, ImageFormatEnum imageFormat, INT cx, INT cy)
{
Gdiplus::Bitmap* pSrcImage = Gdiplus::Bitmap::FromFile(srcFile, FALSE);
if (pSrcImage == NULL)
return FALSE;
//=== Default function...stretches the image
Gdiplus::Image* pDestImage = pSrcImage->GetThumbnailImage(cx, cy);
delete pSrcImage;
CLSID pngClsid;
UINT num = 0; // number of image encoders
UINT size = 0; // size of the image encoder array in bytes
Gdiplus::ImageCodecInfo* pImageCodecInfo = NULL;
Gdiplus::GetImageEncodersSize(&num, &size);
if(size == 0)
return -1; // Failure
pImageCodecInfo = (Gdiplus::ImageCodecInfo*)(malloc(size));
if(pImageCodecInfo == NULL)
return -1; // Failure
GetImageEncoders(num, size, pImageCodecInfo);
for(UINT j = 0; j < num; ++j)
{
if( wcscmp(pImageCodecInfo[j].MimeType, _T("image/png")) == 0 )
{
pngClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
Gdiplus::Status st = pDestImage->Save(thumbnailFile, &pngClsid, NULL);
return st == Gdiplus::Ok;
}
}
free(pImageCodecInfo);
return FALSE;
}
示例9: SetAspectRatio
void SetAspectRatio(Gdiplus::Image &image, RECT &rc)
{
double dWidth = (rc.right - rc.left);
double dHeight = (rc.bottom - rc.top);
double dAspectRatio = dWidth / dHeight;
double dImageWidth = image.GetWidth();
double dImageHeight = image.GetHeight();
double dImageAspectRatio = dImageWidth / dImageHeight;
if (dImageAspectRatio > dAspectRatio) {
double nNewHeight = (dWidth / dImageWidth*dImageHeight);
double nCenteringFactor = (dHeight - nNewHeight) / 2;
SetRect(&rc, 0, (int)nCenteringFactor, (int)dWidth, (int)(nNewHeight + nCenteringFactor));
} else if (dImageAspectRatio < dAspectRatio) {
double nNewWidth = (dHeight / dImageHeight*dImageWidth);
double nCenteringFactor = (dWidth - nNewWidth) / 2;
SetRect(&rc, (int)nCenteringFactor, 0, (int)(nNewWidth + nCenteringFactor), (int)(dHeight));
}
}
示例10: LoadImage
BOOL LoadImage(const HINSTANCE& inst, DWORD res, const TCHAR* name, IMGINFO* img_info, const HDC* mdc)
{
HRSRC src = FindResource(inst, MAKEINTRESOURCE(res), name);
if (src == NULL)
return FALSE;
DWORD len = SizeofResource(inst, src);
BYTE* byte = (BYTE*)LoadResource(inst, src);
if (byte == NULL)
return FALSE;
HGLOBAL global = GlobalAlloc(GMEM_FIXED, len);
BYTE* mem = (BYTE*)GlobalLock(global);
CopyMemory(mem, byte, len);
IStream* stream = NULL;
Gdiplus::Image* image = NULL;
HRESULT hr = CreateStreamOnHGlobal(mem, FALSE, &stream);
if (SUCCEEDED(hr))
{
image = Gdiplus::Image::FromStream(stream);
img_info->hdc = CreateCompatibleDC(*mdc);
HBITMAP hbitmap = CreateCompatibleBitmap(*mdc, image->GetWidth(), image->GetHeight());
SelectObject(img_info->hdc, hbitmap);
Gdiplus::Graphics graphics(img_info->hdc);
Gdiplus::Rect rect;
rect.X = 0.0F;
rect.Y = 0.0F;
rect.Width = image->GetWidth();
rect.Height = image->GetHeight();
Gdiplus::Status s = graphics.DrawImage(image, rect);
DeleteObject(hbitmap);
img_info->image = image;
}
GlobalUnlock(mem);
SAFE_RELEASE(stream);
FreeResource(byte);
if (SUCCEEDED(hr))
return TRUE;
else
return FALSE;
}
示例11: OnCmdFileOpen
void OnCmdFileOpen(HWND hWnd)
{
winx::OpenFileDialog dlg(
_T("Images Files(*.jpg;*.png;*.tif;*.bmp;*.gif)\0*.jpg;*.png;*.tif;*.bmp;*.gif\0All Files(*.*)\0*.*\0")
);
if (IDOK == dlg.DoModal())
{
USES_CONVERSION;
Gdiplus::Image* image = new Gdiplus::Image(T2CW(dlg.lpstrFile));
if (image->GetLastStatus() != Gdiplus::Ok)
{
delete image;
winx::ExMsgBoxTrace(hWnd, _T("Error"), _T("Can't load image from %s"), dlg.lpstrFile);
}
else
{
SetImage(image);
}
}
}
示例12: DrawImage
void Graphics::DrawImage(Image* image, const Rect& rc, const ImageAttributes* attr) {
Gdiplus::Graphics* g = reinterpret_cast<Gdiplus::Graphics*>(_private);
Gdiplus::Image* gdiImage = reinterpret_cast<Gdiplus::Image*>(image->_private);
if(attr!=0) {
Gdiplus::ImageAttributes* ia = reinterpret_cast<Gdiplus::ImageAttributes*>(attr->_private);
g->DrawImage(gdiImage, Gdiplus::Rect(rc.GetLeft(), rc.GetTop(), rc.GetWidth(), rc.GetHeight()), 0, 0, gdiImage->GetWidth(), gdiImage->GetHeight(), Gdiplus::UnitPixel, ia);
}
else {
g->DrawImage(gdiImage, ToGDIRect<Rect, Gdiplus::Rect>(rc));
}
}
示例13: BrouseFile
// ôóíêöèÿ îòêðûòèÿ ôàéëà äëÿ ïðîñìîòðà ñ âõîäÿùèì ïàðàìåòðîì - èìåíåì îòêðûâàåìîãî ãðàôè÷åñêîãî ôàéëà
void BrouseFile(AnsiString FN)
{ float ho=0;
float wo;
if (FN!=""){//åñëè èìÿ ôàéëà óêàçàíî òî âûïîëíèòü äåéñòâèÿ
Form1->Image1->Align=alClient;//ðàçâîðà÷èâàåì îáëàñòü ïðîñìîòðà íà âñþ äîñòóïíþ ïëîùàäü
Form1->Image1->Picture->Assign(0);//î÷èùàåì îáëàñòü ïðîñìîòðà
WCHAR buff[10001];
Graphics::TBitmap *Buf = new Graphics::TBitmap();//ñîçäàåì îáúåêò êëàññà TBitmap
Gdiplus::Image *image =new Gdiplus::Image (FN.WideChar(buff,10000)); //ñîçäàåì îáúåêò êëàññà Gdiplus::Image è çàãðóæàåì â íåãî èçîáðàæåíèå èç âûáðàííîãî ôàéëà
Buf->Width=image->GetWidth();//óêàçûâàåì øèðèíó è âûñîòó èçîáðàæåíèÿ
Buf->Height=image->GetHeight();
Gdiplus::Graphics graphics(Buf->Canvas->Handle);//ïåðåäàåì óêàçàòåëü íà îáúåêò Buf
graphics.DrawImage(image, 0, 0, image->GetWidth(), image->GetHeight());
//ïðîðèñîâûâàåì âçÿòîå èç ôàéëà èçîáðàæåíèå â îáúåêòå Buf
Form1->Image1->Picture->Assign(Buf);//âûâîäì ïðîðèñîâàííîå èçîáðàæåíèå â îáëàñòü ïðîñìîòðà
Form1->ScrollBox1->Refresh();//îáíîâëÿåì ðàçìåðíîñòü îáëàñòè ïðîñìîòðà
z_min=1;//èíèöèàëèçèðåì ïåðåìåííûå ìàñøàáèðîâàíèÿ
z_max=1;
Form1->StatusBar1->Panels->Items[1]->Text="Ôàéë - "+Form1->FileListBox1->Items->Strings[Form1->FileListBox1->ItemIndex];//âûâîäèì ñëóæåáíóþ èíôîðìàöèþ
Form1->StatusBar1->Panels->Items[2]->Text="Ðàçìåð - "+IntToStr(image->GetWidth())+"x"+IntToStr(image->GetHeight());
//
B->Assign(0);//î÷èùàåì ðåçåðâíûé îáúåêò êëàññà TBitmap
B->Width=Form1->Image1->Picture->Bitmap->Width;//çàäàåì ðàçìåðû ðåçåðâíîãî îáúåêòà
B->Height=Form1->Image1->Picture->Bitmap->Height;
B->Canvas->Draw(0,0,Form1->Image1->Picture->Bitmap);//ïðîðèñîâûâàåì èçîáðàæåíèå â ðåçåðâíîì îáúåêòå èç îáëàñòè ïðîñìîòðà
//åñëè êàðòèíêà èçíà÷àëüíî áîëüøå îáëàñòè ïðîñìîòðà
//òî îíà áóäåò àâòîìàòè÷åñêè óìåíüøåíà
//äàëåå îïðåäåëÿåì êîýô. óìåíüøåíèÿ
if ((B->Height>Form1->Image1->Height)||(B->Width>Form1->Image1->Width)) //åñëè ïàðìåòðû êàðòèíêè ïðåâûøàþò ïàðàìåòðû îáëàñòè
{
ho=float(Form1->Image1->Height)/float(B->Height); //âû÷èñëÿåì ñîîòíîøåíèÿ âåëè÷èí
wo=float(Form1->Image1->Width)/float(B->Width);
if (ho>wo) //îïåðåäåëÿåì áîëüøóþ èç âåëè÷èí, ÷òîáû èçîáðàæåíèå ïîìåñòèëîñü â îáëàñòè ïðîñìîòðà
{z_min=1+ho;} //óñòàíàâëèâàåì êîýô.
else {z_min=1+wo;}
}
delete image;//î÷èùàåì ïàìÿòü
delete Buf;
}
}
示例14: GenSmallImage
/**
generate some small images and render them on the backgroun.
*/
static void GenSmallImage( int img_count, Gdiplus::Graphics *g, const Gdiplus::RectF &render_rect, int sel )
{
#define RAND_ALPHA ( 100 + random( 55 ) )
if( img_count < 1 )
{
return;
}
CFileListManager &file_manager = GetInst( CFileListManager );
// render without alpha value
Gdiplus::Image *img = CreateImgFromBuffer( file_manager.GetRandSmall() );
Gdiplus::PointF render_pos = GetRandPosInULRect( img->GetWidth(), img->GetHeight(), render_rect );
Gdiplus::RectF img_rect( render_pos.X, render_pos.Y, (float)img->GetWidth(), (float)img->GetHeight() );
img_alpha( g, img, render_pos.X, render_pos.Y, img_count == 1 ? 255 : RAND_ALPHA );
delete img;
// render with random alpha value and random rotation degree
g->SetClip( img_rect );
for( int i = 1; i < img_count; ++ i )
{
img = CreateImgFromBuffer( file_manager.GetRandSmall() );
img_rotate( g, img, render_pos.X, render_pos.Y, img->GetWidth() / 2, img->GetHeight() / 2,
random( 360 ), // [0-360)
RAND_ALPHA ); // [100-155)
delete img;
}
g->ResetClip();
// blend a 'X' sign onto the picture if it's not the answer
if( img_count > 1 )
{
//BlendXSign( g, img_rect );
}
// blend 'A''B''C''D' sign.
BlendSelSign( g, img_rect, sel );
}
示例15: drawChannel
int ChannelData::drawChannel(Graphics *g, int x, int y){
REAL xx = x * 1.0f;
REAL yy = y * 1.0f;
ServentData* sd;
// 位置を保存
posX = x;
posY = y;
int w/*,h*/;
if (getWidth() == 0){
if (gW){
w = gW;
} else {
w = 400;
}
} else {
w = getWidth();
gW = w;
}
// チャンネル表示部の背景を塗る
if (isSelected()){
// 選択中
SolidBrush b(Color(160,49,106,197));
g->FillRectangle(&b, x, y, w, 14);
} else {
// 非選択
SolidBrush b(Color(160,255,255,255));
g->FillRectangle(&b, x, y, w, 14);
}
// ステータス表示
Gdiplus::Image *img = NULL;
unsigned int nowTime = sys->getTime();
if (this->type != Servent::T_COUT)
{
// COUT以外
Channel *ch = chanMgr->findChannelByChannelID(this->channel_id);
switch(this->getStatus()){
case Channel::S_IDLE:
img = img_idle;
break;
case Channel::S_SEARCHING:
case Channel::S_CONNECTING:
img = img_connect;
break;
case Channel::S_RECEIVING:
if ((skipCount > 2) && (lastSkipTime + 120 > nowTime)){
if (chDisp.relay){
img = img_conn_ok_skip;
} else {
if (chDisp.numRelays){
img = img_conn_full_skip;
} else {
img = img_conn_over_skip;
}
}
} else {
if (chDisp.relay){
img = img_conn_ok;
} else {
if (chDisp.numRelays){
img = img_conn_full;
} else {
img = img_conn_over;
}
}
}
break;
case Channel::S_BROADCASTING:
img = img_broad_ok;
break;
case Channel::S_ERROR:
// bump時にエラーが表示されるのを防止
if (ch && ch->bumped)
{
img = img_connect;
} else
{
img = img_error;
}
break;
default:
img = img_idle;
break;
}
} else
{
// COUT用
img = img_broad_ok;
}
// 描画基点
PointF origin(xx, yy);
// ステータス表示位置
Rect img_rect((INT)origin.X, (INT)origin.Y + 1, img ? img->GetWidth() : 12, 12);
// ステータス描画
ImageAttributes att;
//.........这里部分代码省略.........