// -------------------------------------------------------------------- // サムネイル生成 // -------------------------------------------------------------------- private static Thumbnail?CreateThumbnail(String moviePath, String imageFileName, Int32 maxWidth, Int32 maxHeight) { try { using FileStream sourceStream = new FileStream(imageFileName, FileMode.Open); return(new Thumbnail { Path = moviePath, Bitmap = ServerCommon.CreateThumbnail(sourceStream, ServerConstants.MIME_TYPE_PNG, maxWidth, maxHeight, false), Mime = ServerConstants.MIME_TYPE_PNG, LastModified = YbdCommon.DateTimeToModifiedJulianDate(ServerCommon.LastModified(imageFileName)), }); } catch (Exception excep) { Debug.WriteLine("サムネイル作成エラー:\n" + excep.Message); Debug.WriteLine(" スタックトレース:\n" + excep.StackTrace); return(null); } }
// ==================================================================== // private メンバー関数 // ==================================================================== #if DEBUGz // ==================================================================== // デバッグ専用 // ==================================================================== // -------------------------------------------------------------------- // サムネイル生成テスト // -------------------------------------------------------------------- private static void TestCreateThumbnail() { // 横長・縮小あり using FileStream y1 = new FileStream(ServerConstants.FOLDER_NAME_SAMPLE_DATA_IMAGES + "Test_430x177.png", FileMode.Open); File.WriteAllBytes("TestGen_430x177_square.png", ServerCommon.CreateThumbnail(y1, ServerConstants.MIME_TYPE_PNG, MOVIE_THUMB_WIDTH_MAX, MOVIE_THUMB_HEIGHT_MAX, true)); File.WriteAllBytes("TestGen_430x177_rect.png", ServerCommon.CreateThumbnail(y1, ServerConstants.MIME_TYPE_PNG, MOVIE_THUMB_WIDTH_MAX, MOVIE_THUMB_HEIGHT_MAX, false)); // 横長・縮小なし using FileStream y0 = new FileStream(ServerConstants.FOLDER_NAME_SAMPLE_DATA_IMAGES + "Test_150x62.png", FileMode.Open); File.WriteAllBytes("TestGen_150x62_square.png", ServerCommon.CreateThumbnail(y0, ServerConstants.MIME_TYPE_PNG, MOVIE_THUMB_WIDTH_MAX, MOVIE_THUMB_HEIGHT_MAX, true)); File.WriteAllBytes("TestGen_150x62_rect.png", ServerCommon.CreateThumbnail(y0, ServerConstants.MIME_TYPE_PNG, MOVIE_THUMB_WIDTH_MAX, MOVIE_THUMB_HEIGHT_MAX, false)); // 縦長・縮小あり using FileStream t1 = new FileStream(ServerConstants.FOLDER_NAME_SAMPLE_DATA_IMAGES + "Test_250x468.png", FileMode.Open); File.WriteAllBytes("TestGen_250x468_square.png", ServerCommon.CreateThumbnail(t1, ServerConstants.MIME_TYPE_PNG, MOVIE_THUMB_WIDTH_MAX, MOVIE_THUMB_HEIGHT_MAX, true)); File.WriteAllBytes("TestGen_250x468_rect.png", ServerCommon.CreateThumbnail(t1, ServerConstants.MIME_TYPE_PNG, MOVIE_THUMB_WIDTH_MAX, MOVIE_THUMB_HEIGHT_MAX, false)); // 縦長・縮小なし using FileStream t0 = new FileStream(ServerConstants.FOLDER_NAME_SAMPLE_DATA_IMAGES + "Test_43x80.png", FileMode.Open); File.WriteAllBytes("TestGen_43x80_square.png", ServerCommon.CreateThumbnail(t0, ServerConstants.MIME_TYPE_PNG, MOVIE_THUMB_WIDTH_MAX, MOVIE_THUMB_HEIGHT_MAX, true)); File.WriteAllBytes("TestGen_43x80_rect.png", ServerCommon.CreateThumbnail(t0, ServerConstants.MIME_TYPE_PNG, MOVIE_THUMB_WIDTH_MAX, MOVIE_THUMB_HEIGHT_MAX, false)); }