diff --git a/TelegramBotBase.Extensions.Images/ImageExtensions.cs b/TelegramBotBase.Extensions.Images/ImageExtensions.cs new file mode 100644 index 0000000..0ae703f --- /dev/null +++ b/TelegramBotBase.Extensions.Images/ImageExtensions.cs @@ -0,0 +1,61 @@ +using System; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using System.Threading.Tasks; +using Telegram.Bot.Types.InputFiles; +using Telegram.Bot.Types; +using TelegramBotBase.Sessions; +using TelegramBotBase.Form; + +namespace TelegramBotBase.Extensions.Images +{ + public static class ImageExtensions + { + public static Stream ToStream(this Image image, ImageFormat format) + { + var stream = new System.IO.MemoryStream(); + image.Save(stream, format); + stream.Position = 0; + return stream; + } + + /// + /// Sends an image + /// + /// + /// + /// + /// + /// + /// + public static async Task SendPhoto(this DeviceSession session, Image image, String name, String caption, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false) + { + using (var fileStream = Tools.Images.ToStream(image, ImageFormat.Png)) + { + InputOnlineFile fts = new InputOnlineFile(fileStream, name); + + return await session.SendPhoto(fts, caption: caption, buttons, replyTo, disableNotification); + } + } + + /// + /// Sends an image + /// + /// + /// + /// + /// + /// + /// + public static async Task SendPhoto(this DeviceSession session, Bitmap image, String name, String caption, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false) + { + using (var fileStream = Tools.Images.ToStream(image, ImageFormat.Png)) + { + InputOnlineFile fts = new InputOnlineFile(fileStream, name); + + return await session.SendPhoto(fts, caption: caption, buttons, replyTo, disableNotification); + } + } + } +} diff --git a/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj b/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj new file mode 100644 index 0000000..aa47dfd --- /dev/null +++ b/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj @@ -0,0 +1,17 @@ + + + + netstandard2.1;net472;net5;netcoreapp3.1;net6 + https://github.com/MajMcCloud/TelegramBotFramework + https://github.com/MajMcCloud/TelegramBotFramework + MIT + + + + + + + + + + \ No newline at end of file diff --git a/TelegramBotBase/Sessions/DeviceSession.cs b/TelegramBotBase/Sessions/DeviceSession.cs index 1238c66..da0a5ed 100644 --- a/TelegramBotBase/Sessions/DeviceSession.cs +++ b/TelegramBotBase/Sessions/DeviceSession.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; -using System.Drawing; -using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Text; @@ -422,44 +420,6 @@ namespace TelegramBotBase.Sessions } } - /// - /// Sends an image - /// - /// - /// - /// - /// - /// - /// - public async Task SendPhoto(Image image, String name, String caption, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false) - { - using (var fileStream = Tools.Images.ToStream(image, ImageFormat.Png)) - { - InputOnlineFile fts = new InputOnlineFile(fileStream, name); - - return await SendPhoto(fts, caption: caption, buttons, replyTo, disableNotification); - } - } - - /// - /// Sends an image - /// - /// - /// - /// - /// - /// - /// - public async Task SendPhoto(Bitmap image, String name, String caption, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false) - { - using (var fileStream = Tools.Images.ToStream(image, ImageFormat.Png)) - { - InputOnlineFile fts = new InputOnlineFile(fileStream, name); - - return await SendPhoto(fts, caption: caption, buttons, replyTo, disableNotification); - } - } - /// /// Sends an video /// diff --git a/TelegramBotBase/TelegramBotBase.csproj b/TelegramBotBase/TelegramBotBase.csproj index 456e344..8a9fb11 100644 --- a/TelegramBotBase/TelegramBotBase.csproj +++ b/TelegramBotBase/TelegramBotBase.csproj @@ -1,9 +1,9 @@  - netstandard2.1;net472;net5;netcoreapp3.1 + netstandard2.1;net472;net5;netcoreapp3.1;net6 false - false + False true https://github.com/MajMcCloud/TelegramBotFramework https://github.com/MajMcCloud/TelegramBotFramework @@ -16,6 +16,9 @@ true true snupkg + $(VersionPrefix) + + @@ -28,7 +31,7 @@ full false bin\Debug\ - DEBUG;TRACE + TRACE;DEBUG prompt 4 @@ -64,10 +67,8 @@ - - diff --git a/TelegramBotBase/Tools/Images.cs b/TelegramBotBase/Tools/Images.cs deleted file mode 100644 index e941884..0000000 --- a/TelegramBotBase/Tools/Images.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Imaging; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace TelegramBotBase.Tools -{ - public static class Images - { - public static Stream ToStream(this Image image, ImageFormat format) - { - var stream = new System.IO.MemoryStream(); - image.Save(stream, format); - stream.Position = 0; - return stream; - } - } -} diff --git a/TelegramBotBaseTest/TelegramBotBaseTest.csproj b/TelegramBotBaseTest/TelegramBotBaseTest.csproj index 3bf6473..0224404 100644 --- a/TelegramBotBaseTest/TelegramBotBaseTest.csproj +++ b/TelegramBotBaseTest/TelegramBotBaseTest.csproj @@ -27,6 +27,7 @@ + diff --git a/TelegramBotFramework.sln b/TelegramBotFramework.sln index f14d7d4..234b44b 100644 --- a/TelegramBotFramework.sln +++ b/TelegramBotFramework.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29324.140 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31912.275 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TelegramBotBase", "TelegramBotBase\TelegramBotBase.csproj", "{0BD16FB9-7ED4-4CCB-83EB-5CEE538E1B6C}" EndProject @@ -18,6 +18,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SystemCommandsBot", "Exampl EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JoinHiderBot", "Examples\JoinHiderBot\JoinHiderBot.csproj", "{E804B9E5-7ACC-49D3-9253-806766C1D9A5}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TelegramBotBase.Extensions.Images", "TelegramBotBase.Extensions.Images\TelegramBotBase.Extensions.Images.csproj", "{B5DDFA45-0E01-46A5-B67D-541300CDD606}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -40,6 +42,10 @@ Global {E804B9E5-7ACC-49D3-9253-806766C1D9A5}.Debug|Any CPU.Build.0 = Debug|Any CPU {E804B9E5-7ACC-49D3-9253-806766C1D9A5}.Release|Any CPU.ActiveCfg = Release|Any CPU {E804B9E5-7ACC-49D3-9253-806766C1D9A5}.Release|Any CPU.Build.0 = Release|Any CPU + {B5DDFA45-0E01-46A5-B67D-541300CDD606}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B5DDFA45-0E01-46A5-B67D-541300CDD606}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B5DDFA45-0E01-46A5-B67D-541300CDD606}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B5DDFA45-0E01-46A5-B67D-541300CDD606}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE