LboxGd

  コンストラクタ



Windows 用の bgd.dll をインストールする必要があります
Windows ディレクトリまたは システムディレクトリに bgd.dll をコピーして下さい

全ての機能を実装しているわけではありません。必要な場合はLboxGdを継承して実装して下さい

(bgd.dll は、PHP で使用されている Imageライブラリ(GD) です)
※ 現バージョン(2.0.33)では GIF が使えるようになっています

また、最近のバージョンでは 「Windows users: bgd.dll now uses the __stdcall calling convention」 との事で、試してはいませんが、 VB で使用できるようになっているとの事です

一番重要なのは、ビルドするアプリケーションのプロジェクト設定で、「C/C++」タブのコード生成カテゴリの、「使用するランタイムライブラリ」をマルチスレッド(DLL)にする事です

  
// *********************************************************
// コンストラクタ
// *********************************************************
LboxGd::LboxGd()
{
	this->Type.SetChar( 0, 0 );
	this->ErrMessage.SetChar( 0, 0 );
	this->lib = LoadLibrary( "bgd.dll" );
	this->gd = NULL;
}

// *********************************************************
// デストラクタ
// *********************************************************
LboxGd::~LboxGd()
{
	if ( this->gd != NULL ) {
		this->Destroy();
	}
	if ( this->lib != NULL ) {
		FreeLibrary( this->lib );
	}
}
  



  関数ポインタ宣言



  
#include "gd.h"
typedef gdImagePtr
(__stdcall *LPFUNC_gdImageCreateFrom)(
	FILE *
);
typedef void
(__stdcall *LPFUNC_gdImageDestroy)(
	gdImagePtr
);
typedef int
(__stdcall *LPFUNC_gdImageColor)(
	gdImagePtr,
	int,
	int,
	int
);
typedef void
(__stdcall *LPFUNC_gdImageSetThickness)(
	gdImagePtr,
	int
);
typedef void
(__stdcall *LPFUNC_gdImageSetStyle)(
	gdImagePtr,
	int *,
	int
);
typedef void
(__stdcall *LPFUNC_gdImageLine)(
	gdImagePtr,
	int,
	int,
	int,
	int,
	int
);
typedef void
(__stdcall *LPFUNC_gdImageSave)(
	gdImagePtr,
	FILE *
);
typedef void
(__stdcall *LPFUNC_gdImageJpeg)(
	gdImagePtr,
	FILE *,
	int
);
typedef void
(__stdcall *LPFUNC_gdImageRectangle)(
	gdImagePtr,
	int,int,
	int,int,
	int
);
typedef void
(__stdcall *LPFUNC_gdImageArc)(
	gdImagePtr,
	int,int,
	int,int,
	int,int,
	int
);
typedef void
(__stdcall *LPFUNC_gdImageCopyResampled)(
	gdImagePtr,gdImagePtr,
	int,int,
	int,int,
	int,int,
	int,int
);
typedef gdImagePtr
(__stdcall *LPFUNC_gdImageCreateTrueColor)(
	int, int
);
  



  LoadPng

  
// *********************************************************
// PNG のロード
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxGd::LoadPng( LboxString *LPath )
{
	return LboxGd::LoadPng(
		LPath->szLboxString
	);
}
BOOL LboxGd::LoadPng( LPTSTR lpPath )
{
	if ( this->lib == NULL ) {
		this->SetLibLoadErrorMessage();
		return false;
	}

	if ( this->gd != NULL ) {
		this->Destroy();
	}

	LPFUNC_gdImageCreateFrom Dll_gdImageCreateFromPng;

	Dll_gdImageCreateFromPng =
		(LPFUNC_gdImageCreateFrom)GetProcAddress(
			lib, "gdImageCreateFromPng@4"
		);
	if ( Dll_gdImageCreateFromPng == NULL ) {
		this->SetFuncLoadErrorMessage();
		return false;
	}

	gdImagePtr im;

	FILE *in;
	in = fopen( lpPath, "rb" );
	if ( in == NULL ) {
		this->ErrMessage.operator = (
			"ファイルをオープンできませんでした"
		);
		return false;
	}

	im = Dll_gdImageCreateFromPng( in );
	fclose(in);

	this->gd = (void *)im;
	this->Type.operator = ("PNG");

	return true;
}
  



  LoadJpeg

  
