⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graview.cpp

📁 VC.net 的一些有用的技巧
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	path.AddLines(points,10);
	// 创建路径梯度画刷
	PathGradientBrush pthGrBrush(&path);
	// 设定路径中心颜色为红色
	pthGrBrush.SetCenterColor(Color(255, 255, 0, 0));
	// 顶点颜色数组
	Color colors[] = {
		Color(255, 0, 0, 0),
		Color(255, 0, 255, 0),
		Color(255, 0, 0, 255),
		Color(255, 255, 255, 255),
		Color(255, 0, 0, 0),
		Color(255, 0, 255, 0),
		Color(255, 0, 0, 255),
		Color(255, 255, 255, 255),
		Color(255, 0, 0, 0),
		Color(255, 0, 255, 0)};
		INT count = 10;
		pthGrBrush.SetSurroundColors(colors,&count);
		// 填充路径
		myGraphics.FillPath(&pthGrBrush, &path);*/

	
	// 设置中心点
	// 创建单个椭圆路径
	/*GraphicsPath path;
	path.AddEllipse(0, 0, 140, 70);
	// 创建基于椭圆路径的梯度画刷
	PathGradientBrush pthGrBrush(&path);
	// 设定中心点位置
	pthGrBrush.SetCenterPoint(PointF(120, 40));
	// 设定中心点颜色为蓝色
	pthGrBrush.SetCenterColor(Color(255, 0, 0, 255));
	// 设定边界颜色为浅绿色
	Color colors(Color(255, 0, 255, 255));
	INT count = 1;
	pthGrBrush.SetSurroundColors(&colors, &count);
	myGraphics.FillEllipse(&pthGrBrush, 0, 0, 140, 70);*/


	//将Gamma校正应用于梯度
	/*LinearGradientBrush linGrBrush(
		Point(0, 10),
		Point(200, 10),
		Color::Red,
		Color::Blue);
	myGraphics.FillRectangle(&linGrBrush, 0, 0, 200, 50);
	linGrBrush.SetGammaCorrection(true);
	myGraphics.FillRectangle(&linGrBrush, 0, 60, 200, 50);*/

	// 创建包含单一图形的轨迹
	/*GraphicsPath path;
	path.AddArc(175, 50, 50, 50, 0, -180);
	myGraphics.DrawPath(&Pen(Color(128, 255, 0, 0), 4), &path);*/
	
	// 创建包含两个图形的轨迹
	// 第二个图形的顶点数组
	/*Point points[] = {
			Point(40, 60),
			Point(50, 70),
			Point(30, 90)};
	GraphicsPath path;
	path.StartFigure(); // 开始第一个图形.
	path.AddArc(175, 50, 50, 50, 0, -180);
	path.AddLine(100, 0, 250, 20);
	path.StartFigure(); // 开始第二个图形
	path.AddLine(50, 20, 5, 90);
	path.AddCurve(points, 3);
	path.AddLine(50, 150, 150, 180);
	path.CloseFigure(); // 关闭第二个图形
	myGraphics.DrawPath(&Pen(Color(255, 255, 0, 0), 2), &path);*/

	// 填充轨迹
	/*GraphicsPath path;
	// 添加一个开放的图形
	path.AddArc(0, 0, 150, 120, 30, 120);
	// 添加一个封闭的图形.
	path.AddEllipse(50, 50, 50, 100);
	Pen pen(Color(128, 0, 0, 255), 5);
	SolidBrush brush(Color::Red);
	//按照默认的填充模式FillModeAlternate填充轨迹
	myGraphics.FillPath(&brush, &path);
	myGraphics.DrawPath(&pen, &path);*/


//重新着色
//使用颜色矩阵
/*Image image(L"InputColor.bmp");
ImageAttributes imageAttributes;
UINT width = image.GetWidth();
UINT height = image.GetHeight();

REAL colorMatrixElements[5][5]={ 
	2,  0,  0,  0, 0,        // red scaling factor of 2
	0,  1,  0,  0, 0,        // green scaling factor of 1
	0,  0,  1,  0, 0,        // blue scaling factor of 1
	0,  0,  0,  1, 0,        // alpha scaling factor of 1
	.2f, .2f, .2f, 0, 1};    // three translations of 0.2

ColorMatrix colorMatrix;
RtlMoveMemory((void*)colorMatrix.m, (void*)colorMatrixElements, sizeof(colorMatrixElements));

imageAttributes.SetColorMatrix(
   &colorMatrix, 
   ColorMatrixFlagsDefault,
   ColorAdjustTypeBitmap);

myGraphics.DrawImage(&image, 10, 10);

myGraphics.DrawImage(
   &image,
   Rect(120, 10, width, height),  // destination rectangle 
   0, 0,        // upper-left corner of source rectangle 
   width,       // width of source rectangle
   height,      // height of source rectangle
   UnitPixel,
   &imageAttributes);*/

