forked from devhawk/cppwinrt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.cpp
More file actions
66 lines (54 loc) · 2 KB
/
App.cpp
File metadata and controls
66 lines (54 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "pch.h"
using namespace winrt;
using namespace Windows::ApplicationModel::Activation;
using namespace Windows::Foundation;
using namespace Windows::UI;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::Storage;
using namespace Windows::Storage::Streams;
using namespace Windows::Graphics::Imaging;
using namespace Windows::Media::Ocr;
using namespace Windows::Storage::Pickers;
struct App : ApplicationT<App>
{
void OnLaunched(LaunchActivatedEventArgs const &)
{
TextBlock block;
block.FontFamily(FontFamily(L"Segoe UI Semibold"));
block.FontSize(72.0);
block.Foreground(SolidColorBrush(Colors::Orange()));
block.VerticalAlignment(VerticalAlignment::Center);
block.TextAlignment(TextAlignment::Center);
block.TextWrapping(TextWrapping::Wrap);
Window window = Window::Current();
window.Content(block);
window.Activate();
Async(block);
}
fire_and_forget Async(TextBlock block)
{
FileOpenPicker picker;
picker.FileTypeFilter().Append(L".png");
picker.SuggestedStartLocation(PickerLocationId::PicturesLibrary);
auto file = co_await picker.PickSingleFileAsync();
if (file == nullptr)
{
return;
}
apartment_context ui_thread;
co_await resume_background();
auto stream = co_await file.OpenAsync(FileAccessMode::Read);
auto decoder = co_await BitmapDecoder::CreateAsync(stream);
auto bitmap = co_await decoder.GetSoftwareBitmapAsync();
auto engine = OcrEngine::TryCreateFromUserProfileLanguages();
auto result = co_await engine.RecognizeAsync(bitmap);
co_await ui_thread;
block.Text(result.Text());
}
};
int __stdcall wWinMain(HINSTANCE, HINSTANCE, PWSTR, int)
{
Application::Start([](auto &&) { make<App>(); });
}