// *********************************************************
// JPEG のロード
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxGd::LoadJpeg( LboxString *LPath )
{
	return LboxGd::LoadJpeg(
		LPath->szLboxString
	);
}
BOOL LboxGd::LoadJpeg( LPTSTR lpPath )
{
	if ( this->lib == NULL ) {
		this->SetLibLoadErrorMessage();
		return false;
	}

	if ( this->gd != NULL ) {
		this->Destroy();
	}

	LPFUNC_gdImageCreateFrom Dll_gdImageCreateFromJpeg;

	Dll_gdImageCreateFromJpeg =
		(LPFUNC_gdImageCreateFrom)GetProcAddress(
			lib, "gdImageCreateFromJpeg@4"
		);
	if ( Dll_gdImageCreateFromJpeg == NULL ) {
		this->SetFuncLoadErrorMessage();
		return false;
	}

	gdImagePtr im;

	FILE *in;
	in = fopen( lpPath, "rb" );
	if ( in == NULL ) {
		this->ErrMessage.operator = (
			"ファイルをオープンできませんでした"
		);
		return false;
	}

	im = Dll_gdImageCreateFromJpeg( in );
	fclose(in);

	this->gd = (void *)im;
	this->Type.operator = ("JPEG");

	return true;
}
  



  LoadGif

  
// *********************************************************
// GIF のロード
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxGd::LoadGif( LboxString *LPath )
{
	return LboxGd::LoadGif(
		LPath->szLboxString
	);
}
BOOL LboxGd::LoadGif( LPTSTR lpPath )
{
	if ( this->lib == NULL ) {
		this->SetLibLoadErrorMessage();
		return false;
	}

	if ( this->gd != NULL ) {
		this->Destroy();
	}

	LPFUNC_gdImageCreateFrom Dll_gdImageCreateFromGif;

	Dll_gdImageCreateFromGif =
		(LPFUNC_gdImageCreateFrom)GetProcAddress(
			lib, "gdImageCreateFromJpeg@4"
		);
	if ( Dll_gdImageCreateFromGif == NULL ) {
		this->SetFuncLoadErrorMessage();
		return false;
	}

	gdImagePtr im;

	FILE *in;
	in = fopen( lpPath, "rb" );
	if ( in == NULL ) {
		this->ErrMessage.operator = (
			"ファイルをオープンできませんでした"
		);
		return false;
	}

	im = Dll_gdImageCreateFromGif( in );
	fclose(in);

	this->gd = (void *)im;
	this->Type.operator = ("GIF");

	return true;
}
  



  Load

  
// *********************************************************
// 拡張子によるロード
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxGd::Load( LboxString *LPath )
{
	return LboxGd::Load(
		LPath->szLboxString
	);
}
BOOL LboxGd::Load( LPTSTR lpPath )
{
	LboxString LString;
	LPTSTR ptr;
	
	LString.operator = (lpPath);
	LString.Upper();
	ptr = LString.FindExtension();
	if ( lstrcmp( ptr, ".PNG" ) == 0 ) {
		return LboxGd::LoadPng( lpPath );
	}
	if ( lstrcmp( ptr, ".JPEG" ) == 0 ) {
		return LboxGd::LoadJpeg( lpPath );
	}
	if ( lstrcmp( ptr, ".JPG" ) == 0 ) {
		return LboxGd::LoadJpeg( lpPath );
	}
	if ( lstrcmp( ptr, ".GIF" ) == 0 ) {
		return LboxGd::LoadGif( lpPath );
	}

	return false;
}
  



  SavePng

  
