Rank: Advanced Member
Groups: Guest
Joined: 5/10/2006(UTC) Posts: 32
Thanks: 6 times
|
I'm trying to use the pipeline to tile an image multiple times, after resizing it to the tile size. Using the code below, I get the error Code: Aurigma.GraphicsMill.Codecs.PngReader is included into pipeline more than once.
Code: void Main()
{
int lengthInch = 96;
int widthInch = 24;
int dpi = 300;
using (var reader = ImageReader.Create(@"\\Centrics\Development\MI_TestImages\TestSwatches\ColorTestChart_ARGB_300.png"))
using (var generator = new ImageGenerator(widthInch * dpi, lengthInch * dpi, PixelFormat.Format24bppRgb, RgbColor.White))
using (var writer = new PngWriter($@"C:\temp\Repeat{DateTime.Now.ToString("yyMMdd-hhmmss")}.png"))
{
generator.DpiX = dpi;
generator.DpiY = dpi;
var newImageWidth = widthInch * dpi;
var newImageHeight = (int)(newImageWidth * (reader.Width / reader.Height));
using (var resizer = new Resize(newImageWidth, newImageHeight, ResizeInterpolationMode.Anisotropic9))
{
var resized = (reader + resizer).Build();
Aurigma.GraphicsMill.Pipeline results = new Pipeline();
results += generator;
List<Combiner> combiners = new List<Combiner>();
for (int yOffset = 0; yOffset < (lengthInch * dpi); yOffset += newImageHeight)
{
var combiner = new Combiner(CombineMode.Alpha);
combiner.TopImage = resized;
combiner.X = 0;
combiner.Y = yOffset;
combiners.Add(combiner);
results += combiner;
}
results += writer;
results.Run();
foreach(var part in combiners)
{
part.Dispose();
}
}
}
}
How can I reuse the resized image and combine it with the background generated image providing an offset?
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 9/19/2006(UTC) Posts: 505
Was thanked: 41 time(s) in 41 post(s)
|
Hello Todd,
Unfortunately, it is impossible.
You need to create a separate PngReader for each tile. I would consider using a tile as a Bitmap, if you don’t expect it to be too large. Because many readers, especially with resizers, will also give some memory footprint. |
Best regards, Eugene Kosmin The Aurigma Development Team
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 5/10/2006(UTC) Posts: 32
Thanks: 6 times
|
I updated the code to create the tile Bitmap before, and add that one bitmap to all the combiners, and that returns a PipelineException Aurigma.GraphicsMill.Bitmap is included into pipeline more than once. So I changed it to load, resize, and save the bitmap to be tiled to a memory stream and then created separate bitmaps per combiner. Using new Bitmaps for each blew up the memory to almost 5Gb I switched it to ImageReader.Create(tileMS) for each combiner, and the memory didn't peak above ~836Mb (when viewed in task manager) Code:void Main()
{
int lengthInch = 96;
int widthInch = 24;
int dpi = 300;
int tileHeight;
using (MemoryStream tileMS = new MemoryStream())
{
using (var source = new Aurigma.GraphicsMill.Bitmap(@"\\Centrics\Development\MI_TestImages\TestSwatches\ColorTestChart_ARGB_300.png"))
{
var newImageWidth = widthInch * dpi;
var newImageHeight = (int)(newImageWidth * (source.Width / source.Height));
tileHeight = newImageHeight;
using (var resizer = new Resize(newImageWidth, newImageHeight, ResizeInterpolationMode.Anisotropic9))
{
using (var tileImage = resizer.Apply(source))
{
tileImage.Save(tileMS, new BmpSettings());
}
}
}
using (var generator = new ImageGenerator(widthInch * dpi, lengthInch * dpi, PixelFormat.Format24bppRgb, RgbColor.White))
using (var writer = new PngWriter($@"C:\temp\Repeat{DateTime.Now.ToString("yyMMdd-hhmmss")}.png"))
{
generator.DpiX = dpi;
generator.DpiY = dpi;
Aurigma.GraphicsMill.Pipeline results = new Pipeline();
results += generator;
List<Combiner> combiners = new List<Combiner>();
for (int yOffset = 0; yOffset < (lengthInch * dpi); yOffset += tileHeight)
{
var combiner = new Combiner(CombineMode.Alpha);
combiner.TopImage = ImageReader.Create(tileMS); //new Bitmap(tileMS);
combiner.X = 0;
combiner.Y = yOffset;
combiners.Add(combiner);
results += combiner;
}
results += writer;
results.Run();
foreach (var part in combiners)
{
part.AutoDisposeTopImage = true;
part.Dispose();
}
}
}
}
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 9/19/2006(UTC) Posts: 505
Was thanked: 41 time(s) in 41 post(s)
|
Todd, could you post here your source image, or its dimensions? |
Best regards, Eugene Kosmin The Aurigma Development Team
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 5/10/2006(UTC) Posts: 32
Thanks: 6 times
|
Here is the file in question.
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 9/19/2006(UTC) Posts: 505
Was thanked: 41 time(s) in 41 post(s)
|
Probably, this way is the best you can do for your task. You can also try to add more compression to the image stream using zip. In my case, it gives ~250 Mb in peaks. Code:tileImage.Save(tileMS, new TiffSettings() {Compression = CompressionType.Zip });
|
Best regards, Eugene Kosmin The Aurigma Development Team
|
|
|
|
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.