Re: Q: Why is my BitBlt destination always blank?
- From: cranke_boy <crankeboy@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 26 Mar 2008 12:06:00 -0700
Here is a test form that I think should work (but doesn't). After pressing
the test button, the dest bitmap is written to the file system. When I load
it the image afterwards, it is blank gray instead of a copy of the src bitmap.
I wanted to show that this problem would happen even outside of my main
development project. Is it possibly my Visual Studio / project configuration?
#pragma once
namespace test2 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
[System::Runtime::InteropServices::DllImportAttribute("gdi32.dll")]
extern bool BitBlt(IntPtr hDestDC,
int x,
int y,
int nWidth,
int nHeight,
IntPtr hSrcDC,
int xSrc,
int ySrc,
int dwRop);
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change
the
/// 'Resource File Name' property for the managed resource
compiler tool
/// associated with all .resx files this class depends on.
Otherwise,
/// the designers will not be able to interact properly with
localized
/// resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ btnTemp;
protected:
protected:
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->btnTemp = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// btnTemp
//
this->btnTemp->Location = System::Drawing::Point(12, 12);
this->btnTemp->Name = L"btnTemp";
this->btnTemp->Size = System::Drawing::Size(187, 38);
this->btnTemp->TabIndex = 0;
this->btnTemp->Text = L"button1";
this->btnTemp->UseVisualStyleBackColor = true;
this->btnTemp->Click += gcnew System::EventHandler(this,
&Form1::btnTemp_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(648, 479);
this->Controls->Add(this->btnTemp);
this->Location = System::Drawing::Point(500, 500);
this->Name = L"Form1";
this->StartPosition = System::Windows::Forms::FormStartPosition::Manual;
this->Text = L"Form1";
this->Paint += gcnew System::Windows::Forms::PaintEventHandler(this,
&Form1::Form1_Paint);
this->ResumeLayout(false);
}
#pragma endregion
private:
System::Void Form1_Paint(System::Object^ sender,
System::Windows::Forms::PaintEventArgs^ e)
{
}
private: System::Void btnTemp_Click(System::Object^ sender,
System::EventArgs^ e)
{
Bitmap ^srcImage = gcnew Bitmap("test_src.bmp");
Graphics ^srcG = Graphics::FromImage(srcImage);
Bitmap ^toImage = gcnew Bitmap(srcImage->Width, srcImage->Height, srcG);
Graphics ^toG = Graphics::FromImage(toImage);
IntPtr srcDc = srcG->GetHdc();
IntPtr toDc = toG->GetHdc();
BitBlt(toDc, 0, 0, srcImage->Width, srcImage->Height, srcDc, 0, 0,
0xCC0020);
srcG->ReleaseHdc(srcDc);
toG->ReleaseHdc(toDc);
srcImage->Save("src.jpg");
toImage->Save("dest.jpg");
}
};
}
.
- References:
- Q: Why is my BitBlt destination always blank?
- From: cranke_boy
- Re: Q: Why is my BitBlt destination always blank?
- From: Mark Salsbery [MVP]
- Q: Why is my BitBlt destination always blank?
- Prev by Date: Re: Q: Why is my BitBlt destination always blank?
- Next by Date: PolyPolygon and PolyPolyline in GDI+
- Previous by thread: Re: Q: Why is my BitBlt destination always blank?
- Next by thread: PolyPolygon and PolyPolyline in GDI+
- Index(es):
Relevant Pages
|