CResourceBitmap::CResourceBitmap(int resId) : m_hGlobal(NULL) { HRSRC hRes = ::FindResource(g_hInstance, MAKEINTRESOURCE(resId), L"PNG"); if(!hRes) { return; } DWORD dwSize = ::SizeofResource(g_hInstance, hRes); const void *pResData = ::LockResource( ::LoadResource(g_hInstance, hRes)); if(dwSize < 1 || !pResData) { return; } HGLOBAL hGlob = ::GlobalAlloc(GMEM_MOVEABLE, dwSize); if(hGlob) { void *pGlobBuf = ::GlobalLock(hGlob); if(pGlobBuf) { memcpy_s(pGlobBuf, dwSize, pResData, dwSize); IStream *pStream; if(SUCCEEDED(::CreateStreamOnHGlobal(hGlob, FALSE, &pStream))) { Gdiplus::Bitmap* gdipBmp = Gdiplus::Bitmap::FromStream(pStream); // done its duty here, Bitmap probably keeps a ref: pStream->Release(); if(gdipBmp && gdipBmp->GetLastStatus() == Gdiplus::Ok) { // it worked! m_hGlobal = hGlob; m_bmp = std::shared_ptr<Gdiplus::Bitmap>(gdipBmp); return; // postpone cleanup to destructor! ;) } delete gdipBmp; } ::GlobalUnlock(pGlobBuf); } ::GlobalFree(hGlob); } }
void TVizMapContext::Export(const TStr& FNm, const TStr& EncoderType, const int& Width, const int& Height, const bool& ShowPointNmP, const int& PointFontSize, const int& PointNmFontScale, const double& PointWgtThreshold, const bool& ShowCatNmP, const bool& ShowKeyWdP, const int& KeyWdFontSize, const bool& ShowMgGlassP, const int& LegendGridWidth, const int& LegendGridHeight) { // create graphics Gdiplus::Bitmap* Bmp = new Gdiplus::Bitmap(Width, Height); Gdiplus::Graphics* g = Gdiplus::Graphics::FromImage(Bmp); PGks BmpGks = TWfGks::New(); // paint graphics HDC HdcHandle = g->GetHDC(); BmpGks->BeginPaint(HdcHandle); Paint(BmpGks, ShowPointNmP, PointFontSize, PointNmFontScale, PointWgtThreshold, -1, ShowCatNmP, ShowKeyWdP, KeyWdFontSize, ShowMgGlassP, LegendGridWidth, LegendGridHeight); BmpGks->EndPaint(); g->ReleaseHDC(HdcHandle); // save to disk WCHAR* FNmWChar = new WCHAR[FNm.Len() + 1]; const int Res = MultiByteToWideChar(CP_ACP, 0, FNm.CStr(), FNm.Len() + 1, FNmWChar, FNm.Len() + 1); CLSID pngClsid; GetEncoderClsid(EncoderType, &pngClsid); Bmp->Save(FNmWChar, &pngClsid, NULL); // clean after delete FNmWChar; delete Bmp; delete g; }
void GDIPlus::LoadTexture( gwen::Texture* pTexture ) { Gdiplus::Bitmap* pImage = new Gdiplus::Bitmap( pTexture->name.GetUnicode().c_str() ); pTexture->data = pImage; pTexture->width = pImage->GetWidth(); pTexture->height = pImage->GetHeight(); }
HBITMAP TaskbarWnd::GetIconicRepresentation(int nWidth, int nHeight, int scale ) { HRESULT hr = E_FAIL; Gdiplus::Bitmap* src = Gdiplus::Bitmap::FromHBITMAP( hbm_cached_,0); // scale Gdiplus::Bitmap dest( nWidth, nHeight, PixelFormat32bppARGB); { Gdiplus::RectF rDest(0,0,(Gdiplus::REAL)nWidth, (Gdiplus::REAL)nHeight ); Gdiplus::Graphics gScale( &dest ); if ( scale != 1 ) { nWidth = std::min(nWidth*scale, (int)src->GetWidth()); nHeight = std::min(nHeight*scale, (int)src->GetHeight()); } gScale.DrawImage( src, rDest,0,0,(Gdiplus::REAL)nWidth,(Gdiplus::REAL)nHeight, Gdiplus::UnitPixel, NULL, NULL, NULL ); } delete src; // retval and cleanup HBITMAP hBitmap = 0; dest.GetHBITMAP(Gdiplus::Color::Black, &hBitmap); return hBitmap; }
void MakeIcon(HICON icon, char* path) { Gdiplus::Bitmap* bitmap = Gdiplus::Bitmap::FromFile(ToWChar(path)); if (bitmap->GetWidth()) { bitmap->GetHICON(&icon); delete bitmap; } }
static void GDIPlusDecoder(CStdValVector* data) { HGLOBAL hMem = ::GlobalAlloc(GMEM_FIXED, data->m_data->getLength()); BYTE* pMem = (BYTE*)::GlobalLock(hMem); memcpy(pMem, data->m_data->getMemoryBase(), data->m_data->getLength()); IStream* pIStream = 0; ::CreateStreamOnHGlobal(hMem, FALSE, &pIStream); Gdiplus::Bitmap* pImgBitmap = Gdiplus::Bitmap::FromStream(pIStream); InitClsids(); pIStream->Release(); HRESULT hr = ::CreateStreamOnHGlobal(NULL, true, &pIStream); pImgBitmap->Save(pIStream, &s_bmpClsid, NULL); LARGE_INTEGER liTemp = {0}; pIStream->Seek(liTemp, STREAM_SEEK_SET, NULL); STATSTG stats = {0}; pIStream->Stat(&stats, 0); DWORD dwSize = (DWORD)stats.cbSize.QuadPart; delete data->m_data; data->m_data = new SkMemoryStream(dwSize); pIStream->Read((void *)data->m_data->getMemoryBase(), dwSize, NULL); ::GlobalUnlock(hMem); ::GlobalFree(hMem); pIStream->Release(); delete pImgBitmap; }
void GDIPlus::DrawTexturedRect( Gwen::Texture* pTexture, Gwen::Rect pTargetRect, float u1, float v1, float u2, float v2 ) { Gdiplus::Bitmap* pImage = (Gdiplus::Bitmap*) pTexture->data; // Missing image, not loaded properly? if ( !pImage || pImage->GetType() == Gdiplus::ImageTypeUnknown ) return DrawMissingImage( pTargetRect ); Translate( pTargetRect ); Gdiplus::RectF TargetRect( pTargetRect.x, pTargetRect.y, pTargetRect.w, pTargetRect.h ); // Convert UV to pixel coords float fW = pImage->GetWidth(); float fH = pImage->GetHeight(); u1 *= fW; v1 *= fH; u2 *= fW; u2 -= u1; v2 *= fH; v2 -= v1; graphics->DrawImage( pImage, TargetRect, u1, v1, u2, v2, Gdiplus::UnitPixel ); }
static void getImagePropertiesHelper(vl::ImageShape & shape, Gdiplus::Bitmap & bitmap) { bool grayscale = (bitmap.GetFlags() & ImageFlagsColorSpaceGRAY) ; shape.width = bitmap.GetWidth() ; shape.height = bitmap.GetHeight() ; shape.depth = grayscale ? 1 : 3 ; }
/** * Creates an image list. * @param id Bitmap resource id. * @remark This method assumes that id+1 is the 32-bit toolbar image. Further images * can be added to support different color depths. * @return A handle to the imagelist or NULL on failure. */ HIMAGELIST ToolbarControl::CreateImageList( Int id ) { HIMAGELIST imageList = NULL; OSVERSIONINFO ovi; ovi.dwOSVersionInfoSize = sizeof(ovi); ::GetVersionEx( &ovi ); if( ovi.dwMajorVersion >= 5 && ovi.dwMinorVersion >= 1 ) { // Windows XP or above Gdiplus::Bitmap* bitmap = ResourceManager::LoadImage( MAKEINTRESOURCE(id), "PNG" ); if( bitmap != NULL ) { HBITMAP hBitmap; bitmap->GetHBITMAP(Gdiplus::Color(0xFFFFFFFF), &hBitmap); imageList = ImageList_Create( imageWidth, imageHeight, ILC_COLOR32, 6, 1 ); ImageList_Add( imageList, hBitmap, NULL ); ::DeleteObject( hBitmap ); delete bitmap; } } else { HBITMAP hBitmap = (HBITMAP)::LoadImageA( g_hInstance, MAKEINTRESOURCE( id ), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION ); imageList = ImageList_Create( imageWidth, imageHeight, ILC_MASK | ILC_COLOR24, 6, 1 ); ImageList_AddMasked( imageList, hBitmap, RGB(255, 0, 255) ); ::DeleteObject( hBitmap ); } IMAGEINFO ii; ImageList_GetImageInfo( imageList, 0, &ii ); return imageList; }
///Convert the given RGB array to a JPEG image. The JPEG image is returned in a BYTE array while the length of the array is returned through parameter BYTE* convertToJPEG(BYTE* RGBArray, UINT &length) { BITMAPINFO bmi; //Create bitmap header memset(&bmi, 0, sizeof(bmi)); bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biWidth = 1920; bmi.bmiHeader.biHeight = -1080; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biBitCount = 24; Gdiplus::Bitmap* myImage = new Gdiplus::Bitmap(&bmi, RGBArray); //Form bitmap out of provided RGB array IStream *jpgStream; CLSID jpgClsid; GetEncoderClsid(L"image/jpeg", &jpgClsid); //Get the encoder CreateStreamOnHGlobal(NULL, TRUE, &jpgStream); //Get direct access to physical memory. Create a stream to save directly into it. Delete when stream is released myImage->Save(jpgStream, &jpgClsid); //Save the jpg image into physical memory STATSTG stats; jpgStream->Stat(&stats, STATFLAG_NONAME); //Get stats of the jpg image; more importantly, the size BYTE *jpg = new BYTE[stats.cbSize.QuadPart]; //Create byte array for transferring image to. ULONG read; LARGE_INTEGER lg; lg.QuadPart = 0; jpgStream->Seek(lg, STREAM_SEEK_SET, NULL); //Move to beginning of stream jpgStream->Read(jpg, stats.cbSize.QuadPart, &read); //Read entire stream into the array jpgStream->Release(); //Release the stream length = stats.cbSize.QuadPart; //Save the length of the byte array return jpg; }
Gdiplus::Bitmap* GdiplusUtilities::FromHICON32(HICON hIcon) { Gdiplus::Bitmap* ret = NULL; ICONINFO iconInfo; GetIconInfo(hIcon, &iconInfo); BITMAP bitmapData; GetObject(iconInfo.hbmColor, sizeof(BITMAP), &bitmapData); if (bitmapData.bmBitsPixel != 32) ret = Gdiplus::Bitmap::FromHICON(hIcon); else { ret = new Gdiplus::Bitmap(bitmapData.bmWidth, bitmapData.bmHeight, PixelFormat32bppARGB); Gdiplus::BitmapData bmpData; ret->LockBits(&Gdiplus::Rect(0,0,bitmapData.bmWidth, bitmapData.bmHeight), Gdiplus::ImageLockModeWrite, PixelFormat32bppARGB, &bmpData); #ifndef GetDIBitsVERSION //===Version GetBitmapBits // THIS FUNCTION IS UNDER TESTING. WHAT IF THE bitmap stride is different? Where will the new data go? ASSERT(bmpData.Stride == bmpData.Width * 4); ::GetBitmapBits(iconInfo.hbmColor, 4 * bitmapData.bmWidth * bitmapData.bmHeight, bmpData.Scan0); //===Version GetBitmapBits===END #else //===Version GetDIBits (incomplete) ::GetDIBits(GetDC(), iconInfo.hbmColor, 0, bitmapData.bm) //===Version GetDIBits #endif ret->UnlockBits(&bmpData); } DeleteObject(iconInfo.hbmColor); DeleteObject(iconInfo.hbmMask); return ret; }
// hack for stupid GDIplus void Gdip_RemoveAlpha(Gdiplus::Bitmap& source, Gdiplus::Color color ) { using namespace Gdiplus; Rect r( 0, 0, source.GetWidth(),source.GetHeight() ); BitmapData bdSrc; source.LockBits( &r, ImageLockModeRead , PixelFormat32bppARGB,&bdSrc); BYTE* bpSrc = (BYTE*)bdSrc.Scan0; //bpSrc += (int)sourceChannel; for ( int i = r.Height * r.Width; i > 0; i-- ) { BGRA_COLOR * c = (BGRA_COLOR *)bpSrc; if(c->a!=255) { //c = 255; DWORD * d= (DWORD*)bpSrc; *d= color.ToCOLORREF(); c ->a= 255; } bpSrc += 4; } source.UnlockBits( &bdSrc ); }
Surface8u convertGdiplusBitmap( Gdiplus::Bitmap &bitmap ) { Gdiplus::BitmapData bitmapData; Gdiplus::Rect rect( 0, 0, bitmap.GetWidth(), bitmap.GetHeight() ); Gdiplus::PixelFormat requestedFormat = bitmap.GetPixelFormat(); SurfaceChannelOrder sco; bool premult; gdiplusPixelFormatToSurfaceChannelOrder( requestedFormat, &sco, &premult ); if( sco == SurfaceChannelOrder::UNSPECIFIED ) { UINT flags = bitmap.GetFlags(); sco = ( flags & Gdiplus::ImageFlagsHasAlpha ) ? SurfaceChannelOrder::BGRA : SurfaceChannelOrder::BGR; requestedFormat = ( flags & Gdiplus::ImageFlagsHasAlpha ) ? PixelFormat32bppARGB : PixelFormat24bppRGB; } bitmap.LockBits( &rect, Gdiplus::ImageLockModeRead, requestedFormat, &bitmapData ); Surface8u result( bitmap.GetWidth(), bitmap.GetHeight(), sco.hasAlpha(), sco ); const uint8_t *srcDataBase = (uint8_t*)bitmapData.Scan0; int32_t width = bitmap.GetWidth(); for( uint32_t y = 0; y < bitmap.GetHeight(); ++y ) { memcpy( result.getData( Vec2i( 0, y ) ), srcDataBase + y * bitmapData.Stride, width * result.getPixelInc() ); } bitmap.UnlockBits( &bitmapData ); return result; }
// 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; }
bool CTuoImage::LoadFromFile(bool bPNG) { std::wstring strPath; if (bPNG) strPath = g_strSkinDir + _T("\\") + m_strFileName + _T(".png"); else strPath = g_strSkinDir + _T("\\") + m_strFileName + _T(".ico"); Gdiplus::Bitmap *pBitmap = Gdiplus::Bitmap::FromFile(strPath.c_str()); if (pBitmap) { if (pBitmap->GetLastStatus() == Gdiplus::Ok) { if (m_hBitmap) ::DeleteObject(m_hBitmap); pBitmap->GetHBITMAP(NULL, &m_hBitmap); } BITMAP bmpData; ::GetObject(m_hBitmap, sizeof(BITMAP), &bmpData); m_iWidth = bmpData.bmWidth; m_iHeight = bmpData.bmHeight; m_bUseBitblt = bmpData.bmBitsPixel < 32; delete pBitmap; return true; } return false; }
void gdiplus_container::get_img_size( litehtml::uint_ptr img, litehtml::size& sz ) { Gdiplus::Bitmap* bmp = (Gdiplus::Bitmap*) img; if(bmp) { sz.width = bmp->GetWidth(); sz.height = bmp->GetHeight(); } }
Bitmap CanvasGdiplus::ExtractBitmap() const { DCHECK(!mem_bitmap_.IsNull()); // 生成一个位图, 绘制画布内容到其中并返回. Gdiplus::Bitmap* bitmap = mem_bitmap_.GetNativeBitmap(); Gdiplus::Rect rc_bitmap(0, 0, bitmap->GetWidth(), bitmap->GetHeight()); return Bitmap(bitmap->Clone(rc_bitmap, bitmap->GetPixelFormat())); }
int NativeMenu::AddSubMenu(HMENU& menu,Settings* settings){ int length = settings->getInteger("length",0); Settings* item; TCHAR* label; TCHAR* icon; appjs_action_callback* actionCb; for( int i = 0; i < length; i++ ) { item = new Settings( settings->getObject( i ) ); label = item->getString("label",TEXT("")); icon = item->getString("icon",TEXT("")); actionCb = new appjs_action_callback(); actionCb->action = Persistent<Object>::New( item->getObject("action") ); actionCb->item = Persistent<Object>::New( settings->getObject( i ) ); actionCb->menu = this; Settings* subsettings = new Settings(item->getObject("submenu")); HMENU submenu = CreateMenu(); if(AddSubMenu(submenu,subsettings)) { // has submenu MENUINFO menuInfo; memset(&menuInfo, 0, sizeof(menuInfo)); menuInfo.cbSize = sizeof(menuInfo); menuInfo.fMask = MIM_STYLE; menuInfo.dwStyle = MNS_NOTIFYBYPOS; SetMenuInfo(submenu,&menuInfo); AppendMenu(menu,MF_POPUP,(UINT)submenu,label); } else { // does not have submenu MENUITEMINFO menuItemInfo; menuItemInfo.cbSize = sizeof(MENUITEMINFO); menuItemInfo.fMask = MIIM_DATA; menuItemInfo.dwTypeData = label; menuItemInfo.dwItemData =(ULONG_PTR) actionCb; menuItemInfo.cch = wcslen(label); if( wcslen(label) == 0 ) { menuItemInfo.fMask |= MIIM_TYPE; menuItemInfo.fType = MF_SEPARATOR; } else { menuItemInfo.fMask |= MIIM_STRING; if(item->has("icon")) { menuItemInfo.fMask |= MIIM_BITMAP; HBITMAP bitmap; Gdiplus::Color color; Gdiplus::Bitmap* img = Gdiplus::Bitmap::FromFile(icon); img->GetHBITMAP(color, &bitmap); menuItemInfo.hbmpItem = bitmap; } } InsertMenuItem(menu,i,false,&menuItemInfo); } } return length; }
Gwen::Color GDIPlus::PixelColour( Gwen::Texture* pTexture, unsigned int x, unsigned int y, const Gwen::Color& col_default ) { Gdiplus::Bitmap* pImage = (Gdiplus::Bitmap*) pTexture->data; if ( !pImage ) return col_default; Gdiplus::Color c; pImage->GetPixel( x, y, &c ); return Gwen::Color( c.GetR(), c.GetG(), c.GetB(), c.GetA() ); }
//------------------------------------------------------------------------------------- void DlgOpenImage::OnFileNameChange() { m_thumb.ApplyEffect (FCEffectFillColor(FCColor(255,255,255))) ; CString szFile = GetPathName() ; FCImageProperty prop ; CSize sizeImage (0,0) ; if (PathFileExists(szFile)) { IMAGE_TYPE imgType = FCImageCodecFactory::GetTypeByFileExt(szFile) ; if ( (imgType == IMG_JPG) || (imgType == IMG_BMP) || (imgType == IMG_PNG) || (imgType == IMG_TIF) || (imgType == IMG_GIF) ) { Gdiplus::Bitmap bmp (szFile) ; if (bmp.GetLastStatus() == Gdiplus::Ok) { sizeImage = CSize (bmp.GetWidth(), bmp.GetHeight()) ; FCImageCodec_Gdiplus::GetPropertyFromBitmap(bmp, prop) ; // calculate thumb size CRect rc (0, 0, m_thumb.Width(), m_thumb.Height()) ; rc = FCObjGraph::CalcFitWindowSize (sizeImage, rc) ; FCImageDrawDC memDC (m_thumb) ; Gdiplus::Graphics(memDC).DrawImage (&bmp, rc.left, rc.top, rc.Width(), rc.Height()) ; } } } // update size CString s ; if (sizeImage.cx && sizeImage.cy) { s.Format(L"%d x %d", sizeImage.cx, sizeImage.cy) ; s = L"Size :" + s ; } SetDlgItemText(IDC_SIZE_VALUE, s) ; // update date s = L"" ; if (prop.m_ExifDTOrig.length()) { s = L"Date :" + CString(prop.m_ExifDTOrig.c_str()) ; } SetDlgItemText(IDC_DATE_VALUE, s) ; m_ctrl.Invalidate() ; }
BOOL CVideoPane::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here // 获取参数 CRect rect; GetClientRect(rect); CString strOcxPath = eLTE_Tool::GetOcxPath(); // 设置图标 Gdiplus::Bitmap* pBitmap = Gdiplus::Bitmap::FromFile(strOcxPath + _T("Skin\\Icon.ico")); if (NULL != pBitmap && Gdiplus::Ok == pBitmap->GetLastStatus()) { HICON hIcon = NULL; pBitmap->GetHICON(&hIcon); if (NULL != hIcon) { SetIcon(hIcon, FALSE); // Set small icon SetIcon(hIcon, TRUE); // Set big icon } } // 显示边框 ModifyStyle(0, WS_BORDER); SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_DRAWFRAME); // 创建标题栏 CreateCaption(rect, strOcxPath); // 创建视频窗口 CreateVideoStatic(rect, strOcxPath); // 创建工具栏 CreateToolBar(rect, strOcxPath); // 禁用按钮 EnableImageButton(FALSE); // 工具栏隐藏 if (!m_bShowToolBar) { m_SnapshotBtn.ShowWindow(SW_HIDE); m_ReversePlayBtn.ShowWindow(SW_HIDE); m_FullScreenBtn.ShowWindow(SW_HIDE); m_AudioBtn.ShowWindow(SW_HIDE); } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
LRESULT CMediaClipView::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { CPaintDC dc(m_hWnd); { Gdiplus::Graphics graphics(dc.m_hDC); Gdiplus::Bitmap* pBitmap; GetBitmap(&pBitmap); if (pBitmap) { CRect client; GetClientRect(&client); graphics.DrawImage(pBitmap, m_videoRect, 0, 0, pBitmap->GetWidth(), pBitmap->GetHeight(), Gdiplus::UnitPixel); } } dc.FillSolidRect(&m_bottomRect, GetSysColor(COLOR_BTNFACE)); dc.FillSolidRect(&m_sliderRect, RGB(220, 220, 220)); { /* CComQIPtr<IMediaSeeking> mediaSeeking = m_dsGraph; LONGLONG llpos; mediaSeeking->GetCurrentPosition(&llpos); double seconds = (double)llpos / 10000000; //seconds; */ double secondWidth = m_sliderRect.Width() / m_pStream->m_pDocument->m_duration; int x = m_sliderRect.left + (m_pStream->m_pDocument->m_currentTime * secondWidth); dc.MoveTo(x, m_sliderRect.top); dc.LineTo(x, m_sliderRect.bottom); double clipBegin = m_pStream->m_pDocument->GetClipBegin(); double clipEnd = m_pStream->m_pDocument->GetClipEnd(); x = m_sliderRect.left + (clipBegin * secondWidth); dc.DrawText("{", 1, CRect(x-5, m_sliderRect.top, x+5, m_sliderRect.bottom), DT_CENTER | DT_SINGLELINE); x = m_sliderRect.left + (clipEnd * secondWidth); dc.DrawText("}", 1, CRect(x-5, m_sliderRect.top, x+5, m_sliderRect.bottom), DT_CENTER | DT_SINGLELINE); } return 0; }
view::pixel_t* read(wchar_t *filename){ Gdiplus::Bitmap *bmp = Gdiplus::Bitmap::FromFile(filename); if (bmp->GetLastStatus() != Gdiplus::Ok) return 0; Gdiplus::Rect r; r.X = 0; r.Y = 0; r.Width = bmp->GetWidth(); r.Height = bmp->GetHeight(); Gdiplus::BitmapData data; bmp->LockBits(&r, Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, &data); return (view::pixel_t*)data.Scan0; }
void CListViewNode::OnCalcRects(Gdiplus::Graphics* graphics, LPRECT pRect, LPINT maxWidth) { if ( !m_listView ) return; Gdiplus::Font* pFont = NULL; if ( m_selected ) pFont = m_listView->get_Font(_T(".Font.Selected"), _T("ListView")); else pFont = m_listView->get_Font(_T(".Font.Normal"), _T("ListView")); Gdiplus::PointF pt; pt.X = (Gdiplus::REAL)(pRect->left); pt.Y = (Gdiplus::REAL)(pRect->top); Gdiplus::RectF textRect; if ( m_text.IsEmpty() ) { textRect.X = pt.X; textRect.Y = pt.Y; textRect.Height = pFont->GetHeight(graphics); textRect.Width = 10; } else graphics->MeasureString(m_text.GetString(), m_textDisplayLength, pFont, pt, Gdiplus::StringFormat::GenericTypographic(), &textRect); Convert2Rect(pRect, &textRect); Gdiplus::Bitmap* image = NULL; LONG hImage = 0; if ( (m_imageIndex >= 0) && (((dword)m_imageIndex) < m_listView->get_ImageCount()) ) image = m_listView->get_Image(m_imageIndex); if ( image && (image->GetHeight() > 0) ) hImage = image->GetHeight(); ::SetRect(&m_iconRect, pRect->left, pRect->top, pRect->left + hImage, (hImage > 0)?(pRect->top + hImage):(pRect->bottom)); if ( (hImage > 0) && ((pRect->bottom - pRect->top) > hImage) ) ::OffsetRect(&m_iconRect, 0, (pRect->bottom - pRect->top - hImage) / 2); ::OffsetRect(pRect, hImage + 2, 0); ::CopyRect(&m_textRect, pRect); if ( hImage > (pRect->bottom - pRect->top) ) ::OffsetRect(&m_textRect, 0, (hImage - (pRect->bottom - pRect->top)) / 2); ::CopyRect(&m_borderRect, &m_textRect); m_borderRect.right += 4; m_borderRect.bottom += 4; ::OffsetRect(&m_textRect, 2, 2); if ( m_borderRect.right > *maxWidth ) *maxWidth = m_borderRect.right; ::OffsetRect(pRect, -(hImage + 2), 0); pRect->top = max(m_iconRect.bottom, m_borderRect.bottom); pRect->bottom = 0; }
Meter::Meter(std::wstring bitmapName, int x, int y, int units) : _value(0.0f), _drawnValue(-1.0f), _units(units), _drawnUnits(-1) { _rect.X = x; _rect.Y = y; Gdiplus::Bitmap *bmp = Gdiplus::Bitmap::FromFile( bitmapName.c_str(), false); CLOG(L"Loading meter bitmap: %s\nStatus: %d", bitmapName.c_str(), bmp->GetLastStatus()); _bitmap = bmp; _rect.Width = bmp->GetWidth(); _rect.Height = bmp->GetHeight(); }
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; }
void SaveGIF(HBITMAP hBmp, TCHAR* szFilename) { Gdiplus::GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); Gdiplus::Bitmap *pBitmap = Gdiplus::Bitmap::FromHBITMAP(hBmp, (HPALETTE)GetStockObject(DEFAULT_PALETTE) ); if( pBitmap ) { // Get the CLSID of the GIF encoder. CLSID clsidEncoder; if( GetEncoderClsid(L"image/gif", clsidEncoder)) { LPWSTR pswFile = mir_t2u(szFilename); pBitmap->Save((const WCHAR*)pswFile, &clsidEncoder, NULL); mir_free(pswFile); } delete pBitmap; } Gdiplus::GdiplusShutdown(gdiplusToken); }
int DxFont::GetCharMaxX(Gdiplus::Bitmap & charBitmap) { int width = charBitmap.GetWidth( ); int height = charBitmap.GetHeight( ); for(int x = width - 1; x >= 0; --x ) { for(int y = 0; y < height; ++y) { Gdiplus::Color color; charBitmap.GetPixel(x, y, &color); if( color.GetAlpha() > 0) return x; } } return width - 1; }
static std::pair<bool, String> save_png_gdiplus(const Path &filename, const ImageBW &img) { // gdi+ does not support URIs Path winname(filename); winname.ToWindows(); const auto newsize = winname.Size() + 1; auto wcstring = std::vector<wchar_t>(newsize); auto convertedChars = size_t(0); mbstowcs_s(&convertedChars, wcstring.data(), newsize, winname.CStr(), _TRUNCATE); Gdiplus::Bitmap *outbm = outbm = new Gdiplus::Bitmap(INT(img.GetWidth()), INT(img.GetHeight()), PixelFormat1bppIndexed); if (!outbm) { return std::make_pair(false, String(_("Cannot create bitmap"))); } Gdiplus::BitmapData bitmapData; auto clip = Gdiplus::Rect(0, 0, outbm->GetWidth(), outbm->GetHeight()); outbm->LockBits(&clip, Gdiplus::ImageLockModeWrite, PixelFormat1bppIndexed, &bitmapData); auto *pixels = (uint8_t*)bitmapData.Scan0; //#pragma omp parallel for FOREACHPIXEL(x, y, img) { size_t poffset = x / 8 + y * bitmapData.Stride; if (img.At(x, y)) { uint8_t b = 1 << (7 - (x % 8)); pixels[poffset] |= b; } }
//--------------------------------------------------------------------------- HRESULT CreateAtlasTexture(ID3D11Device* device, Gdiplus::Bitmap& fontSheetBitmap, const FontAtlasSizeInfo* pSizeInfo, ID3D11Texture2D** ppD3dTexture, ID3D11ShaderResourceView** ppD3dShaderResourceView ) { using namespace Gdiplus; HRESULT hr = S_OK; // Lock the bitmap for direct memory access BitmapData bmData; Rect rect(0, 0, pSizeInfo->atlasTextureWidth, pSizeInfo->atlasTextureHeight ); fontSheetBitmap.LockBits(&rect,ImageLockModeRead, PixelFormat32bppARGB, &bmData); // Copy into a texture. D3D11_TEXTURE2D_DESC texDesc; texDesc.Width = pSizeInfo->atlasTextureWidth; texDesc.Height = pSizeInfo->atlasTextureHeight; texDesc.MipLevels = 1; texDesc.ArraySize = 1; texDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; texDesc.SampleDesc.Count = 1; texDesc.SampleDesc.Quality = 0; texDesc.Usage = D3D11_USAGE_IMMUTABLE; texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; texDesc.CPUAccessFlags = 0; texDesc.MiscFlags = 0; D3D11_SUBRESOURCE_DATA data; data.pSysMem = bmData.Scan0; data.SysMemPitch = pSizeInfo->atlasTextureWidth * 4; data.SysMemSlicePitch = 0; hr = device->CreateTexture2D(&texDesc, &data, ppD3dTexture ); if(FAILED(hr)) return hr; D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; srvDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; srvDesc.Texture2D.MipLevels = 1; srvDesc.Texture2D.MostDetailedMip = 0; hr = device->CreateShaderResourceView(*ppD3dTexture, &srvDesc, ppD3dShaderResourceView ); if(FAILED(hr)) return hr; fontSheetBitmap.UnlockBits(&bmData); return hr; }