お知らせ

電子会議

ライブラリ

パレット

Delphi FAQ検索

Delphi FAQ一覧

サンプル蔵





FDelphi FAQ
16番会議室「玉石混淆みんなで作るSample蔵」に寄せられたサンプル

"Bitmap結合+コメント付け TStream使用"

この発言に対し以下のコメントが寄せられています
#00453 TN さん コンテナフォームを使ってみたら?
#00815 とよぞう さん RE:Bitmap結合+コメント付け TStream使用

TFileStreamとTMemoryStreamを使い複数(この場合2つ)Bitmapファイルを 結合し、コメントを付加した、独自ファイルを作る/読む方法の例です。  Formに ボタン二つとTImage二つ、TLabel一つ貼り付けます。 c:\に 1.bmpと2.bmpを用意しておきます。 type TWbmpHeader=Record cmtsize,bmp1size,bmp2size:integer; end; //結合させる procedure TForm1.Button1Click(Sender: TObject); var fs,bmp1,bmp2:TFileStream; theHeader:TWbmpHeader; comment:string; begin bmp1:=TFilestream.Create('c:\1.bmp',fmOpenRead); bmp2:=TFilestream.Create('c:\2.bmp',fmOpenRead); fs:=TFileStream.create('c:\12.wbmp',fmCreate); comment:='コメントです'; try with theHeader do begin bmp1size:=bmp1.size; bmp2size:=bmp2.size; cmtSize:=length(comment); end; fs.position:=0; fs.Write(theHeader,sizeOf(theHeader)); bmp1.position:=0;//無くても良いが念のため bmp2.position:=0;//無くても良いが念のため fs.copyfrom(bmp1,bmp1.size); fs.copyfrom(bmp2,bmp2.size); fs.Write(PChar(comment)^,length(comment)); finally fs.free; bmp1.free; bmp2.free; end; end; //別々に取り出す procedure TForm1.Button2Click(Sender: TObject); var bmp1,bmp2:TMemoryStream; fs:TFileStream; theHeader:TWbmpHeader; comment:string; pComment:PChar; bmp:TBitmap; begin bmp:=TBitmap.create; bmp1:=TMemoryStream.Create; bmp2:=TMemorystream.Create; fs:=TFileStream.create('c:\12.wbmp',fmOpenRead); try fs.position:=0; fs.Read(theheader,sizeOf(theHeader)); bmp1.CopyFrom(fs,theHeader.bmp1size); bmp2.CopyFrom(fs,theHeader.bmp2size); pComment:=StrAlloc(theHeader.cmtSize+1); fs.Read(pComment^,theHeader.cmtSize); (pComment+theHeader.cmtSize)^:=#0; comment:=string(pComment); bmp1.position:=0;//必須 bmp.LoadFromStream(bmp1); image1.Picture.assign(bmp); bmp2.position:=0;//必須 bmp.LoadFromStream(bmp2); image2.Picture.assign(bmp); label1.Caption:=comment; finally fs.free; bmp1.free; bmp2.free; bmp.free; strDispose(pComment); end; end; ☆☆☆ わからないときサンプル蔵 わかったときサンプル蔵 ☆☆☆ 98/03/15(日) 01:14 凛(MXB01744) Original document by 凛 氏 ID:(MXB01744)



ここにあるドキュメントは NIFTY SERVEの Delphi Users' Forum の16番会議室「玉石混淆みんなで作るSample蔵」に投稿されたサンプルです。これらのサンプルはボーランド株式会社がサポートする公式のものではありません。また、必ずしも動作が検証されているものではありません。これらのサンプルを使用したことに起因するいかなる損害も投稿者、およびフォーラムスタッフはその責めを負いません。使用者のリスクの範疇でご使用下さい。

Copyright 1996-2002 Delphi Users' Forum