全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1519
推到 Plurk!
推到 Facebook!

【轉貼】Message test

 
axsoft
版主


發表:681
回覆:1056
積分:969
註冊:2002-03-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2006-07-04 19:04:03 IP:61.219.xxx.xxx 未訂閱

Messsage test

GO~~ GO~

Code test


//---------------------------------------------------------------------------
#include
#pragma hdrstop

#if defined(__BORLANDC__) // fix for BCB
#undef LCS_SIGNATURE
#undef LCS_sRGB
#define LCS_SIGNATURE 'COSP'
#define LCS_sRGB 'BGRs'
#endif

// needed for ICM
#include
#pragma link "mscms.lib"

#include
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

TForm1 *Form1;
//---------------------------------------------------------------------------

__fastcall TForm1::TForm1(
TComponent* Owner): TForm(Owner),
OrigBitmap_(new Graphics::TBitmap())
{
OrigBitmap_->Assign(
Image1->Picture->Bitmap
);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::
RestoreButtonClick(TObject *Sender)
{
Image1->Picture->Bitmap->Assign(
OrigBitmap_.get()
);
ShowMessage("Bitmap restored.");
}
//---------------------------------------------------------------------------

void __fastcall TForm1::
ColorMatchButtonClick(TObject *Sender)
{
// get the file-name of the
// monitor's default profile
TCHAR monitor_profilename[MAX_PATH];
const HDC hScreenDC = GetDC(NULL);
DWORD num_chars = MAX_PATH;
const bool got_profile =
GetICMProfile(
hScreenDC, &num_chars,
monitor_profilename
);
ReleaseDC(NULL, hScreenDC);
if (!got_profile)
{
throw EWin32Error("no profile");
}

// initialize a PROFILE structure
PROFILE monitor_profile;
monitor_profile.dwType =
PROFILE_FILENAME;
monitor_profile.pProfileData =
static_cast
(monitor_profilename);
monitor_profile.cbDataSize =
(lstrlen(monitor_profilename) 1) *
sizeof(TCHAR);

// create the color profile object
HPROFILE hMonitorProfile =
OpenColorProfile(
&monitor_profile, PROFILE_READ,
FILE_SHARE_READ, OPEN_EXISTING
);
if (hMonitorProfile == NULL)
{
throw EWin32Error(
"OpenColorProfile() failed"
);
}
try
{
// validate the profile's contents
BOOL is_monitor_valid = FALSE;
IsColorProfileValid(
hMonitorProfile, &is_monitor_valid
);
if (!is_monitor_valid)
{
throw EWin32Error("bad profile");
}

// initialize a LOGCOLORSPACE struct
LOGCOLORSPACE lcs = {
LCS_SIGNATURE, 0x400,
sizeof(LOGCOLORSPACE)
};
// sRGB color space
lcs.lcsCSType = LCS_sRGB;
// perceptual rendering intent
lcs.lcsIntent = LCS_GM_IMAGES;

// create a color transform object
const HTRANSFORM hColorTransform =
CreateColorTransform(
&lcs, hMonitorProfile, NULL,
NORMAL_MODE ENABLE_GAMUT_CHECKING
);
if (hColorTransform == NULL)
{
throw EWin32Error(
"CreateColorTransform() failed"
);
}
try
{
//
// color-match the bitmap...
//

// grab a reference to
// the TBitmap object
Graphics::TBitmap& Bitmap =
*Image1->Picture->Bitmap;
Bitmap.PixelFormat = pf24bit;

// grab a pointer to the pixels
BITMAP bmp;
GetObject(Bitmap.Handle,
sizeof(BITMAP), &bmp
);

// color-match the bitmap's pixels
const bool match_ok =
TranslateBitmapBits(
hColorTransform,
bmp.bmBits, BM_RGBTRIPLETS,
bmp.bmWidth, bmp.bmHeight,
NULL, bmp.bmBits,
BM_RGBTRIPLETS, NULL, NULL, 0
);
if (match_ok)
{
// repaint
Image1->Refresh();
ShowMessage(
"Bitmap color-matched."
);
}
else
{
throw EWin32Error(
"TranslateBitmapBits() failed"
);
}
}
catch (...)
{
// destroy the color
// transform object
DeleteColorTransform(
hColorTransform
);
throw;
}
}
catch (...)
{
// destroy the color profile object
CloseColorProfile(hMonitorProfile);
throw;
}
// destroy the color profile object
CloseColorProfile(hMonitorProfile);
}
//---------------------------------------------------------------------------


系統時間:2024-07-02 2:56:28
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!