// *********************************************************
// PNG 保存
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxGd::SavePng( LboxString *LPath )
{
	return LboxGd::SavePng(
		LPath->szLboxString
	);
}
BOOL LboxGd::SavePng( LPTSTR lpPath )
{
	if ( this->lib == NULL ) {
		this->SetLibLoadErrorMessage();
		return false;
	}

	LPFUNC_gdImageSave Dll_gdImagePng;

	Dll_gdImagePng =
		(LPFUNC_gdImageSave)GetProcAddress(
			lib, "gdImagePng@8"
		);
	if ( Dll_gdImagePng == NULL ) {
		this->SetFuncLoadErrorMessage();
		return false;
	}

	FILE *out;
	out = fopen( lpPath, "wb" );
	if ( out == NULL ) {
		this->ErrMessage.operator = (
			"ファイルをオープンできませんでした"
		);
		return false;
	}

	gdImagePtr im;

	im = (gdImagePtr)(this->gd);

	Dll_gdImagePng(im, out);
	fclose( out );

	return true;
}
  



  SaveJpeg

宣言が以下のようになっているので、第2引数は省略可能です
  
BOOL Save( LboxString *LPath, int Quality=75 );
BOOL Save( LPTSTR lpPath, int Quality=75 );
  

  
// *********************************************************
// JPEG 保存
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxGd::SaveJpeg( LboxString *LPath, int Quality )
{
	return LboxGd::SaveJpeg(
		LPath->szLboxString,
		Quality
	);
}
BOOL LboxGd::SaveJpeg( LPTSTR lpPath, int Quality )
{
	if ( this->lib == NULL ) {
		this->SetLibLoadErrorMessage();
		return false;
	}

	LPFUNC_gdImageJpeg Dll_gdImageJpeg;

	Dll_gdImageJpeg =
		(LPFUNC_gdImageJpeg)GetProcAddress(
			lib, "gdImageJpeg@12"
		);
	if ( Dll_gdImageJpeg == NULL ) {
		this->SetFuncLoadErrorMessage();
		return false;
	}

	FILE *out;
	out = fopen( lpPath, "wb" );
	if ( out == NULL ) {
		this->ErrMessage.operator = (
			"ファイルをオープンできませんでした"
		);
		return false;
	}

	gdImagePtr im;

	im = (gdImagePtr)(this->gd);

	Dll_gdImageJpeg(im, out, Quality);
	fclose( out );

	return true;
}
  



  SaveGif

  
// *********************************************************
// GIF 保存
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxGd::SaveGif( LboxString *LPath )
{
	return LboxGd::SaveGif(
		LPath->szLboxString
	);
}
BOOL LboxGd::SaveGif( LPTSTR lpPath )
{
	if ( this->lib == NULL ) {
		this->SetLibLoadErrorMessage();
		return false;
	}

	LPFUNC_gdImageSave Dll_gdImageGif;

	Dll_gdImageGif =
		(LPFUNC_gdImageSave)GetProcAddress(
			lib, "gdImageGif@8"
		);
	if ( Dll_gdImageGif == NULL ) {
		this->SetFuncLoadErrorMessage();
		return false;
	}

	FILE *out;
	out = fopen( lpPath, "wb" );
	if ( out == NULL ) {
		this->ErrMessage.operator = (
			"ファイルをオープンできませんでした"
		);
		return false;
	}

	gdImagePtr im;

	im = (gdImagePtr)(this->gd);

	Dll_gdImageGif(im, out);
	fclose( out );

	return true;
}
  



  Save

宣言が以下のようになっているので、第2引数は省略可能です
  
