public void PictureEditListviewCommand_Execute(object obj) { if (obj == null) { return; } if (RentLivingEdit == null) { return; } System.Collections.IList items = (System.Collections.IList)obj; if (items.Count > 0) { RentLivingPicture rlpic = items.Cast <RentLivingPicture>().FirstOrDefault(); if (rlpic == null) { return; } PictureEdit(rlpic); } }
// 物件画像編集メソッド(Listview内外のコマンドから呼ばれる) private void PictureEdit(RentLivingPicture rlpic) { // 画像編集Windowへ渡す為のArgをセット OpenRentLivingImageWindowEventArgs ag = new OpenRentLivingImageWindowEventArgs(); ag.Id = rlpic.RentPictureId; ag.RentLivingPictureObject = rlpic; ag.RentLivingPictures = RentLivingEdit.RentLivingPictures; ag.IsEdit = true; // 画像編集Windowを開く OpenRentLivingImageWindow?.Invoke(this, ag); }
public void PictureAddCommand_Execute() { if (RentLivingEdit == null) { return; } var files = _openDialogService.GetOpenPictureFileDialog("物件写真の追加"); if (files != null) { foreach (String filePath in files) { string fileName = filePath.Trim(); if (!string.IsNullOrEmpty(fileName)) { FileInfo fi = new FileInfo(fileName); if (fi.Exists) { // 画像データの読み込み FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); // Imageオブジェクトに読み込み。 System.Drawing.Image img = System.Drawing.Image.FromStream(fs, false, false); // 検証なしが早い。https://www.atmarkit.co.jp/ait/articles/0706/07/news139.html // ByteArrayに変換 byte[] ImageData = Methods.ImageToByteArray(img); // サムネイル画像の作成 System.Drawing.Image thumbImg = Methods.FixedSize(img, 130, 87); // ByteArrayに変換 byte[] ImageThumbData = Methods.ImageToByteArray(thumbImg); // RentLivingPictureオブジェクトを用意 RentLivingPicture rlpic = new RentLivingPicture(RentLivingEdit.RentId, RentLivingEdit.RentLivingId, Guid.NewGuid().ToString()); rlpic.PictureData = ImageData; rlpic.PictureThumbData = ImageThumbData; rlpic.PictureFileExt = fi.Extension; // 画面閉じる際の確認用のフラグ。 rlpic.IsNew = true; // DBに保存する為のフラグ。 rlpic.IsModified = true; // ビットマップImageに変換(表示用) rlpic.Picture = Methods.BitmapImageFromImage(img, Methods.FileExtToImageFormat(rlpic.PictureFileExt)); rlpic.PictureThumb = Methods.BitmapImageFromImage(thumbImg, Methods.FileExtToImageFormat(rlpic.PictureFileExt)); // 物件の画像リストに追加。 //RentLivingEdit.RentLivingPictures.Add(rlpic); fs.Close(); // 画像編集Windowへ渡す為のArgをセット OpenRentLivingImageWindowEventArgs ag = new OpenRentLivingImageWindowEventArgs(); ag.Id = rlpic.RentPictureId; ag.RentLivingPictureObject = rlpic; ag.RentLivingPictures = RentLivingEdit.RentLivingPictures; ag.IsEdit = false; // 画像編集Windowを開く OpenRentLivingImageWindow?.Invoke(this, ag); } } } } }