Open kazukazu0333 opened 1 year ago
以下は、あなたが要求した要件に基づいた ViewModel の例です。必要に応じて調整してください。
using Prism.Commands;
using Prism.Mvvm;
namespace CameraAdjustment.ViewModels
{
public class MainViewModel : BindableBase
{
private BitmapImage _capturedImage;
public BitmapImage CapturedImage
{
get { return _capturedImage; }
set { SetProperty(ref _capturedImage, value); }
}
private double _zoomRatio;
public double ZoomRatio
{
get { return _zoomRatio; }
set { SetProperty(ref _zoomRatio, value); }
}
private int _imageOffsetX;
public int ImageOffsetX
{
get { return _imageOffsetX; }
set { SetProperty(ref _imageOffsetX, value); }
}
private int _imageOffsetY;
public int ImageOffsetY
{
get { return _imageOffsetY; }
set { SetProperty(ref _imageOffsetY, value); }
}
private ObservableCollection<LineProfileViewModel> _lineProfiles = new ObservableCollection<LineProfileViewModel>();
public ObservableCollection<LineProfileViewModel> LineProfiles
{
get { return _lineProfiles; }
set { SetProperty(ref _lineProfiles, value); }
}
private bool _isContinuousCaptureEnabled;
public bool IsContinuousCaptureEnabled
{
get { return _isContinuousCaptureEnabled; }
set { SetProperty(ref _isContinuousCaptureEnabled, value); }
}
public DelegateCommand CaptureSingleImageCommand { get; }
public DelegateCommand CaptureContinuousImagesCommand { get; }
public DelegateCommand ZoomInCommand { get; }
public DelegateCommand ZoomOutCommand { get; }
public DelegateCommand<Point> ShowLineProfileCommand { get; }
public DelegateCommand<MouseEventArgs> UpdateOffsetCommand { get; }
private ICaptureService _captureService;
public MainViewModel(ICaptureService captureService)
{
// キャプチャーサービスインタフェースの設定
_captureService = captureService;
// キャプチャー実行コマンドの定義
CaptureSingleImageCommand = new DelegateCommand(ExecuteCaptureSingleImage);
CaptureContinuousImagesCommand = new DelegateCommand(ExecuteCaptureContinuousImages);
ZoomInCommand = new DelegateCommand(ExecuteZoomIn);
ZoomOutCommand = new DelegateCommand(ExecuteZoomOut);
ShowLineProfileCommand = new DelegateCommand<Point>(ExecuteShowLineProfile);
UpdateOffsetCommand = new DelegateCommand<MouseEventArgs>(ExecuteUpdateOffset);
}
private void ExecuteCaptureSingleImage()
{
var image = _captureService.CaptureSingleImage();
CapturedImage = ConvertToBitmapImage(image);
}
private void ExecuteCaptureContinuousImages()
{
// start and stop continuous capture
}
private void ExecuteZoomIn()
{
// zoom in
}
private void ExecuteZoomOut()
{
// zoom out
}
private void ExecuteShowLineProfile(Point point)
{
// add line profile view model
// show line profile view
}
private void ExecuteUpdateOffset(MouseEventArgs e)
{
// update image offest
}
private BitmapImage ConvertToBitmapImage(Bitmap image)
{
// convert bitmap to bitmapimage
}
}
public class LineProfileViewModel
{
public List<Point> Points { get; set; }
public List<double> Values { get; set; }
}
}
以上が ViewModel の例です。ご参考になると思います。
上記に述べた手順にしたがって、C#コードを作成し、それらを相互に結び付けて、カメラ調整用画面を作成してください
ViewのXAMLコードの例を以下に示します。この例では、カメラから取得した画像を表示するためのImage要素、ラインプロファイルを表示するためのChart要素、および撮影ボタンを持つStackPanel要素が表示されています。このViewは、プリズムのモジュール、ビュー、およびビューモデルの要件に準拠しています。
この例では、ビュー・モデルにプロパティとしてバインドするための各種要素が含まれています。例えば、ImageコントロールのSourceプロパティにCapturedImageをバインドすることで、シングルショットまたは連続ショットのフレームから取得した画像を表示することができます。また、ラインプロファイルを表示するために、Chartコントロールを使用し、ChartのLineSeriesにLineProfileをバインドします。ビュー・モデルでコマンドを設定することで、シングルショットと連続撮影ボタンも実装できます。