//使用颜色再变换表
/*Image image(L"RemapInput.bmp");
ImageAttributes  imageAttributes;
UINT width = image.GetWidth();
UINT height = image.GetHeight();
ColorMap colorMap;

colorMap.oldColor = Color(255, 255, 0, 0);  // opaque red
colorMap.newColor = Color(255, 0, 0, 255);  // opaque blue

imageAttributes.SetRemapTable(1,&colorMap,ColorAdjustTypeBitmap);

myGraphics.DrawImage(&image, 10, 10, width, height);

myGraphics.DrawImage(
   &image, 
   Rect(150, 10, width, height),  // destination rectangle 
   0, 0,        // upper-left corner of source rectangle 
   width,       // width of source rectangle
   height,      // height of source rectangle
   UnitPixel,
   &imageAttributes);*/

	//图形容器
	/*myGraphics.TranslateTransform(200, 0);
    GraphicsContainer myGraphicsContainer;
	myGraphicsContainer = myGraphics.BeginContainer();
	myGraphics.TranslateTransform(0, 100);
	myGraphics.DrawRectangle(&myPen, 0, 0, 50, 50);
	myGraphics.EndContainer(myGraphicsContainer);
	myGraphics.DrawRectangle(&myPen, 0, 0, 50, 50);*/

	//嵌套容器中的变换
	/*GraphicsContainer myGraphicsContainer;
	SolidBrush solidBrush(Color::Black);
	myGraphics.FillRectangle(&solidBrush, 100, 80, 3, 3);
	myGraphics.TranslateTransform(100, 80);
	myGraphicsContainer = myGraphics.BeginContainer();
	myGraphics.RotateTransform(30);
	myGraphics.DrawRectangle(&myPen, -60, -30, 120, 60);
	myGraphics.EndContainer(myGraphicsContainer);
	myGraphics.DrawRectangle(&myPen, -60, -30, 120, 60);*/

	//在嵌套容器中剪辑
	GraphicsContainer myGraphicsContainer;
	Pen redPen(Color::Red, 2);
	Pen bluePen(Color::Blue, 2);
	SolidBrush aquaBrush(Color(255, 180, 255, 255));
	SolidBrush greenBrush(Color(255, 150, 250, 130));
	myGraphics.SetClip(Rect(50, 65, 150, 120));
	myGraphics.FillRectangle(&aquaBrush, 50, 65, 150, 120);
	myGraphicsContainer = myGraphics.BeginContainer();
	// 创建由单个椭圆构成的路径
	GraphicsPath path;
	path.AddEllipse(75, 50, 100, 150);
	// 基于路径创建区域
	Region region(&path);
	myGraphics.FillRegion(&greenBrush, &region);
	myGraphics.SetClip(&region, CombineModeReplace);
	myGraphics.DrawLine(&redPen, 50, 0, 350, 300);
	myGraphics.EndContainer(myGraphicsContainer);
	myGraphics.DrawLine(&bluePen, 70, 0, 370, 300);



	//区域
	//在一个区域点击检测
	//假设最近的鼠标单击位置保存在point中
	//point值为(60, 10)时,光标位于区域中
	//point值为(0, 0)时,光标不在区域中
	/*Point point(60, 10);	
	SolidBrush solidBrush(Color::Black);
	Region region1(Rect(50, 0, 50, 150));
	Region region2(Rect(0, 50, 150, 50));
	//创建两个区域的并集
	region1.Union(&region2);
	if(region1.IsVisible(point, &myGraphics))
	{
		//如果点在该区域中,使用不透明画刷
		solidBrush.SetColor(Color(255, 255, 0, 0));
	}
	else
	{
		//如果点不在该区域中,使用半透明画刷
		solidBrush.SetColor(Color(64, 255, 0, 0));
	}
	myGraphics.FillRegion(&solidBrush, &region1);*/

	
	//在一个区域中剪辑
	//创建一个多边形路径
	/*Point polyPoints[] = {
			Point(10, 10),
			Point(150, 10),
			Point(100, 75),
			Point(100, 150)};
	GraphicsPath path;
	path.AddPolygon(polyPoints,4);
	//基于路径创建区域
	Region region(&path);
	//绘制区域轮廓
	Pen pen(Color::Black);
	myGraphics.DrawPath(&pen, &path);
	//设置图形对象的剪辑区域
	myGraphics.SetClip(&region, CombineModeReplace);
	//绘制被剪辑的字符串.
	FontFamily fontFamily(L"宋体");
	Font font(
		&fontFamily,
		36,
		FontStyleBold,
		UnitPixel);
	SolidBrush solidBrush(Color(255, 255, 0, 0));
	myGraphics.DrawString(
		L"在一个区域中剪辑",
		-1,
		&font,
		PointF(15, 25),
		&solidBrush);
	myGraphics.DrawString(
		L"在一个区域中剪辑",
		-1,
		&font,
		PointF(15, 68),
		&solidBrush);*/
}


// CgraView 诊断

#ifdef _DEBUG
void CgraView::AssertValid() const
{
	CView::AssertValid();
}

void CgraView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CgraDoc* CgraView::GetDocument() const // 非调试版本是内联的
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CgraDoc)));
	return (CgraDoc*)m_pDocument;
}
#endif //_DEBUG


// CgraView 消息处理程序

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -