-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Artem Sulimov
committed
Jun 3, 2021
0 parents
commit 3c70f9a
Showing
5 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bin | ||
obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Drawing; | ||
using System.Drawing.Drawing2D; | ||
using System.Drawing.Imaging; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading; | ||
|
||
namespace TestImages | ||
{ | ||
static class Program | ||
{ | ||
static byte[] _jpegBytes; | ||
static EventWaitHandle _evt = new AutoResetEvent(false); | ||
static bool _running = true; | ||
|
||
static void Main(string[] args) | ||
{ | ||
int imagesOnCollage = int.Parse(args.FirstOrDefault() ?? "10"); | ||
int aCollageDrawingPeriodMs = int.Parse(args.Skip(1).FirstOrDefault() ?? "100"); | ||
|
||
//ThreadPool.SetMinThreads(100, 100); | ||
|
||
Console.CancelKeyPress += (s, e) => | ||
{ | ||
_running = false; | ||
e.Cancel = true; | ||
}; | ||
|
||
_jpegBytes = File.ReadAllBytes("image.jpg"); | ||
|
||
while (_running) | ||
{ | ||
var sw = Stopwatch.StartNew(); | ||
DrawCollageImages(imagesOnCollage); | ||
int spent = (int)sw.Elapsed.TotalMilliseconds; | ||
int left = aCollageDrawingPeriodMs - spent; | ||
if (left < 0) left = 0; | ||
Thread.Sleep(left); | ||
} | ||
|
||
_evt.Dispose(); | ||
} | ||
|
||
static void DrawCollageImages(int count) | ||
{ | ||
ThreadPool.QueueUserWorkItem(_ => | ||
{ | ||
Console.WriteLine("thread id {0,4}, threads count {1,3}", | ||
Thread.CurrentThread.ManagedThreadId, ThreadPool.ThreadCount); | ||
using (var collage = new Bitmap(1000, 1000)) | ||
{ | ||
DrawCollageImagesImpl(collage, count); | ||
} | ||
_evt.Set(); | ||
Thread.Sleep(20000); // prevent this thread id reuse | ||
} | ||
); | ||
_evt.WaitOne(); | ||
} | ||
|
||
static void DrawCollageImagesImpl(Image collage, int count) | ||
{ | ||
using (var g = Graphics.FromImage(collage)) | ||
{ | ||
g.DrawCollageImages(count); | ||
} | ||
} | ||
|
||
static Rectangle _rect = new Rectangle(0, 0, 500, 500); | ||
|
||
static void DrawCollageImages(this Graphics g, int count) | ||
{ | ||
for (int i=0; i<count; i++) | ||
{ | ||
g.DrawCollageImage(_rect); | ||
} | ||
} | ||
|
||
static void DrawCollageImage(this Graphics g, Rectangle r) | ||
{ | ||
using var ms = new MemoryStream(_jpegBytes); | ||
using var img = Image.FromStream(ms); | ||
g.DrawImage(img, r.X, r.Y, r.Width, r.Height); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="System.Drawing.Common" Version="5.0.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="*.jpg"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |