Exemplo n.º 1
0
// *************************************************************
//		GetImageAttributes()
// *************************************************************
Gdiplus::ImageAttributes* ImageHelper::GetImageAttributes(IImage* img)
{
	if (!img) return NULL;

	Gdiplus::ImageAttributes* attr = new Gdiplus::ImageAttributes();

	attr->SetWrapMode(Gdiplus::WrapModeTileFlipXY);

	VARIANT_BOOL useTransparency;
	img->get_UseTransparencyColor(&useTransparency);

	OLE_COLOR clr1, clr2;
	img->get_TransparencyColor(&clr1);
	img->get_TransparencyColor2(&clr2);

	SetTransparency(*attr, useTransparency ? true : false, clr1, clr2);

	Gdiplus::ColorMatrix m = GetColorMatrix(img);
	attr->SetColorMatrix(&m);

	Gdiplus::REAL gamma;	
	img->get_Gamma(&gamma);
	attr->SetGamma(gamma);

	return attr;
}
Exemplo n.º 2
0
    void CanvasGdiplus::RestoreLayer()
    {
        DCHECK(layers_.size());
        
        CanvasLayer* layer = layers_.top();
        layers_.pop();
        DCHECK(layer);

        Gdiplus::Graphics* current = GetCurrentGraphics();
        Gdiplus::Bitmap* native_bitmap =
            layer->mem_bitmap.GetNativeBitmap();
        Gdiplus::ImageAttributes ia;
        Gdiplus::ColorMatrix cm =
        {
            1.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 1.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 1.0, 0.0, 0.0,
            0.0, 0.0, 0.0, (static_cast<float>(layer->alpha))/255, 0.0,
            0.0, 0.0, 0.0, 0.0, 1.0
        };
        ia.SetColorMatrix(&cm);
        Gdiplus::Rect destRect(layer->bounds.x(), layer->bounds.y(),
            layer->bounds.width(), layer->bounds.height());
        current->DrawImage(native_bitmap, destRect,
            layer->bounds.x(), layer->bounds.y(),
            layer->bounds.width(), layer->bounds.height(),
            Gdiplus::UnitPixel, &ia);

        delete layer;
    }
