求助 Graphics 不能绘制透明效果。
求助 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; } }; }