BOOL Save( LboxString *LPath, int Quality=75 );
BOOL Save( LPTSTR lpPath, int Quality=75 );
  

  
// *********************************************************
// 拡張子による保存
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxGd::Save( LboxString *LPath, int Quality )
{
	return LboxGd::Save(
		LPath->szLboxString,
		Quality
	);
}
BOOL LboxGd::Save( LPTSTR lpPath, int Quality )
{
	LboxString LString;
	LPTSTR ptr;
	
	LString.operator = (lpPath);
	LString.Upper();
	ptr = LString.FindExtension();
	if ( lstrcmp( ptr, ".PNG" ) == 0 ) {
		return LboxGd::SavePng( lpPath );
	}
	if ( lstrcmp( ptr, ".JPEG" ) == 0 ) {
		return LboxGd::SaveJpeg( lpPath, Quality );
	}
	if ( lstrcmp( ptr, ".JPG" ) == 0 ) {
		return LboxGd::SaveJpeg( lpPath, Quality );
	}
	if ( lstrcmp( ptr, ".GIF" ) == 0 ) {
		return LboxGd::SaveGif( lpPath );
	}

	return false;
}
  



  CreateColor

  
// *********************************************************
// カラー作成
// 戻り値 : true 成功, false 失敗
// *********************************************************
int LboxGd::CreateColor( int r, int g, int b )
{
	if ( this->lib == NULL ) {
		this->SetLibLoadErrorMessage();
		return false;
	}

	LPFUNC_gdImageColor Dll_gdImageColorAllocate;

	Dll_gdImageColorAllocate =
		(LPFUNC_gdImageColor)GetProcAddress(
			lib, "gdImageColorAllocate@16"
		);
	if ( Dll_gdImageColorAllocate == NULL ) {
		this->SetFuncLoadErrorMessage();
		return false;
	}

	gdImagePtr im;

	im = (gdImagePtr)(this->gd);
	int nRet;

	nRet = Dll_gdImageColorAllocate(im, r, g, b );

	return nRet;
}
  



  SetLineWidth

  
// *********************************************************
// 線幅決定
// 戻り値 : true 成功, false 失敗
// *********************************************************
int LboxGd::SetLineWidth( int nWidth )
{
	if ( this->lib == NULL ) {
		this->SetLibLoadErrorMessage();
		return false;
	}

	LPFUNC_gdImageSetThickness Dll_gdImageSetThickness;

	Dll_gdImageSetThickness =
		(LPFUNC_gdImageSetThickness)GetProcAddress(
			lib, "gdImageSetThickness@8"
		);
	if ( Dll_gdImageSetThickness == NULL ) {
		this->SetFuncLoadErrorMessage();
		return false;
	}

	gdImagePtr im;

	im = (gdImagePtr)(this->gd);

	Dll_gdImageSetThickness(im, nWidth);

	return true;
}
  



  SetStyle

  
// *********************************************************
// 線スタイル作成
// 戻り値 : true 成功, false 失敗
// *********************************************************
int LboxGd::SetStyle( int *Array, int nArray )
{
	if ( this->lib == NULL ) {
		this->SetLibLoadErrorMessage();
		return false;
	}

	LPFUNC_gdImageSetStyle Dll_gdImageSetStyle;

	Dll_gdImageSetStyle =
		(LPFUNC_gdImageSetStyle)GetProcAddress(
			lib, "gdImageSetStyle@12"
		);
	if ( Dll_gdImageSetStyle == NULL ) {
		this->SetFuncLoadErrorMessage();
		return false;
	}

	gdImagePtr im;

	im = (gdImagePtr)(this->gd);

	Dll_gdImageSetStyle(im, Array, nArray);

	return true;
}
  



  Line

スタイルを使用した直線(つまり点線)を引くサンプル
  
