Comments (8)
The Clone()
method creates of copy of the pixels of the input image and then resizes that to the new dimensions. Here is an example what it does with the memory (the numbers are made up but should give you an idea of what happens):
flowchart TD
A[Create image] --> B[10 mb used]
B --> C[Clone]
C --> D[20 mb used]
D --> E[Resize to 50%]
B --> F[Resize without clone]
E --> G[15 mb used]
F --> G
This means that with the new method the maximum amount of memory that is used is 15mb.
from magick.net.
In theory this could be possible for methods of ImageMagick that return a new image. It's an interesting idea but I will need to think about an API for this. And that will probably happen after I have added a new source code generator to call the native api.
from magick.net.
Sounds good, I look forward to it.
from magick.net.
Do you have any ideas how I could/should integrate this in the API? I think this behavior would only be required for methods that change the dimensions of an image. Otherwise you could just use .Clone()
and change the image. I am now thinking about something like this:
using var image = new MagickImage("input.png");
using var thumbnail = image.NewMethod().Resize(100, 100);
using var thumbnail = image.NewProperty.Resize(100, 100);
The NewMethod()
or NewProperty
would return an interface that includes a the methods that change the dimensions of the image. But the disadvantage of this would be the discoverability in the api. So I am also thinking about something like this:
using var image = new MagickImage("input.png");
using var thumbnail = image.ResizeWithSuffix(100, 100);
As you can see besides deciding which option to use the naming is also something that I have to think about. Do you have any suggestions?
from magick.net.
Not sure how feasible this is, and I realize this is adding to the original requirement, but the ideal for me would be something like this:
IMagickImage<QuantumType> CloneCropAndResize(IMagickGeometry? crop, IMagickGeometry? resize)
Where:
crop
specifies which portion of the source image to grab. If null, the entire source imageresize
specifies how to resize it into a new image instance. If null, no resizing.
ie: it would be the equivalent of the following but internally would combine all this into a single resize operation without the overhead of the full clone at the start.
image.Clone().Crop(crop).Resize(resize);
The nice thing about this is it would let you grab any region at any resolution. ie: you could grab tiled sections of a source image at display resolutions for rendering.
The name CloneCropAndResize
is a bit wordy but sums up what it's doing. Alternative suggestion: ExtractImage
, or maybe ExtractSubImage
?
from magick.net.
Those are not the only two methods this option will become available to. Creating a new method for each possible combination is not feasible.
from magick.net.
Ah ok, I see what you mean.
Perhaps NewMethod()
could be CloneThen()
.
var newImage = image.CloneThen().Resize(100, 100);
I guess the downside to this is it might be tempting to chain these together fluent style, but the result of the Crop call wouldn't be disposed.
var newImage = image
.CloneThen().Crop(10, 10, 1000, 1000)
.CloneThen().Resize(100, 100)
Thinking out loud (again no idea if this is feasible) but what if you could put together a chain of operations which you terminated with a function to actually do the work. ie: each intermediate operation just returned an interface (not an image instance) upon which you could perform additional operations. The Process()
call at the end walks the chain of operations and produces a final image.
eg:
var newImage = image
.CloneThen()
.Crop(10, 10, 1000, 1000)
.Resize(100, 100)
.Whatever()
.SomethingElse()
.Process();
You're obviously thinking about this from a broader perspective than my narrow view... I'm sure whatever you come up with will be fine.
from magick.net.
Good question. But I don’t think that new methods are needed, because it's already supported quite simply:
using MagickImage image = new MagickImage(inputStream);
using MagickImage thumbnail = image.Clone() as MagickImage;
thumbnail.Resize(100, 100);
from magick.net.
Related Issues (20)
- EXR images with more than 4 channels return the first 4 channels only HOT 2
- Hope to support converting ESP files to PNG format HOT 4
- Slowness in MagickImage Object Creation
- Some way to detect folder in Pds format
- Add support for Fx operation on multiple images
- Since Magick.NET 13.6.0, images resized are much heavier HOT 9
- `MagickImage.GetColorProfile()` returns non-null value for GIF without color profile HOT 1
- How to ignore unknown tiff Tag(32934 , etc) when use MagickImage open such tiff image ? HOT 5
- MagicFormat enum values change in 13.7.0 HOT 3
- colors.xml missing? HOT 1
- Possible bug with forced casting on IChannelPerceptualHash HOT 3
- EXIF Orientation was Changed when Call AutoOrient() and Save. HOT 3
- Probable bug with TemporaryMagickFormat? HOT 1
- Setting ResourceLimits.Thread does not work. Value stays the same HOT 3
- Create ToImageSource() method similar to ToBitmapSource() to support WinAppSDK Images
- Pixel cache does not seem to be garbage collected HOT 1
- Writing WebP-Files on ARM-Container with auto orient fails HOT 19
- Support for JXL thumbnail/preview in new lossy DNG file format HOT 3
- Error 504 when convert ARW to jpg HOT 1
- BitmapFrame.Create() throws ArgumentException: 'Value does not fall within the expected range.' when XmpProfile is set HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from magick.net.