Rank: Newbie
Groups: Guest
Joined: 2/7/2019(UTC) Posts: 9
Thanks: 6 times
|
please help, I work on very large graphic files, that's why I use the pipeline method Can this function be used in two stages? stage 1*load image file *change size (to very large) stage 2 (in the loop)*crop big image *save result something like this: Code:
using (var reader = ImageReader.Create("imgFile.jpg"))
using (var resize = new Resize(bigX, bigY))
{
Pipeline.Run(reader + resize);
for (int y = 0; y < 1234; y++)
{
for (int x = 0; x < 123; x++)
{
using (var crop = new Crop(x, y, someWidth, someHeigh))
using (var writer = new JpegWriter(nazwaPliku + ".png"))
Pipeline.Run(crop + writer);
}
}
}
now I use one-step method but it is not effective because unnecessarily every time the graphics are loaded and cropped: Code:
using (var reader = ImageReader.Create("imgFile.jpg"))
using (var resize = new Resize(bigX, bigY))
{
for (int y = 0; y < 1234; y++)
{
for (int x = 0; x < 123; x++)
{
using (var crop = new Crop(x, y, someWidth, someHeigh))
using (var writer = new JpegWriter(nazwaPliku + ".png"))
Pipeline.Run(reader + resize + crop + writer);
}
}
}
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 7/28/2003(UTC) Posts: 1,660
Thanks: 5 times Was thanked: 76 time(s) in 74 post(s)
|
You can use the Receivers collection to build a graph instead of a plain pipeline. Here is a code sample: Code:using Aurigma.GraphicsMill.Codecs;
using Aurigma.GraphicsMill.Transforms;
class Program
{
static void Main(string[] args)
{
using (var reader = ImageReader.Create("../../../in.jpg"))
using (var resize = new Resize(400, 500))
using (var crop1 = new Crop(0, 0, 300, 400))
using (var crop2 = new Crop(100, 100, 200, 150))
using (var writer1 = new JpegWriter("../../../out1.jpg"))
using (var writer2 = new JpegWriter("../../../out2.jpg"))
{
var pipeline = reader + resize;
resize.Receivers.Add(crop1);
crop1.Receivers.Add(writer1);
resize.Receivers.Add(crop2);
crop2.Receivers.Add(writer2);
pipeline.Run();
}
}
}
Please note, you may experience problems if you have 1000s of elements in the graph. So, don't build a very large pipeline. |
Best regards, Fedor Skvortsov
|
1 user thanked Fedor for this useful post.
|
|
|
Rank: Newbie
Groups: Guest
Joined: 2/7/2019(UTC) Posts: 9
Thanks: 6 times
|
thank you very much, now I fully understood how it works. I am very impressed with the performance!previously it took over an hour to process 10,000 "crops"and now less than 5 minutes. I used your hint like this: Code:
using (var reader = ImageReader.Create(fileInput))
{
using (var resize = new Resize(pixX , pixY))
{
var pipeline = reader + resize;
var crops = new List<Crop>();
var writers = new List<JpegWriter>();
for (int y = 0; y < photosOnHeight; y++)
{
for (int x = 0; x < photosOnWidth; x++)
{
crops.Add(new Crop(calcX(x,y), calcY(x,y), calcW(x,y), calcH(x,y)));
writers.Add(new JpegWriter(SaveFileName(x,y)));
}
}
for (int a = 0; a < crops.Count; a++)
{
resize.Receivers.Add(crops[a]);
crops[a].Receivers.Add(writers[a]);
}
pipeline.Run();
for (int b = 0; b < crops.Count; b++)
{
crops[b].Dispose();
writers[b].Dispose();
}
}
}
the code worked even for 100,000 "crops" Edited by user Sunday, November 24, 2019 9:55:21 AM(UTC)
| Reason: update info
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.