はじめまして。
まだまだ、Delphi初心者なので困っています。
アドバイスをよろしくお願いします。
今、Image Obectsという画像処理ツールを使って、
フォーム上へ画像を表示させるプログラムを作って
います。簡単なプログラムなのですが、IODisplayの
部分で、EAccessViolationエラーが発生してしまいます。
画像の読み込みまではできているようなのですが、
表示がうまくいきません。
以下にソースを示しますので、アドバイスをいただけたら
と思います。よろしくお願いします。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
OleCtrls, IOLib_TLB, OleAuto, StdCtrls, ExtDlgs, Ole2;
type
TForm1 = class(TForm)
IODisplay1: TIODisplay;
private
{ Private 宣言 }
public
{ Public 宣言 }
end;
var
Form1:TForm1;
ImageA:Variant; //ファイルから読み込むための画像オブジェクト
rc:Boolean; //オブジェクトの初期化成否フラッグ
ioFileTypes:Variant; //ファイルの情報用オブジェクト
SizeX, SizeY, SizeB:Integer;//画像ファイルのxy方向大きさ
ioFile:Variant; //ファイルの入出力用オブジェクト
implementation
{$R *.DFM}
begin
//各オブジェクトの生成
//イメージオブジェクト
ImageA:=CreateOleObject('IO.IOImage');
//ファイルタイプオブジェクト
ioFileTypes:=CreateOleObject('IO.IOFileTypes');
//ファイルオブジェクト
ioFile:=CreateOleObject('IO.IOFile');
//読み込みファイルの設定
ioFileTypes.NeedToRead('IOImage');
ioFile.filename:='C:\Temp\image.bmp';
//ファイルからイメージを読み込み
rc:=ImageA.ReadFromFile(ioFile);
if not rc then
begin
ShowMessage('ファイルの読み込み処理(ImageRead)に失敗しました。');
ImageA.Destroy;
end else
begin
ShowMessage('読み込みまではできてます!');
//画像のxy大きさを取得
SizeX:=ImageA.Size(ioAxisX);
SizeY:=ImageA.Size(ioAxisY);
ShowMessage('SizeX='+ IntToStr(SizeX));
ShowMessage('SizeY='+ IntToStr(SizeY));
//画像のバンド幅(TrueColorか256階調かの判別)を取得
SizeB:=ImageA.Size(ioAxisB);
ShowMessage('SizeB='+ IntToStr(SizeB));
end;
//一度ディスプレイに表示
Form1.IODisplay1.Image:=ImageA;
ImageA.Destroy;
end.
IODisplay1がどういう定義になっているかによります。
ImageプロパティにはImageAが代入できるのですか?
代入後、ImageAをDestroyしてよいのでしょうか。
# 一般的に、Destroyでなく、Freeのほうがよろしいかと思います
一般的には、Imageプロパティには
Image.Assign(ImageA);
などとしますが。
ありがとうございます。
しかし、まだ、解決できていません。
IODisplayの定義部分を見てみました。
Imageプロパティは普通のものとちょっと違うんでしょうか?
以下に定義部分を示してみます。
ヅラヅラ記載してすみません。
アドバイスを宜しくお願いします。
定義部
TIODisplay = class(TOleControl)
private
FOnMouseDownImage: TIODisplayMouseDownImage;
FOnMouseMoveImage: TIODisplayMouseMoveImage;
FOnMouseUpImage: TIODisplayMouseUpImage;
FOnAnnotationToolAction: TIODisplayAnnotationToolAction;
FOnScrolled: TNotifyEvent;
FOnMouseWheelRotateImage: TIODisplayMouseWheelRotateImage;
FIntf: IIODisplay;
function GetControlInterface: IIODisplay;
protected
procedure CreateControl;
procedure InitControlData; override;
function Get_Image: IDispatch;
procedure Set_Image(const Image: IDispatch);
function Get_Acquire: IDispatch;
procedure Set_Acquire(const Acquire: IDispatch);
function Get_Overlay: IDispatch;
procedure Set_Overlay(const Overlay: IDispatch);
function Get_AnnotationTool: IDispatch;
procedure Set_AnnotationTool(const AnnotationTool: IDispatch);
function Get_Annotations: IDispatch;
procedure Set_Annotations(const Annotations: IDispatch);
function Get_DisplayOrigin: IDispatch;
procedure Set_DisplayOrigin(const DisplayOrigin: IDispatch);
function Get_Color(pixelValue: Double): OLE_COLOR;
procedure Set_Color(pixelValue: Double; result: OLE_COLOR);
procedure Set_ColorRange(startPixelValue: Double; endPixelValue:
Double; Param3: OLE_COLOR);
public
procedure Refresh;
function Snap: WordBool;
function Paint(var deviceContext: OLE_HANDLE; imageLeft: Integer;
imageTop: Integer;
imageWidth: Integer; imageHeight: Integer;
paintLeft: OLE_XPOS_PIXELS;
paintTop: OLE_YPOS_PIXELS; paintWidth:
OLE_XSIZE_PIXELS;
paintHeight: OLE_YSIZE_PIXELS): WordBool;
procedure UpdateWindow;
procedure DoClick;
function PaintDisplay(var deviceContext: OLE_HANDLE; left:
OLE_XPOS_PIXELS;
top: OLE_YPOS_PIXELS; width:
OLE_XSIZE_PIXELS; height: OLE_YSIZE_PIXELS): WordBool;
function CopyToClipboard: WordBool;
procedure AboutBox;
property ControlInterface: IIODisplay read GetControlInterface;
property DefaultInterface: IIODisplay read GetControlInterface;
property Window: Integer index -515 read GetIntegerProp;
property Image: IDispatch index 1011 read GetIDispatchProp write
SetIDispatchProp;
property Acquire: IDispatch index 1012 read GetIDispatchProp write
SetIDispatchProp;
property Overlay: IDispatch index 1013 read GetIDispatchProp write
SetIDispatchProp;
property AnnotationTool: IDispatch index 1015 read GetIDispatchProp
write SetIDispatchProp;
property Annotations: IDispatch index 1016 read GetIDispatchProp
write SetIDispatchProp;
property DisplayOrigin: IDispatch index 1017 read GetIDispatchProp
write SetIDispatchProp;
property Color[pixelValue: Double]: OLE_COLOR read Get_Color write
Set_Color;
property ColorRange[startPixelValue: Double; endPixelValue: Double]:
OLE_COLOR write Set_ColorRange;
property SnapComplete: WordBool index 1024 read GetWordBoolProp;
published
property ParentColor;
property TabStop;
property Align;
property DragCursor;
property DragMode;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property Visible;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnStartDrag;
property OnKeyUp;
property OnKeyPress;
property OnKeyDown;
property OnDblClick;
property OnClick;
property BackColor: TColor index -501 read GetTColorProp write
SetTColorProp stored False;
property BorderStyle: Integer index -504 read GetIntegerProp write
SetIntegerProp stored False;
property BorderVisible: WordBool index -519 read GetWordBoolProp
write SetWordBoolProp stored False;
property Appearance: Smallint index -520 read GetSmallintProp write
SetSmallintProp stored False;
property MousePointer: Integer index -521 read GetIntegerProp write
SetIntegerProp stored False;
property Zoom: Single index 1010 read GetSingleProp write
SetSingleProp stored False;
property ForceBackgroundPalette: WordBool index 1001 read
GetWordBoolProp write SetWordBoolProp stored False;
property RangeMaximum: Double index 1002 read GetDoubleProp write
SetDoubleProp stored False;
property RangeMinimum: Double index 1003 read GetDoubleProp write
SetDoubleProp stored False;
property Live: WordBool index 1014 read GetWordBoolProp write
SetWordBoolProp stored False;
property LiveUpdate: WordBool index 1004 read GetWordBoolProp write
SetWordBoolProp stored False;
property OverlayColor: TColor index 1005 read GetTColorProp write
SetTColorProp stored False;
property DisplayMode: TOleEnum index 1006 read GetTOleEnumProp write
SetTOleEnumProp stored False;
property RenderMode: TOleEnum index 1007 read GetTOleEnumProp write
SetTOleEnumProp stored False;
property RangeMode: TOleEnum index 1008 read GetTOleEnumProp write
SetTOleEnumProp stored False;
property SnapMode: TOleEnum index 1025 read GetTOleEnumProp write
SetTOleEnumProp stored False;
property BufferMode: TOleEnum index 1026 read GetTOleEnumProp write
SetTOleEnumProp stored False;
property OnMouseDownImage: TIODisplayMouseDownImage read
FOnMouseDownImage write FOnMouseDownImage;
property OnMouseMoveImage: TIODisplayMouseMoveImage read
FOnMouseMoveImage write FOnMouseMoveImage;
property OnMouseUpImage: TIODisplayMouseUpImage read FOnMouseUpImage
write FOnMouseUpImage;
property OnAnnotationToolAction: TIODisplayAnnotationToolAction read
FOnAnnotationToolAction write FOnAnnotationToolAction;
property OnScrolled: TNotifyEvent read FOnScrolled write
FOnScrolled;
property OnMouseWheelRotateImage: TIODisplayMouseWheelRotateImage
read FOnMouseWheelRotateImage write FOnMouseWheelRotateImage;
end;
気になるのは、Imageプロパティのwriteで、SetIDispatchPropを指定しているところです。Set_Imageプロシージャもあるようですが、使っていないのですよね。
これを見る限りでは、普通に := で代入してよさそうです。
ただ、代入後のオブジェクトを解放して良いかどうかは、マニュアルを見てください。
サンプルも付属しているようですが、そちらは調べました?
製品のようなので、開発元に問い合わせた方が早いと思います。
こういう高価なライブラリは、なかなか有用な情報が見つかりませんから。
サンプルもあるのですが、マニュアルと違うような使い方をしていて、
かなり難しかったです。
もう少し、がんばってみようと思ってます。
開発元への問い合わせも考えてみたいと思います。
Web上で調べても情報がないんですよね・・・
ホントにありがとうございました。
ツイート | ![]() |