int b,w;
b = Gd->CreateColor( 0, 0, 0 );
w = Gd->CreateColor( 255, 255, 255 );
int s[10];
s[0] = b;
s[1] = b;
s[2] = b;
s[3] = b;
s[4] = b;
s[5] = w;
s[6] = w;
s[7] = w;
s[8] = w;
s[9] = w;
Gd->SetStyle( s, 10 ); // 10 は配列数
Gd->Line( 0, 0, 100, 100 );
  

  
// *********************************************************
// 直線の描画
// 戻り値 : true 成功, false 失敗
// *********************************************************
// スタイル使用
int LboxGd::Line( int x1, int y1, int x2, int y2 )
{
	if ( this->lib == NULL ) {
		this->SetLibLoadErrorMessage();
		return false;
	}

	LPFUNC_gdImageLine Dll_gdImageLine;

	Dll_gdImageLine =
		(LPFUNC_gdImageLine)GetProcAddress(
			lib, "gdImageLine@24"
		);
	if ( Dll_gdImageLine == NULL ) {
		this->SetFuncLoadErrorMessage();
		return false;
	}

	gdImagePtr im;

	im = (gdImagePtr)(this->gd);

	Dll_gdImageLine(im, x1, y1, x2, y2, gdStyled );

	return true;
}
// 色使用
int LboxGd::Line( int x1, int y1, int x2, int y2, int color )
{
	if ( this->lib == NULL ) {
		this->SetLibLoadErrorMessage();
		return false;
	}

	LPFUNC_gdImageLine Dll_gdImageLine;

	Dll_gdImageLine =
		(LPFUNC_gdImageLine)GetProcAddress(
			lib, "gdImageLine@24"
		);
	if ( Dll_gdImageLine == NULL ) {
		this->SetFuncLoadErrorMessage();
		return false;
	}

	gdImagePtr im;

	im = (gdImagePtr)(this->gd);

	Dll_gdImageLine(im, x1, y1, x2, y2, color );

	return true;
}
  



  Box

  
// *********************************************************
// 矩形の描画
// 戻り値 : true 成功, false 失敗
// *********************************************************
int LboxGd::Box(
	int x1, int y1, int x2, int y2, int color, int fill )
{
	if ( this->lib == NULL ) {
		this->SetLibLoadErrorMessage();
		return false;
	}

	LPFUNC_gdImageRectangle Dll_gdImageRectangle;

	if ( fill ) {
		Dll_gdImageRectangle =
			(LPFUNC_gdImageRectangle)GetProcAddress(
				lib, "imageFilledRectAngle@24"
			);
	}
	else {
		Dll_gdImageRectangle =
			(LPFUNC_gdImageRectangle)GetProcAddress(
				lib, "gdImageRectangle@24"
			);
	}
	if ( Dll_gdImageRectangle == NULL ) {
		this->SetFuncLoadErrorMessage();
		return false;
	}

	gdImagePtr im;

	im = (gdImagePtr)(this->gd);

	Dll_gdImageRectangle(im, x1, y1, x2, y2, color );

	return true;
}
  



  Arc

  
// *********************************************************
// 楕円の描画
// 戻り値 : true 成功, false 失敗
// *********************************************************
int LboxGd::Arc( int x, int y, int w, int h, int color )
{
	if ( this->lib == NULL ) {
		this->SetLibLoadErrorMessage();
		return false;
	}

	return LboxGd::Arc(
		x, y,
		w, h,
		0, 359,
		color
	);
}
int LboxGd::Arc(
	int x, int y, int w, int h, int s, int e, int color )
{
	if ( this->lib == NULL ) {
		this->SetLibLoadErrorMessage();
		return false;
	}

	LPFUNC_gdImageArc Dll_gdImageArc;

	Dll_gdImageArc =
		(LPFUNC_gdImageArc)GetProcAddress(
			lib, "gdImageArc@32"
		);
	if ( Dll_gdImageArc == NULL ) {
		this->SetFuncLoadErrorMessage();
		return false;
	}

	gdImagePtr im;

	im = (gdImagePtr)(this->gd);

	Dll_gdImageArc(im, x, y, w, h, s, e, color );

	return true;
}
  



  Copy

