Re: Q: Why is my BitBlt destination always blank?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




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");
}
};
}


.



Relevant Pages

  • Re: New to C++ entirely (HELP!)
    ... MFC and ATL are C++ class libraries that target native Win32 development. ... int __stdcall WinMain ... using namespace System::IO; ... static void Main2; ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Personal project, extending Scheme to OOP
    ... I've been passing around a reference to a single namespace ... unsigned int type: 4; ...
    (comp.lang.scheme)
  • [PATCH 2/8] ns: Introduce the setns syscall
    ... of containers but in the context of people doing interesting ... There is also demand in the context of containers to have ... int setns; ... an the name of the namespace you think you are changing, ...
    (Linux-Kernel)
  • Re: Late binding with unmanaged code
    ... I wonder can someone else show an example of importing GetProcAddress ... Scott Blood ... I don't know if i am missing a namespace. ... public extern static int InvokeFunc(int funcptr, int hwnd, string ...
    (microsoft.public.dotnet.languages.csharp)
  • [RFC] [PATCH] fs-wide dirty bit + reservations + multiple block allocation
    ... while the file system is marked clean results in a clean fsck. ... int count) ... * We use sorted double linked list for the per-filesystem reservation ... void ext2_free_blocks (struct inode * inode, unsigned long block, ...
    (Linux-Kernel)