示例#1
0
    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()));
    }
示例#2
0
void IrisBitmap::IrisDrawText(const IrisFont* fontIris, int x, int y, int width, int height, wstring str, int align){
	this->needRefreshTexture = true;

	if (x > this->width || y > this->height || x < 0 || y < 0)
		return;

	//this->needRefreshTexture = true;

	int size = IrisFont::defaultSize;
	IrisColor *color;
	wstring name;
	bool bold, shadow, italic;

	if(fontIris == NULL){
		name = IrisFont::defaultName;
		bold = IrisFont::defaultBold;
		shadow = IrisFont::defaultShadow;
		italic = IrisFont::defaultItalic;
		color = IrisFont::defaultColor;
	}
	else
	{
		name = fontIris->name;
		bold = fontIris->bold;
		shadow = fontIris->shadow;
		italic = fontIris->italic;
		color = fontIris->color;
	}

	// release
	

	Gdiplus::Bitmap *tBitmap = this->bitmap->Clone(0, 0, this->bitmap->GetWidth(), this->bitmap->GetHeight(), PixelFormat32bppARGB);
	Graphics tg(tBitmap);

	Gdiplus::FontFamily fontFamily(name.c_str());
	int fs = FontStyleRegular;
	
	if(bold)
		fs |= FontStyleBold;

	if(italic)
		fs |= FontStyleItalic;

	//lfont.lfWeight = 1000;
	Gdiplus::Font font(&fontFamily, (REAL)size, fs, UnitPixel);

	StringFormat strFormat;

	switch(align){
	case 0:
		strFormat.SetAlignment(StringAlignmentNear);
		break;
	case 1:
		strFormat.SetAlignment(StringAlignmentCenter);
		break;
	}

	Brush *brush;

	if(shadow)
		brush = new HatchBrush(HatchStyle90Percent, Color(color->red, color->green, color->blue));
	else
		brush = new SolidBrush(Color(color->red, color->green, color->blue));

	strFormat.SetFormatFlags(StringFormatFlagsNoWrap);
	Gdiplus::RectF r((REAL)x, (REAL)y, (REAL)width, (REAL)height);
	tg.SetSmoothingMode(SmoothingModeAntiAlias);
	tg.SetInterpolationMode(InterpolationModeHighQualityBicubic);
	Gdiplus::GraphicsPath path;
	path.AddString(str.c_str(), str.size(), &fontFamily, FontStyleRegular, 20, r, &strFormat);
	Gdiplus::Pen pen(Color(color->red, color->green, color->blue), 2);
	tg.DrawPath(&pen, &path);
	tg.FillPath(brush, &path);

	if(this->bitmap != 0){
		delete this->bitmap;
		this->bitmap = 0;
	}

	this->bitmap = tBitmap->Clone(0, 0, tBitmap->GetWidth(), tBitmap->GetHeight(), PixelFormat32bppARGB);

	//CLSID encoderClsid;
	//ModuleIrisGraphics::GetEncoderClsid(L"image/png", &encoderClsid);
	//this->bitmap->Save(L"string.png", &encoderClsid, NULL);

	delete brush;
	delete tBitmap;
	
}
void IrisBitmap::IrisDrawText(const IIrisFont* fontIris, int x, int y, int width, int height, wstring str, int align){
	this->needRefreshTexture = true;
	Gdiplus::Bitmap *tBitmap = this->bitmap->Clone(0, 0, this->bitmap->GetWidth(), this->bitmap->GetHeight(), PixelFormat32bppARGB);

	Graphics tg(tBitmap);

	int size = IrisFont::defaultSize;
	IrisColor *color;
	wstring name;
	bool bold, shadow, italic;

	if(fontIris == NULL){
		name = IrisFont::defaultName;
		bold = IrisFont::defaultBold;
		shadow = IrisFont::defaultShadow;
		italic = IrisFont::defaultItalic;
		color = (IrisColor*)IrisFont::defaultColor;
	}
	else
	{
		name = ((IrisFont*)fontIris)->name;
		bold = ((IrisFont*)fontIris)->bold;
		shadow = ((IrisFont*)fontIris)->shadow;
		italic = ((IrisFont*)fontIris)->italic;
		color = (IrisColor*)((IrisFont*)fontIris)->color;
	}

	FontFamily fontFamily(name.c_str());
	int fs = FontStyleRegular;

	if(bold)
		fs |= FontStyleBold;

	if(italic)
		fs |= FontStyleItalic;

	Font font(&fontFamily, (REAL)size, fs, UnitWorld);

	StringFormat strFormat;

	switch(align){
	case 0:
		strFormat.SetAlignment(StringAlignmentNear);
		break;
	case 1:
		strFormat.SetAlignment(StringAlignmentCenter);
		break;
	}

	Brush *brush;

	if(shadow)
		brush = new HatchBrush(HatchStyle90Percent, Color(color->red, color->green, color->blue));
	else
		brush = new SolidBrush(Color(color->red, color->green, color->blue));

	Color keyColor;
	if(color->red == 0 || color->blue == 0 || color-> green == 0)
		keyColor = Color::MakeARGB(255, 255, 255, 255);
	else
		keyColor = Color::MakeARGB(255, color->red - 1, color->green - 1, color->blue - 1);

	Gdiplus::PointF point((REAL)x, (REAL)y);
	strFormat.SetFormatFlags(StringFormatFlagsNoWrap);
	Gdiplus::RectF r((REAL)x, (REAL)y, (REAL)width, (REAL)height);

	tg.DrawString(str.c_str(), str.length(), &font, r, &strFormat, brush);

	if(this->bitmap != 0){
		delete this->bitmap;
		this->bitmap = 0;
	}

	this->bitmap = tBitmap->Clone(0, 0, tBitmap->GetWidth(), tBitmap->GetHeight(), PixelFormat32bppARGB);

	delete brush;
	delete tBitmap;

}
示例#4
0
BOOL CPictureCtrl::Show(LPCTSTR pcszFile,UINT nDrawFlag)
{
	USES_CONVERSION;

	if (pcszFile == NULL)
	{
		if (m_nTimerId != 0)
		{
			KillTimer(m_nTimerId);
			m_nTimerId = 0;
		}

		if (m_pImage != NULL)
		{
			delete m_pImage;
			m_pImage = NULL;
			Invalidate(FALSE);
		}
			
		m_strFilePath.Empty();
		return TRUE;
	}
	else
	{
		Gdiplus::Bitmap *pSrcImage = Gdiplus::Bitmap::FromFile(T2CW(pcszFile));
		if (pSrcImage == NULL)
			return FALSE;

		if (pSrcImage->GetLastStatus() != Gdiplus::Ok)
		{
			delete pSrcImage;
			return FALSE;
		}

		Gdiplus::Bitmap *pImage = pSrcImage->Clone(0,0,pSrcImage->GetWidth(),
			pSrcImage->GetHeight(),def_gplusPixFormat);
		delete pSrcImage;
		if (pSrcImage == NULL)
			return FALSE;
		
		Show(NULL,0);
		m_nDrawFlag = nDrawFlag;
		m_pImage = pImage;

		UINT nDimCount = m_pImage->GetFrameDimensionsCount();
		
		CArray<GUID,GUID&> dimGuids;
		dimGuids.SetSize(nDimCount);
 
		m_pImage->GetFrameDimensionsList(dimGuids.GetData(), nDimCount);
		m_nFrameCount = pImage->GetFrameCount(dimGuids.GetData());
	
		if (m_nFrameCount > 1)
		{
			m_dimGuid = dimGuids[0];

			int nSize = pImage->GetPropertyItemSize(PropertyTagFrameDelay);
			m_propItem.SetSize(nSize); 

			pImage->GetPropertyItem(PropertyTagFrameDelay, nSize, 
				(Gdiplus::PropertyItem*)m_propItem.GetData());

			m_nCurFrame = 0;
			m_nTimerId = SetTimer(TIMER_ID,GetFrameDelay(),NULL);
		} 
 
		Invalidate(FALSE);
		m_dwSampleTick = GetTickCount();

		m_strFilePath = pcszFile;
		return TRUE;
	}
}