以前の記事で欠落していた機能の補完です
まずjpsファイルの構造ですが、これは左右のjpeg画像を横に並べただけのものです。つまり

図で表すと、こんな感じですね。もとのjpsファイルは拡張子こそ*.jpsですが、中身はjpegなので、これを左右に分離するもっとも自然な流れは、全体のbitmapを用意して、左半分と右半分のbitmapに分割して、それぞれを表示するなりファイルセーブするなりで目的は達成されます。従って、コードは、
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <jpeg.hpp>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
TJPEGImage* original = new TJPEGImage();
TBitmap* origbitmap = new TBitmap();
void CropJPEG_L_Half2()
{
TBitmap* bitmap = new TBitmap();
try {
bitmap->Assign(original);
int width = bitmap->Width;
int height = bitmap->Height;
// Create a cropped bitmap
TBitmap* croppedBitmap = new TBitmap();
try {
croppedBitmap->Width = width/2;
croppedBitmap->Height = height;
// Copy the desired region from the original bitmap
croppedBitmap->Canvas->CopyRect(
Rect(0, 0, width/2, height),
bitmap->Canvas,
Rect(0,0,width/2, height) // left image
);
if( Form1->Cross )
Form1->Image2->Picture->Bitmap = croppedBitmap;
else
Form1->Image3->Picture->Bitmap = croppedBitmap;
} __finally {
delete croppedBitmap;
}
} __finally {
delete bitmap;
}
}
void CropJPEG_R_Half2()
{
TBitmap* bitmap = new TBitmap();
try {
bitmap->Assign(original);
int width = bitmap->Width;
int height = bitmap->Height;
// Create a cropped bitmap
TBitmap* croppedBitmap = new TBitmap();
try {
croppedBitmap->Width = width/2;
croppedBitmap->Height = height;
// Copy the desired region from the original bitmap
croppedBitmap->Canvas->CopyRect(
Rect(0, 0, width/2, height),
bitmap->Canvas,
Rect(width/2,0,width, height) // right image
);
if( Form1->Cross )
Form1->Image3->Picture->Bitmap = croppedBitmap;
else
Form1->Image2->Picture->Bitmap = croppedBitmap;
} __finally {
delete croppedBitmap;
}
} __finally {
delete bitmap;
}
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OpenJPSClick(TObject *Sender)
{
if(OpenDialog1->Execute()) {
original->LoadFromFile(OpenDialog1->FileName);
origbitmap->Assign(original);
Image1->Picture->Bitmap = origbitmap;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SplitClick(TObject *Sender)
{
CropJPEG_L_Half2();
CropJPEG_R_Half2();
}
//---------------------------------------------------------------------------
フォームは、

こんな感じです。OpenJPSボタンを押すと、

ダイアログが出て、*.jpsファイルを選んで”開く”と、

ここでSplitします。

左右の画像の間隔はフォームのサイズを変えて調整できます。

さて、あとはmpoファイルの扱いですが、こちらはmposhowのソースにやり方が書いてあるはずですから、出来るでしょう。最後の壁がプレビュー付きのOpenDialogですな……。(期日未定:鋭意制作中ないし研究中)
コメント