mirror of
https://github.com/Stone-Red-Code/Markdowser.git
synced 2026-09-04 09:06:15 +02:00
Add common image processor
This commit is contained in:
@@ -39,6 +39,9 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Update="Views\Content\CommonImageContentView.axaml.cs">
|
||||||
|
<DependentUpon>CommonImageContentView.axaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Update="Views\Content\MarkdownContentView.axaml.cs">
|
<Compile Update="Views\Content\MarkdownContentView.axaml.cs">
|
||||||
<DependentUpon>MarkdownContentView.axaml</DependentUpon>
|
<DependentUpon>MarkdownContentView.axaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using Markdowser.ViewModels;
|
||||||
|
using Markdowser.ViewModels.Content;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Markdowser.Processing.Processors;
|
||||||
|
internal class CommonImageProcessor : IContentProcessor
|
||||||
|
{
|
||||||
|
public bool CanProcess(HttpContentHeaders httpContentHeaders)
|
||||||
|
{
|
||||||
|
return httpContentHeaders.ContentType?.MediaType?.StartsWith("image/") == true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ContentViewModelBase> Process(HttpResponseMessage httpResponseMessage, IProgress<ProcessingProgress> progress)
|
||||||
|
{
|
||||||
|
return new CommonImageContentViewModel(httpResponseMessage.RequestMessage?.RequestUri?.Host?.ToString() ?? "Image", await httpResponseMessage.Content.ReadAsStreamAsync());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using Avalonia.Media.Imaging;
|
||||||
|
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Markdowser.ViewModels.Content;
|
||||||
|
internal class CommonImageContentViewModel(string title, Stream stream) : ContentViewModelBase(title)
|
||||||
|
{
|
||||||
|
public Bitmap Image { get; set; } = Bitmap.DecodeToHeight(stream, 1080);
|
||||||
|
}
|
||||||
@@ -167,6 +167,7 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||||||
content = DefaultContent;
|
content = DefaultContent;
|
||||||
|
|
||||||
contentProcessorManager.RegisterProcessor(new HtmlProcessor());
|
contentProcessorManager.RegisterProcessor(new HtmlProcessor());
|
||||||
|
contentProcessorManager.RegisterProcessor(new CommonImageProcessor());
|
||||||
|
|
||||||
GlobalState.UrlChanged += (sender, url) =>
|
GlobalState.UrlChanged += (sender, url) =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<UserControl xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:vm="using:Markdowser.ViewModels"
|
||||||
|
xmlns:cmd="using:Markdowser.Commands"
|
||||||
|
xmlns:utils="using:Markdowser.Utilities"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
|
xmlns:md="https://github.com/whistyun/Markdown.Avalonia"
|
||||||
|
xmlns:ctxt="clr-namespace:ColorTextBlock.Avalonia;assembly=ColorTextBlock.Avalonia"
|
||||||
|
x:DataType="vm:Content.CommonImageContentViewModel"
|
||||||
|
x:Class="Markdowser.Views.Content.CommonImageContentView">
|
||||||
|
|
||||||
|
<Grid>
|
||||||
|
<Image Source="{Binding Image}"/>
|
||||||
|
</Grid>
|
||||||
|
</UserControl>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using Avalonia.Controls;
|
||||||
|
|
||||||
|
namespace Markdowser.Views.Content;
|
||||||
|
|
||||||
|
public partial class CommonImageContentView : UserControl
|
||||||
|
{
|
||||||
|
public CommonImageContentView()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user