First release of IronSoftware drawing extension
This commit is contained in:
parent
26152ee348
commit
ad40675b87
@ -0,0 +1,73 @@
|
||||
using IronSoftware.Drawing;
|
||||
using SixLabors.ImageSharp;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot.Types;
|
||||
using TelegramBotBase.Form;
|
||||
using TelegramBotBase.Sessions;
|
||||
using static IronSoftware.Drawing.AnyBitmap;
|
||||
using SKImage = SixLabors.ImageSharp.Image;
|
||||
|
||||
namespace TelegramBotBase.Extensions.Images.IronSoftware
|
||||
{
|
||||
public static class ImageExtensions
|
||||
{
|
||||
public static Stream ToStream(this AnyBitmap image, ImageFormat format)
|
||||
{
|
||||
var stream = new MemoryStream();
|
||||
image.ExportStream(stream, format);
|
||||
stream.Position = 0;
|
||||
return stream;
|
||||
}
|
||||
|
||||
public static async Task<Stream> ToStream(this SKImage image)
|
||||
{
|
||||
var stream = new MemoryStream();
|
||||
await image.SaveAsPngAsync(stream);
|
||||
stream.Position = 0;
|
||||
return stream;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends an image
|
||||
/// </summary>
|
||||
/// <param name="image"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="buttons"></param>
|
||||
/// <param name="replyTo"></param>
|
||||
/// <param name="disableNotification"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Message> SendPhoto(this DeviceSession session, AnyBitmap image, string name,
|
||||
string caption, ButtonForm buttons = null, int replyTo = 0,
|
||||
bool disableNotification = false)
|
||||
{
|
||||
using (var fileStream = ToStream(image, ImageFormat.Png))
|
||||
{
|
||||
var fts = InputFile.FromStream(fileStream, name);
|
||||
|
||||
return await session.SendPhoto(fts, caption, buttons, replyTo, disableNotification);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends an image
|
||||
/// </summary>
|
||||
/// <param name="image"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="buttons"></param>
|
||||
/// <param name="replyTo"></param>
|
||||
/// <param name="disableNotification"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Message> SendPhoto(this DeviceSession session, SKImage image, string name,
|
||||
string caption, ButtonForm buttons = null, int replyTo = 0,
|
||||
bool disableNotification = false)
|
||||
{
|
||||
using (var fileStream = await ToStream(image))
|
||||
{
|
||||
var fts = InputFile.FromStream(fileStream, name);
|
||||
|
||||
return await session.SendPhoto(fts, caption, buttons, replyTo, disableNotification);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
7
TelegramBotBase.Extensions.Images.IronSoftware/README.md
Normal file
7
TelegramBotBase.Extensions.Images.IronSoftware/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
# TelegramBotBase.Extensions.Images.IronSoftware
|
||||
|
||||
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Images.IronSoftware/)
|
||||
[](https://www.t.me/tgbotbase)
|
||||
|
||||
[](https://raw.githubusercontent.com/MajMcCloud/TelegramBotFramework/master/LICENCE.md)
|
||||
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Images.IronSoftware)
|
||||
@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net6</TargetFrameworks>
|
||||
<RepositoryUrl>https://github.com/MajMcCloud/TelegramBotFramework</RepositoryUrl>
|
||||
<PackageProjectUrl>https://github.com/MajMcCloud/TelegramBotFramework</PackageProjectUrl>
|
||||
<Copyright>MIT</Copyright>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="IronSoftware.System.Drawing" Version="2024.1.1" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="TelegramBotBase" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -32,7 +32,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotAndWebApplication", "Exa
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InlineAndReplyCombination", "Examples\InlineAndReplyCombination\InlineAndReplyCombination.csproj", "{067E8EBE-F90A-4AFF-A0FF-20578216486E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DependencyInjection", "Examples\DependencyInjection\DependencyInjection.csproj", "{689B16BC-200E-4C68-BB2E-8B209070849B}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DependencyInjection", "Examples\DependencyInjection\DependencyInjection.csproj", "{689B16BC-200E-4C68-BB2E-8B209070849B}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TelegramBotBase.Extensions.Images.IronSoftware", "TelegramBotBase.Extensions.Images.IronSoftware\TelegramBotBase.Extensions.Images.IronSoftware.csproj", "{DC521A4C-7446-46F7-845B-AAF10EDCF8C6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -84,6 +86,10 @@ Global
|
||||
{689B16BC-200E-4C68-BB2E-8B209070849B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{689B16BC-200E-4C68-BB2E-8B209070849B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{689B16BC-200E-4C68-BB2E-8B209070849B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{DC521A4C-7446-46F7-845B-AAF10EDCF8C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DC521A4C-7446-46F7-845B-AAF10EDCF8C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DC521A4C-7446-46F7-845B-AAF10EDCF8C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DC521A4C-7446-46F7-845B-AAF10EDCF8C6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -98,6 +104,7 @@ Global
|
||||
{52EA3201-02E8-46F5-87C4-B4752C8A815C} = {BFA71E3F-31C0-4FC1-A320-4DCF704768C5}
|
||||
{067E8EBE-F90A-4AFF-A0FF-20578216486E} = {BFA71E3F-31C0-4FC1-A320-4DCF704768C5}
|
||||
{689B16BC-200E-4C68-BB2E-8B209070849B} = {BFA71E3F-31C0-4FC1-A320-4DCF704768C5}
|
||||
{DC521A4C-7446-46F7-845B-AAF10EDCF8C6} = {E3193182-6FDA-4FA3-AD26-A487291E7681}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {59CB40E1-9FA7-4867-A56F-4F418286F057}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user