Exemplo n.º 3
0
void CVideoPane::OnPaint()
{
	CPaintDC dc(this); // device context for painting
	// TODO: Add your message handler code here
	// Do not call CDialog::OnPaint() for painting messages

	// 绘制标题栏
	if (NULL != m_pImgCaption)
	{
		// 设置坐标
		CRect rect;
		GetClientRect(rect);
		Gdiplus::Rect gRect(rect.left, rect.top, rect.right, CAPTION_HEIGHT);
		Gdiplus::ImageAttributes ImgAtt;
		ImgAtt.SetWrapMode(Gdiplus::WrapModeTileFlipXY); 
		Gdiplus::Graphics graphics(dc);
		graphics.DrawImage(m_pImgCaption, gRect, 0, 0, (INT)m_pImgCaption->GetWidth(), (INT)m_pImgCaption->GetHeight(), Gdiplus::UnitPixel, &ImgAtt);
	}

	// 标题栏文本
	CRect rect;
	GetClientRect(rect);
	rect.left += BTN_CLOSE_SPACE;
	rect.bottom = CAPTION_HEIGHT;
	dc.SetBkMode(CAPTION_FONT_BKCLR);
	dc.SetTextColor(CAPTION_FONT_COLOR);
	CFont font;
	font.CreateFont(CAPTION_FONT_SIZE, 0, 0, 0, FW_NORMAL, FALSE,FALSE,FALSE,0,0,0,0,0,CAPTION_FONT_NAME);
	dc.SelectObject(font);
	dc.DrawText(m_strCaptionText, -1, &rect, DT_SINGLELINE | DT_VCENTER);
}
Exemplo n.º 4
0
void ImageAttributes::SetColorMatrix(const ColorMatrix* cm) {
    Gdiplus::ColorMatrix gdiMatrix;
    for(int a = 0; a < 5; a++) {
        for(int b = 0; b < 5; b++) {
            gdiMatrix.m[a][b] = cm->m[a][b];
        }
    }

    Gdiplus::ImageAttributes* ia = reinterpret_cast<Gdiplus::ImageAttributes*>(_private);
    ia->SetColorMatrix(&gdiMatrix);
}
bool CInstallDesktopTipWnd::LoadBkgImage()
{
    HRSRC hRes = FindResource(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_PNG_NEW), _T("png"));
    if(hRes == NULL)
    {
        return false;
    }
    DWORD dwResSize = SizeofResource(AfxGetInstanceHandle(), hRes);
    if(dwResSize <= 0)
    {
        return false;
    }
    HGLOBAL hResData = LoadResource(AfxGetInstanceHandle(), hRes);
    if(hResData == NULL)
    {
        return false;
    }
    LPVOID lpResourceData = LockResource(hResData);
    HGLOBAL hResourceBuffer = GlobalAlloc(GMEM_MOVEABLE, dwResSize);
    LPVOID lpResourceBuffer = GlobalLock(hResourceBuffer); 
    CopyMemory(lpResourceBuffer, lpResourceData, dwResSize);
    IStream* piStream = NULL; 
    if(CreateStreamOnHGlobal(hResourceBuffer, FALSE, &piStream) == S_OK)
    {
        m_Image = Image::FromStream(piStream);
        piStream->Release();
    }
    GlobalUnlock(hResourceBuffer);
    GlobalFree(hResourceBuffer);
    FreeResource(hResData);

    ATLASSERT(m_Image);
    m_ImageWidth = m_Image->GetWidth();
    m_ImageHeight = m_Image->GetHeight();

    m_ImageMemBitmap = CreateDefaultDIBSection(m_ImageWidth, m_ImageHeight);
    m_ImageMemDC = ::CreateCompatibleDC(NULL);
    ::SelectObject(m_ImageMemDC, m_ImageMemBitmap);

    Gdiplus::Graphics memGraphics(m_ImageMemDC);
    memGraphics.SetCompositingMode(CompositingModeSourceOver);
    memGraphics.SetCompositingQuality(CompositingQualityHighSpeed);
    BitBlt(m_ImageMemDC, 0, 0, m_ImageWidth, m_ImageHeight, NULL, 0, 0, BLACKNESS);
    Gdiplus::ImageAttributes imAtt; 	
    imAtt.SetWrapMode(Gdiplus::WrapModeTileFlipXY);
    memGraphics.DrawImage(m_Image, Gdiplus::Rect(0, 0, m_ImageWidth, m_ImageHeight),
        0, 0, m_ImageWidth, m_ImageHeight, Gdiplus::UnitPixel, &imAtt, NULL, NULL);

    return true;
}
Exemplo n.º 6
0
void CVideoStatic::SetBackGroudImage(const CPaintDC& dc)
{
	// ¼ÓÔر³¾°logoͼƬ
	if (NULL == m_pImage)
	{
		m_pImage = Gdiplus::Image::FromFile(m_strLogoPath);
		if (NULL == m_pImage)
		{
			LOG_RUN_ERROR("m_pImage is null.");
			return;
		}
		else
		{
			if (Gdiplus::Ok != m_pImage->GetLastStatus())
			{
				std::string strPath = eLTE_Tool::UnicodeToANSI(m_strLogoPath.GetString()).c_str();
				LOG_RUN_ERROR("Gdiplus::Image::FromFile failed. (%s)", strPath.c_str());
				m_pImage = NULL;
				return;
			}
		}
	}

	// ¾ÓÖÐλÖüÆËã
	CRect rect;
	GetClientRect(&rect);
	int iWidth = (int)m_pImage->GetWidth();
	int iHeight = (int)m_pImage->GetHeight();
	if ((double)rect.right/rect.bottom > (double)iWidth/iHeight)
	{
		iHeight = rect.bottom / 3;
		iWidth = iHeight * (int)m_pImage->GetWidth() / (int)m_pImage->GetHeight();
	}
	else
	{
		iWidth = rect.right / 3;
		iHeight = iWidth * (int)m_pImage->GetHeight() / (int)m_pImage->GetWidth();
	}

	int iLeft = (rect.right - iWidth) / 2;
	int iTop = (rect.bottom - iHeight) / 2;

	// »æÖÆͼƬ
	Gdiplus::Graphics graphics(dc);
	Gdiplus::Rect gRect(iLeft, iTop, iWidth, iHeight);
	Gdiplus::ImageAttributes ImgAtt;
	ImgAtt.SetWrapMode(Gdiplus::WrapModeTileFlipXY);
	graphics.DrawImage(m_pImage, gRect, 0, 0, (INT)m_pImage->GetWidth(), (INT)m_pImage->GetHeight(), Gdiplus::UnitPixel, &ImgAtt);
}
Exemplo n.º 7
0
BOOL CBSObject::DrawPNG(HDC hDC, const RECT &rectDst, Gdiplus::Image* pImage, const RECT* prectImagePortion /*= NULL*/)
{
	BOOL bRet = FALSE;

    if (pImage > 0)
    {
        Gdiplus::Graphics graphics(hDC);

        Gdiplus::RectF cRectF(static_cast<Gdiplus::REAL>(rectDst.left), 
            static_cast<Gdiplus::REAL>(rectDst.top), 
            static_cast<Gdiplus::REAL>(rectDst.right - rectDst.left), 
            static_cast<Gdiplus::REAL>(rectDst.bottom - rectDst.top));
								
	    Gdiplus::ImageAttributes clImgAtt;
	    clImgAtt.SetWrapMode(Gdiplus::WrapModeTileFlipXY);

        if (NULL == prectImagePortion)
		{
			graphics.DrawImage(pImage, 
                cRectF, 
                static_cast<Gdiplus::REAL>(0), 
                static_cast<Gdiplus::REAL>(0),
                static_cast<Gdiplus::REAL>(pImage->GetWidth()), 
                static_cast<Gdiplus::REAL>(pImage->GetHeight()),
				Gdiplus::UnitPixel, 
                &clImgAtt); //
		}
		else
        {
			graphics.DrawImage(pImage, 
                cRectF, 
                static_cast<Gdiplus::REAL>(prectImagePortion->left), 
				static_cast<Gdiplus::REAL>(prectImagePortion->top), 
				static_cast<Gdiplus::REAL>(prectImagePortion->right - prectImagePortion->left), 
				static_cast<Gdiplus::REAL>(prectImagePortion->bottom - prectImagePortion->top), 
				Gdiplus::Unit::UnitPixel, 
				NULL, //&clImgAtt
				NULL, 
				NULL);
		}

        bRet = TRUE;
    }

	return bRet;
}
Exemplo n.º 8
0
void Splash::DrawPNG(PNG* lpPNG, ColorMatrix* cmMatrix)
{
	// Check alpha
	if(lpPNG->fAlpha <= 0.0f) return;

	// Check cmMatrix for null
	if(cmMatrix == NULL) cmMatrix = &ClrMatrix;

	// Set alpha
	cmMatrix->m[3][3] = lpPNG->fAlpha;
	Gdiplus::ImageAttributes iaAttr;
	iaAttr.SetColorMatrix(cmMatrix, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap);
	
	// Draw
	_oGrphInf.graphics->DrawImage(lpPNG->GetImage(), *lpPNG->frcDest, lpPNG->frcSrc->X, lpPNG->frcSrc->Y, lpPNG->frcSrc->Width, lpPNG->frcSrc->Height, Gdiplus::UnitPixel, &iaAttr);
	_oGrphInf.graphics->Flush();
}
Exemplo n.º 9
0
// *************************************************************
//		GetImageAttributes()
// *************************************************************
Gdiplus::ImageAttributes* ImageHelper::GetImageAttributes(float alpha, bool useTransparency, OLE_COLOR clr1, OLE_COLOR clr2)
{
	Gdiplus::ImageAttributes* attr = new Gdiplus::ImageAttributes();

	attr->SetWrapMode(Gdiplus::WrapModeTileFlipXY);

	Gdiplus::ColorMatrix matrix;

	ZeroMemory((void*)&matrix.m, 25 * sizeof(REAL));
	for (int i = 0; i < 5; i++) matrix.m[i][i] = 1.0f;

	matrix.m[3][3] = alpha;
	attr->SetColorMatrix(&matrix);

	SetTransparency(*attr, useTransparency, clr1, clr2);

	return attr;
}
Exemplo n.º 10
0
Gdiplus::Bitmap* CSkinUnitODL::CreateImageData( INT nGroutX, INT nGroutY, INT nSrcWidth, INT nSrcHeight, Gdiplus::Color clBackground, CString strPicPath )
{
	//定义目标图片:代表宽度、高度,水泥槽宽度
	Gdiplus::Bitmap *img=new Gdiplus::Bitmap(nSrcWidth + nGroutX, nSrcHeight + nGroutY);
	//计算点的最大最小位置
	Gdiplus::Bitmap bmp(strPicPath);
	Gdiplus::Graphics buffer(img);//Gaphics对象引用内存画布   
	buffer.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);//SmoothingModeAntiAlias);
	buffer.ResetTransform();
	buffer.Clear(clBackground);
	{
		Gdiplus::ImageAttributes attImage;
		attImage.SetWrapMode(Gdiplus::WrapMode::WrapModeTile);

		Gdiplus::Rect rtDraw(nGroutX/2, nGroutY/2, nSrcWidth, nSrcHeight);
		//图片原始尺寸在bmp内,画到 x,y点, 需要原始图片的位置是 srcX, srcY, 目标图形区域大小是 srcWidth, srcHeight
		buffer.DrawImage(&bmp, rtDraw, 0, 0, bmp.GetWidth(), bmp.GetHeight(), Gdiplus::Unit::UnitPixel, &attImage);
	}

	return img;
}
Exemplo n.º 11
0
BOOL CDuiImgX::StretchBlt(HDC hdc,int x,int y,int nWid,int nHei,int xSrc,int ySrc,int nWidSrc,int nHeiSrc,BYTE byAlpha/*=0xFF*/)
{
    if(IsEmpty()) return FALSE;
    Gdiplus::Graphics graphics(hdc);
	Gdiplus::ImageAttributes ImgAtt;
	ImgAtt.SetWrapMode(Gdiplus::WrapModeTileFlipXY);
    if(byAlpha!=0xFF)
    {
        Gdiplus::ColorMatrix ClrMatrix =
        {
            1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
            0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
            0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
            0.0f, 0.0f, 0.0f, float(byAlpha)/0xFF, 0.0f,
            0.0f, 0.0f, 0.0f, 0.0f, 1.0f
        };
        ImgAtt.SetColorMatrix(&ClrMatrix);
    }

    return S_OK==graphics.DrawImage(m_pImg,Gdiplus::Rect(x,y,nWid,nHei),xSrc,ySrc,nWidSrc,nHeiSrc,Gdiplus::UnitPixel,&ImgAtt);
}
Exemplo n.º 12
0
    void CanvasGdiplus::TileImageInt(const Bitmap& bitmap,
        int src_x, int src_y, int dest_x, int dest_y, int w, int h)
    {
        if(!IntersectsClipRectInt(dest_x, dest_y, w, h))
        {
            return;
        }

        Gdiplus::Graphics* current = GetCurrentGraphics();
        if(!bitmap.IsNull())
        {
            Gdiplus::Bitmap* native_bitmap = bitmap.GetNativeBitmap();
            Gdiplus::ImageAttributes ia;
            ia.SetWrapMode(Gdiplus::WrapModeTile);
            Gdiplus::Rect rc_dest(dest_x, dest_y, w, h);
            current->DrawImage(native_bitmap,
                rc_dest, src_x, src_y,
                native_bitmap->GetWidth()-src_x,
                native_bitmap->GetHeight()-src_y,
                Gdiplus::UnitPixel, &ia);
        }
    }
Exemplo n.º 13
0
// *************************************************************
//		SetTransparency()
// *************************************************************
void ImageHelper::SetTransparency(Gdiplus::ImageAttributes& attributes, bool useTransparency, OLE_COLOR clr1, OLE_COLOR clr2)
{
	// setting range of colors which will be transparent
	if (useTransparency)
	{
		Gdiplus::Color color1(MIN(GetRValue(clr1), GetRValue(clr2)),
			MIN(GetGValue(clr1), GetGValue(clr2)),
			MIN(GetBValue(clr1), GetBValue(clr2)));

		Gdiplus::Color color2(MAX(GetRValue(clr1), GetRValue(clr2)),
			MAX(GetGValue(clr1), GetGValue(clr2)),
			MAX(GetBValue(clr1), GetBValue(clr2)));

		attributes.SetColorKey(color1, color2);
	}
}
Exemplo n.º 14
0
//-----------------------------------------------------------------------------
void GdiplusDrawContext::drawBitmap (CBitmap* cbitmap, const CRect& dest, const CPoint& offset, float alpha)
{
	alpha *= currentState.globalAlpha;
	if (alpha == 0.f || pGraphics == 0)
		return;
	IPlatformBitmap* platformBitmap = cbitmap ? cbitmap->getPlatformBitmap () : 0;
	GdiplusBitmap* gpb = platformBitmap ? dynamic_cast<GdiplusBitmap*> (platformBitmap) : 0;
	Gdiplus::Bitmap* bitmap = gpb ? gpb->getBitmap () : 0;
	if (bitmap)
	{
		GdiplusDrawScope drawScope (pGraphics, currentState.clipRect, getCurrentTransform ());

		Gdiplus::ImageAttributes imageAtt;
		if (alpha != 1.f)
		{
			// introducing the alpha blend matrix
			Gdiplus::ColorMatrix colorMatrix =
			{
				1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
				0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
				0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
				0.0f, 0.0f, 0.0f, alpha, 0.0f,
				0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
			};
			// create the imageattribute modifier
			imageAtt.SetColorMatrix (&colorMatrix, Gdiplus::ColorMatrixFlagsDefault,
				Gdiplus::ColorAdjustTypeBitmap);
#if 1
			Gdiplus::Rect	myDestRect(
				(INT)dest.left,
				(INT)dest.top,
				(INT)dest.getWidth (),
				(INT)dest.getHeight ());
			pGraphics->DrawImage (
				bitmap,
				myDestRect,
				(INT)offset.x,
				(INT)offset.y,
				(INT)dest.getWidth (),
				(INT)dest.getHeight (),
				Gdiplus::UnitPixel,
				&imageAtt);
#else
			// create a temporary bitmap to prevent OutOfMemory errors
			Gdiplus::Bitmap myBitmapBuffer ((INT)dest.getWidth (), (INT)dest.getHeight (),PixelFormat32bppARGB);
			// create a graphics context for the temporary bitmap
			Gdiplus::Graphics* myGraphicsBuffer = Gdiplus::Graphics::FromImage (&myBitmapBuffer);
			// copy the rectangle we want to paint to the temporary bitmap
			Gdiplus::Rect myTransRect(
				0,
				0,
				(INT)dest.getWidth (),
				(INT)dest.getHeight ());
			// transfer the bitmap (without modification by imageattr!)
			myGraphicsBuffer->DrawImage (
				bitmap,myTransRect,
				(INT)offset.x,
				(INT)offset.y,
				(INT)dest.getWidth (),
				(INT)dest.getHeight (),
				Gdiplus::UnitPixel,
				0);
			// now transfer the temporary to the real context at the advised location
			Gdiplus::Rect myDestRect (
				(INT)dest.left,
				(INT)dest.top,
				(INT)dest.getWidth (),
				(INT)dest.getHeight ());
			// transfer from temporary bitmap to real context (with imageattr)
			pGraphics->DrawImage (
				&myBitmapBuffer,
				myDestRect,
				(INT)0,
				(INT)0,
				(INT)dest.getWidth (),
				(INT)dest.getHeight (),
				Gdiplus::UnitPixel,
				&imageAtt);
			// delete the temporary context of the temporary bitmap
			delete myGraphicsBuffer;
#endif
		}
		else
		{
			Gdiplus::Rect	myDestRect(
				(INT)dest.left,
				(INT)dest.top,
				(INT)dest.getWidth (),
				(INT)dest.getHeight ());
			pGraphics->DrawImage (
				bitmap,
				myDestRect,
				(INT)offset.x,
				(INT)offset.y,
				(INT)dest.getWidth (),
				(INT)dest.getHeight (),
				Gdiplus::UnitPixel,
				0);
		}
	}
}
Exemplo n.º 15
0
HRESULT CImageImpl::Render(HDC hDC, LPCRECT pDstRect, LPCRECT pSrcRect, LPCRECT pBoundRect)
{
    USE_CLASS_DATA(CLASS_DATA_MEMBER_LIST);

    UNREFERENCED_PARAMETER(pSrcRect);
    UNREFERENCED_PARAMETER(pBoundRect);

    if (m_pImage == NULL)
        return S_FALSE;

    BOOL bGray = m_pImage->IsGrayScale();
    UINT uFrames = 0;
    if (S_OK == GetNumFrames(&uFrames) && uFrames > 1) 
    {
        if (bGray)
        {
            //填充白色
            HBRUSH hBrush = ::CreateSolidBrush(RGB(255, 255, 255));
            ::FillRect(hDC, pDstRect, hBrush);
            ::DeleteObject(hBrush);

            try
            {
                //去alpha矩阵,未实现
                static Gdiplus::ColorMatrix removeAlphaMatrix = 
                {
                    1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
                    0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
                    0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
                    0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
                    0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
                };

                //去色矩阵
                static Gdiplus::ColorMatrix grayMatrix = 
                {
                    0.3f, 0.3f, 0.3f, 0.0f, 0.0f,
                    0.59f, 0.59f, 0.59f, 0.0f, 0.0f,
                    0.11f, 0.11f, 0.11f, 0.0f, 0.0f,
                    0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
                    0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
                };

                //选择第一帧
                GUID guidGif = Gdiplus::FrameDimensionTime;
                m_pBitmap->SelectActiveFrame(&guidGif, 0);

                CRect dstRect = *pDstRect;
                Gdiplus::Rect rcDraw(dstRect.left, dstRect.top, (dstRect.right - dstRect.left), (dstRect.bottom - dstRect.top));
                Gdiplus::Graphics graphics(hDC);
                Gdiplus::ImageAttributes *pImageAttributes = new Gdiplus::ImageAttributes();
                pImageAttributes->SetColorMatrix(&grayMatrix);
                Gdiplus::Status ret = graphics.DrawImage(m_pBitmap, 
                    rcDraw, 
                    0, 0, m_pBitmap->GetWidth(), m_pBitmap->GetHeight(), 
                    Gdiplus::UnitPixel, pImageAttributes);
                delete pImageAttributes;

                if (ret == Gdiplus::Ok)
                    return S_OK;
            }
            catch (...)
            {
            }
        } 
        else 
        {
            //填充白色
            ::FillRect(hDC, pDstRect, (HBRUSH)::GetStockObject(WHITE_BRUSH));

            if (S_OK == RenderFrame(hDC, 0, pDstRect))
                return S_OK;
        }

    }

    if (! m_pImage->AlphaIsValid()) 
    {
        if (! m_pImage->Stretch(hDC, *pDstRect))
            return S_FALSE;
    }
    else 
    {
        if (! m_pImage->Draw(hDC, *pDstRect))
            return S_FALSE;
    }

    return S_OK;
}
Exemplo n.º 16
0
void CListViewNode::OnPaint(Gdiplus::Graphics* graphics, INT xPos, INT yPos, INT cBottom, INT cRight)
{
	if ( !m_listView )
		return;

	RECT iconRect; ::CopyRect(&iconRect, &m_iconRect); ::OffsetRect(&iconRect, -xPos, -yPos);
	RECT textRect; ::CopyRect(&textRect, &m_textRect); ::OffsetRect(&textRect, -xPos, -yPos);
	RECT borderRect; ::CopyRect(&borderRect, &m_borderRect); borderRect.right = borderRect.left + cRight; ::OffsetRect(&borderRect, 0, -yPos);
	
	if ( iconRect.bottom < 0 )
		return;
	if ( iconRect.top >= cBottom )
		return;

	Gdiplus::Font* pFont = NULL;
	Gdiplus::Brush* pBrushBackground = NULL;
	Gdiplus::Brush* pBrushForeground = NULL;

	if ( m_selected )
	{
		pFont = m_listView->get_Font(_T(".Font.Selected"), _T("ListView"));
		pBrushBackground = m_listView->get_Brush(_T(".BackgroundColor.Selected"), _T("ListView"), Gdiplus::Color::Blue);
		pBrushForeground = m_listView->get_Brush(_T(".ForegroundColor.Selected"), _T("ListView"), Gdiplus::Color::White);
	}
	else
	{
		pFont = m_listView->get_Font(_T(".Font.Normal"), _T("ListView"));
		pBrushBackground = m_listView->get_Brush(_T(".BackgroundColor.Normal"), _T("ListView"), Gdiplus::Color::White);
		pBrushForeground = m_listView->get_Brush(_T(".ForegroundColor.Normal"), _T("ListView"), Gdiplus::Color::Black);
	}

	Gdiplus::RectF iconRectF; Convert2RectF(&iconRectF, &iconRect);
	Gdiplus::RectF textRectF; Convert2RectF(&textRectF, &textRect);
	Gdiplus::RectF borderRectF; Convert2RectF(&borderRectF, &borderRect);
	Gdiplus::PointF pt; pt.X = textRectF.X; pt.Y = textRectF.Y;

	graphics->FillRectangle(pBrushBackground, borderRectF);

	Gdiplus::Bitmap* image = NULL;
	UINT 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();
	if ( hImage > 0 )
	{
		Gdiplus::Color transparentcolor;
		Gdiplus::ImageAttributes imAtt;

		image->GetPixel(0, hImage - 1, &transparentcolor);
		imAtt.SetColorKey(transparentcolor, transparentcolor, Gdiplus::ColorAdjustTypeBitmap);

		graphics->DrawImage(image, iconRectF, 0.0, 0.0, Cast(Gdiplus::REAL,hImage), Cast(Gdiplus::REAL,hImage), Gdiplus::UnitPixel, &imAtt);
	}
	if ( !(m_text.IsEmpty()) )
		graphics->DrawString(m_text.GetString(), m_textDisplayLength, pFont, pt, Gdiplus::StringFormat::GenericTypographic(), pBrushForeground);
	if ( m_focused )
	{
		Gdiplus::Pen grayPen(Gdiplus::Color::Gray);
		grayPen.SetDashStyle(Gdiplus::DashStyleDot);

		graphics->DrawRectangle(&grayPen, textRectF);
	}
}
Exemplo n.º 17
0
HBITMAP g_load_png_gdiplus_throw(HDC dc, const char * fn, unsigned target_cx, unsigned target_cy)
{
	//FIXME m_gdiplus_initialised = (Gdiplus::Ok == Gdiplus::GdiplusStartup(&m_gdiplus_instance, &Gdiplus::GdiplusStartupInput(), NULL));
	pfc::string8 canPath;
	HBITMAP bm = 0;

	abort_callback_dummy p_abort;
	file::ptr p_file;
	filesystem::g_get_canonical_path(fn, canPath);
	filesystem::g_open_read(p_file, canPath, p_abort);
	t_size fsize = pfc::downcast_guarded<t_size>(p_file->get_size_ex(p_abort));
	pfc::array_staticsize_t<t_uint8> buffer(fsize);
	p_file->read(buffer.get_ptr(), fsize, p_abort);
	p_file.release();

	IStream *pStream = NULL;
	HGLOBAL gd = GlobalAlloc(GMEM_FIXED | GMEM_MOVEABLE, buffer.get_size());
	if (gd == NULL)
		throw exception_win32(GetLastError());
	void * p_data = GlobalLock(gd);
	if (p_data == NULL)
	{
		GlobalFree(gd);
		throw exception_win32(GetLastError());
	}

	memcpy(p_data, buffer.get_ptr(), buffer.get_size());
	GlobalUnlock(gd);

	HRESULT hr = CreateStreamOnHGlobal(gd, TRUE, &pStream);
	if (FAILED(hr))
	{
		GlobalFree(gd);
		throw exception_win32(hr);
	}

	Gdiplus::Bitmap pImage(pStream);

	CheckGdiplusStatus() << pImage.GetLastStatus();
	{
		Gdiplus::BitmapData bitmapData;
		//Gdiplus::Bitmap * ppImage = &pImage;
		if (target_cx != pfc_infinite || target_cy != pfc_infinite)
		{
			Gdiplus::Bitmap pBitmapResized(target_cx == pfc_infinite ? pImage.GetWidth() : target_cx, target_cy == pfc_infinite ? pImage.GetHeight() : target_cy, PixelFormat32bppARGB);
			CheckGdiplusStatus() << pBitmapResized.GetLastStatus();
			Gdiplus::Graphics pGraphics(&pBitmapResized);
			CheckGdiplusStatus() << pGraphics.GetLastStatus();
			CheckGdiplusStatus() << pGraphics.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHighQuality);
			CheckGdiplusStatus() << pGraphics.SetInterpolationMode(Gdiplus::InterpolationModeBicubic);
			Gdiplus::ImageAttributes imageAttributes;
			CheckGdiplusStatus() << imageAttributes.SetWrapMode(Gdiplus::WrapModeTileFlipXY);
			CheckGdiplusStatus() << pGraphics.DrawImage(&pImage, Gdiplus::Rect(0, 0, pBitmapResized.GetWidth(), pBitmapResized.GetHeight()), 0, 0, pImage.GetWidth(), pImage.GetHeight(), Gdiplus::UnitPixel, &imageAttributes);

			CheckGdiplusStatus() << pBitmapResized.LockBits(&Gdiplus::Rect(0, 0, pBitmapResized.GetWidth(), pBitmapResized.GetHeight()), Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, &bitmapData);
			bm = g_CreateHbitmapFromGdiplusBitmapData32bpp(bitmapData);
			CheckGdiplusStatus() << pBitmapResized.UnlockBits(&bitmapData);
		}
		else
		{
			CheckGdiplusStatus() << pImage.LockBits(&Gdiplus::Rect(0, 0, pImage.GetWidth(), pImage.GetHeight()), Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, &bitmapData);
			//assert bitmapData.Stride == bitmapData.Width
			bm = g_CreateHbitmapFromGdiplusBitmapData32bpp(bitmapData);
			CheckGdiplusStatus() << pImage.UnlockBits(&bitmapData);
		}
	}
	return bm;

}
Exemplo n.º 18
0
	HBITMAP g_create_hbitmap_from_image(Gdiplus::Bitmap & bm, t_size & cx, t_size & cy, COLORREF cr_back, bool b_reflection)
	{
		HDC dc=NULL, dcc=NULL;
		dc = GetDC(NULL);
		dcc = CreateCompatibleDC(dc);
		//cy = bm.GetHeight();
		if (b_reflection)
			cy = cx;//(cy*11 -7) / 14;
		t_size ocx=cx,ocy=cy;

		t_size cx_source = bm.GetWidth(), cy_source = bm.GetHeight();


		double ar_source = (double)cx_source / (double)cy_source;
		double ar_dest = (double)ocx / (double)ocy;
		//unsigned cx = RECT_CX(rc), cy = RECT_CY(rc);

		if (ar_dest < ar_source)
			cy = (unsigned)floor((double)ocx / ar_source);
		else if (ar_dest > ar_source)
			cx = (unsigned)floor((double)ocy * ar_source);

		//cy = (unsigned)floor((double)ocx / ar_source);
		if ( (ocx - cx) % 2) cx++;

		t_size reflect_cy = b_reflection ? (cy*3)/11 : 0;
		HBITMAP bitmap = CreateCompatibleBitmap(dc, cx, cy + reflect_cy);
		HBITMAP bm_old = SelectBitmap(dcc, bitmap);

		unsigned err = 0;
		Gdiplus::Graphics graphics(dcc);
		err = graphics.GetLastStatus();
		graphics.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHighQuality);
		graphics.SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic);

		Gdiplus::SolidBrush br(Gdiplus::Color(LOBYTE(LOWORD(cr_back)),HIBYTE(LOWORD(cr_back)),LOBYTE(HIWORD(cr_back)) ));
		graphics.FillRectangle(&br, 0, 0, cx, cy + reflect_cy);

		//if (cx_source>=2 && cy_source>=2)
		{
			{
#if 1
				Gdiplus::ImageAttributes imageAttributes;
				imageAttributes.SetWrapMode(Gdiplus::WrapModeTileFlipXY);
				Gdiplus::Rect destRect(0, 0, cx, cy);
				graphics.DrawImage(&bm, destRect, 0, 0, cx_source, cy_source, Gdiplus::UnitPixel, &imageAttributes);
#else
				if (cx_source == cx && cy_source == cy)
				{
					Gdiplus::Rect destRect(0, 0, cx, cy);
					graphics.SetInterpolationMode(Gdiplus::InterpolationModeNearestNeighbor);
					graphics.DrawImage(&bm, destRect, 0, 0, cx_source, cy_source, Gdiplus::UnitPixel);
					graphics.SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic);
				}
				else
				{
					Gdiplus::Rect destRect(-1, -1, cx+2, cy+2);
					//Gdiplus::Rect destRect(0, 0, cx, cy);
					graphics.DrawImage(&bm, destRect, 0, 0, cx_source, cy_source, Gdiplus::UnitPixel);
				}
#endif
			}

			{
				Gdiplus::Bitmap scaled(bitmap, NULL);
				t_size i;
				if (reflect_cy)
				{

					Gdiplus::Rect rectref(0, cy, cx, reflect_cy);
					Gdiplus::Color cr_end(255,LOBYTE(LOWORD(cr_back)),HIBYTE(LOWORD(cr_back)),LOBYTE(HIWORD(cr_back)));
					Gdiplus::Color cr_start(148,LOBYTE(LOWORD(cr_back)),HIBYTE(LOWORD(cr_back)),LOBYTE(HIWORD(cr_back)));
					//Gdiplus::Color cr_middle(100,255,255,255);
					Gdiplus::Rect destRect(0, cy, cx, reflect_cy);
					graphics.DrawImage(&scaled, destRect, 0, cy, cx, 0-reflect_cy, Gdiplus::UnitPixel);
					Gdiplus::LinearGradientBrush lgb(rectref, cr_start, cr_end, Gdiplus::LinearGradientModeVertical);
					graphics.FillRectangle(&lgb, rectref);
					//graphics.FillRectangle(&Gdiplus::SolidBrush(cr_middle), rectref);
					/*for (i=0; i<reflect_cy; i++)
					{
						Gdiplus::ImageAttributes attrib;
						Gdiplus::ColorMatrix mtrx = {0};
						mtrx.m[0][0] = 1;
						mtrx.m[1][1] = 1;
						mtrx.m[2][2] = 1;
						mtrx.m[3][3] = float(0.42) - (float(0.42)*(float(i)/float(reflect_cy)));
						mtrx.m[4][4] = 1;

						attrib.SetColorMatrix (&mtrx, Gdiplus::ColorMatrixFlagsDefault, Gdiplus::ColorAdjustTypeDefault);
						//Gdiplus::Rect sourceRect(0, cy-1-i, cx, cy-i);
						Gdiplus::Rect destRect(0, cy+i, cx, 1);
						graphics.DrawImage(&scaled, destRect, 0, cy-i-1, cx, 1, Gdiplus::UnitPixel, &attrib);
					}*/
				}
			}
			err = graphics.GetLastStatus();
		}
		//m_bitmap = pfc::rcnew_t<Gdiplus::CachedBitmap>(&bm, &_graphics);
		//err = m_bitmap->GetLastStatus();

		SelectBitmap(dcc, bm_old);

		DeleteDC(dcc);
		ReleaseDC(NULL, dc);

		return bitmap;
	}
