![]() |
#2
追梦人zmrghy2022-09-03 20:07
只有本站会员才能查看附件,请 登录 只有本站会员才能查看附件,请 登录 只有本站会员才能查看附件,请 登录 终于想到了,绘制镂空效果的方法,只是太麻烦了! 大家,知不知道,在C++ CLR中有没有现成的库函数,可以直接绘制镂空效果。。。。 ![]() private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { SolidBrush^ Brush1 = gcnew SolidBrush(Color::FromArgb(0, 255, 255)); //青色 Bitmap^ MyImage = gcnew Bitmap(200, 200); Bitmap^ TempImage = gcnew Bitmap(200, 200); Graphics^ g = Graphics::FromImage(MyImage); //200x200全画面青色 g->FillRectangle(Brush1, 0, 0, 200, 200); //100x100 右下部1/4正方形 每一个像素设置为透明色 for (int i = 100; i < 200; i++) for (int j = 100; j < 200; j++) MyImage->SetPixel(i, j, Color::FromArgb(0x00000000)); //绘制镂空文字。。。。 g = Graphics::FromImage(TempImage); String^ drawString = " 二货\r\n晚上好"; System::Drawing::Font^ drawFont = gcnew System::Drawing::Font("宋体", 20); PointF drawPoint = PointF(5.0F, 5.0F); g->DrawString(drawString, drawFont, Brush1, drawPoint); for (int i = 0; i < 200; i++) for (int j = 0; j < 200; j++) if(TempImage->GetPixel(i,j) != Color::FromArgb(0x00000000)) MyImage->SetPixel(i, j, Color::FromArgb(0x00000000)); this->pictureBox1->Image =(Image^) MyImage->Clone(); delete Brush1; delete drawString; delete drawFont; delete TempImage; delete MyImage; } |
只有本站会员才能查看附件,请 登录
只有本站会员才能查看附件,请 登录
只有本站会员才能查看附件,请 登录
求助 Graphics 不能绘制透明效果。
100x100 左上部1/4正文形透明色 为什么不能像右下部一样漏出背景色。
第104 行代码,不是脱了裤子放屁吗???
镂空一个矩形的效果,用嵌套for循环来实现。
如果,需要镂空一个圆,或者不规则图形,或者镂空文字 的效果应该如何实现。。。

#pragma once
namespace ClearRectangle {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Form1 摘要
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: 在此处添加构造函数代码
//
}
protected:
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::PictureBox^ pictureBox1;
protected:
private: System::Windows::Forms::Button^ button1;
private:
/// <summary>
/// 必需的设计器变量。
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
void InitializeComponent(void)
{
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
this->button1 = (gcnew System::Windows::Forms::Button());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->BeginInit();
this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(192)), static_cast<System::Int32>(static_cast<System::Byte>(255)),
static_cast<System::Int32>(static_cast<System::Byte>(192)));
this->pictureBox1->Location = System::Drawing::Point(0, 0);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(200, 200);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
//
// button1
//
this->button1->Location = System::Drawing::Point(51, 213);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(97, 39);
this->button1->TabIndex = 1;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(200, 266);
this->Controls->Add(this->button1);
this->Controls->Add(this->pictureBox1);
this->Name = L"Form1";
this->Text = L"Form1";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->EndInit();
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
SolidBrush^ Brush1 = gcnew SolidBrush(Color::FromArgb(192, 255, 255)); //淡青色
SolidBrush^ Brush2 = gcnew SolidBrush(Color::FromArgb(0x00000000)); //透明色
Bitmap^ MyImage = gcnew Bitmap(200, 200);
Graphics^ g = Graphics::FromImage(MyImage);
//200x200全画面淡青色
g->FillRectangle(Brush1, 0, 0, 200, 200);
//100x100 左上部1/4正文形透明色
g->FillRectangle(Brush2, 0, 0, 100, 100);
//100x100 右下部1/4正方形 每一个像素设置为透明色
for (int i = 100; i < 200; i++)
for (int j = 100; j < 200; j++)
MyImage->SetPixel(i, j, Color::FromArgb(0x00000000));
this->pictureBox1->Image =(Image^) MyImage->Clone();
delete MyImage;
}
};
}
namespace ClearRectangle {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Form1 摘要
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: 在此处添加构造函数代码
//
}
protected:
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::PictureBox^ pictureBox1;
protected:
private: System::Windows::Forms::Button^ button1;
private:
/// <summary>
/// 必需的设计器变量。
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
void InitializeComponent(void)
{
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
this->button1 = (gcnew System::Windows::Forms::Button());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->BeginInit();
this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(192)), static_cast<System::Int32>(static_cast<System::Byte>(255)),
static_cast<System::Int32>(static_cast<System::Byte>(192)));
this->pictureBox1->Location = System::Drawing::Point(0, 0);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(200, 200);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
//
// button1
//
this->button1->Location = System::Drawing::Point(51, 213);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(97, 39);
this->button1->TabIndex = 1;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(200, 266);
this->Controls->Add(this->button1);
this->Controls->Add(this->pictureBox1);
this->Name = L"Form1";
this->Text = L"Form1";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->EndInit();
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
SolidBrush^ Brush1 = gcnew SolidBrush(Color::FromArgb(192, 255, 255)); //淡青色
SolidBrush^ Brush2 = gcnew SolidBrush(Color::FromArgb(0x00000000)); //透明色
Bitmap^ MyImage = gcnew Bitmap(200, 200);
Graphics^ g = Graphics::FromImage(MyImage);
//200x200全画面淡青色
g->FillRectangle(Brush1, 0, 0, 200, 200);
//100x100 左上部1/4正文形透明色
g->FillRectangle(Brush2, 0, 0, 100, 100);
//100x100 右下部1/4正方形 每一个像素设置为透明色
for (int i = 100; i < 200; i++)
for (int j = 100; j < 200; j++)
MyImage->SetPixel(i, j, Color::FromArgb(0x00000000));
this->pictureBox1->Image =(Image^) MyImage->Clone();
delete MyImage;
}
};
}