50% 縮小サンプル
  
if ( Commdlg->OpenFileName( FilePath ) ) {
	Dlg->EditSetText( IDC_READONLY, FilePath );
	if ( !(Gd->Load(FilePath)) ) {
		Dlg->MsgOk("ERR");
		break;
	}

	LboxString SavePath;
	Tool.ProgramDirectory( &SavePath );
	SavePath.AddBackslash();
	SavePath.operator += ("SAVE.PNG");

	LboxGd Gd2;

	Gd->Copy( &Gd2, 50 );

	Gd2.Save( &SavePath );
}
  

  
// *********************************************************
// 伸縮コピー
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxGd::Copy( LboxGd *objGD, int nRate )
{
	if ( this->lib == NULL ) {
		this->SetLibLoadErrorMessage();
		return false;
	}

	LPFUNC_gdImageCopyResampled Dll_gdImageCopyResampled;

	Dll_gdImageCopyResampled =
		(LPFUNC_gdImageCopyResampled)GetProcAddress(
			lib, "gdImageCopyResampled@40"
		);
	if ( Dll_gdImageCopyResampled == NULL ) {
		this->SetFuncLoadErrorMessage();
		return false;
	}

	int w,w2;
	int h,h2;

	this->GetImageSize( &w, &h );
	w2 = (double)w * ( (double)nRate / (double)100 );
	h2 = (double)h * ( (double)nRate / (double)100 );

	gdImagePtr im_in;
	gdImagePtr im_out;

	if ( !(objGD->Create( w2, h2 )) ) {
		return false;
	}

	im_in = (gdImagePtr)(this->gd);
	im_out = (gdImagePtr)(objGD->gd);

	Dll_gdImageCopyResampled(
		im_out,
		im_in,
		0, 0, 0, 0,
		w2, h2,
		w, h
	);

	return true;
}
  



  GetWidth

  
// *********************************************************
// 幅取得
// 戻り値 : 幅
// *********************************************************
int LboxGd::GetWidth( void )
{
	gdImagePtr im;

	im = (gdImagePtr)(this->gd);

	return im->sx;
}
  



  GetHeight

  
// *********************************************************
// 高さ取得
// 戻り値 : 高さ
// *********************************************************
int LboxGd::GetHeight( void )
{
	gdImagePtr im;

	im = (gdImagePtr)(this->gd);

	return im->sy;
}
  



  GetImageSize

  
// *********************************************************
// 幅・高さ取得
// 戻り値 : 高さ
// *********************************************************
void LboxGd::GetImageSize( int *w, int *h )
{
	(*w) = this->GetWidth();
	(*h) = this->GetHeight();
}
  



  新規イメージ作成

  
// *********************************************************
// 新規イメージ作成
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxGd::CreateJpeg( int w, int h )
{
	this->Type = "JPEG";
	return LboxGd::Create( w, h );
}
BOOL LboxGd::CreatePng( int w, int h )
{
	this->Type = "PNG";
	return LboxGd::Create( w, h );
}
BOOL LboxGd::Create( int w, int h )
{
	if ( this->lib == NULL ) {
		this->SetLibLoadErrorMessage();
		return false;
	}

	LPFUNC_gdImageCreateTrueColor Dll_gdImageCreateTrueColor;

	Dll_gdImageCreateTrueColor =
		(LPFUNC_gdImageCreateTrueColor)GetProcAddress(
			lib, "gdImageCreateTrueColor@8"
		);
	if ( Dll_gdImageCreateTrueColor == NULL ) {
		this->SetFuncLoadErrorMessage();
		return false;
	}

	if ( this->gd != NULL ) {
		this->Destroy();
	}

	gdImagePtr im;

	im = Dll_gdImageCreateTrueColor(
		w, h
	);
	this->gd = (void *)im;

	return true;
}
  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