Exemplo n.º 19
0
BOOL CBSObject::DrawPNG(HDC hDC, const RECT &rectDst, const RECT* prectImagePortion, UINT Res, HINSTANCE hInst)
{
	BOOL bRet = FALSE;

    Gdiplus::Graphics graphics(hDC);

	HRSRC  hResource = ::FindResource(hInst,  MAKEINTRESOURCE(Res),  TEXT("PNG"));  
	if  (hResource > 0)
    {
	    DWORD  imageSize = ::SizeofResource(hInst, hResource);  
	    if  (imageSize > 0)
        {
            HGLOBAL hHandle = ::LoadResource(hInst,hResource);
            if (NULL != hHandle)
            {
                void* pResourceData = ::LockResource(hHandle);

                if  (pResourceData != NULL)  
                {
                    HGLOBAL hBuffer;
                    hBuffer = ::GlobalAlloc(GMEM_MOVEABLE, imageSize);  
                    if  (hBuffer)  
                    {  
                        void* pBuffer = ::GlobalLock(hBuffer);  
                        if  (pBuffer)  
                        {  
                            memcpy_s(pBuffer, imageSize, pResourceData, imageSize); //For stm0117
                            IStream*  pStream = NULL;  
                            if  (::CreateStreamOnHGlobal(hBuffer,  FALSE,  &pStream) == S_OK)  
                            {  
                                Gdiplus::Image cImage(pStream);
                                Gdiplus::RectF cRectF(static_cast<Gdiplus::REAL>(rectDst.left), 
                                    static_cast<Gdiplus::REAL>(rectDst.top), 
                                    static_cast<Gdiplus::REAL>(rectDst.right - rectDst.left), 
                                    static_cast<Gdiplus::REAL>(rectDst.bottom - rectDst.top));
                                Gdiplus::ImageAttributes clImgAtt;
								clImgAtt.SetWrapMode(Gdiplus::WrapModeTileFlipXY);
								if (NULL == prectImagePortion)
								{
									graphics.DrawImage(&cImage, 
                                        cRectF, 
                                        static_cast<Gdiplus::REAL>(0), 
                                        static_cast<Gdiplus::REAL>(0),
                                        static_cast<Gdiplus::REAL>(cImage.GetWidth()), 
                                        static_cast<Gdiplus::REAL>(cImage.GetHeight()),
										Gdiplus::UnitPixel, 
                                        &clImgAtt); //
								}
								else
                                {
									graphics.DrawImage(&cImage, 
                                        cRectF, 
                                        static_cast<Gdiplus::REAL>(prectImagePortion->left), 
										static_cast<Gdiplus::REAL>(prectImagePortion->top), 
										static_cast<Gdiplus::REAL>(prectImagePortion->right - prectImagePortion->left), 
										static_cast<Gdiplus::REAL>(prectImagePortion->bottom - prectImagePortion->top), 
										Gdiplus::Unit::UnitPixel, 
										NULL, 
										NULL, 
										NULL);
								}

                                pStream->Release();  
                                bRet = TRUE;
                            }  
                            ::GlobalUnlock(hBuffer);  
                        }  
                        ::GlobalFree(hBuffer);  
                        hBuffer  =  NULL;  
                    }
                }
            }
        }
    }

	return bRet;
}