Does ImageProcessor ImageFactory Load System.Drawing.Image modify by reference argument - imageprocessor

ImageProcessor ImageFactory supports Load method with argument System.Drawing.Image. But Save method does not support similar argument. Is there a way with ImageProcessor ImageFactory to Load a System.Drawing.Image, manipulate the image, e.g., Brightness, then Save the modified image to System.Drawing.Image?

You can't use a reference to the original image since that is tightly bound to the input stream.
You can either.
1. Save to the output stream and use Image.FromStream to create a new image.
2. Use a binary formatter to perform a deep clone of the ImageFactory.Image property https://stackoverflow.com/a/43042865/427899

Related

Updating metadata using Java and iCAFE

This answer explains how to update metadata.
How to manipulate image metadata in ICAFE
I wanted to update both the EXIF and the IPTC sections, retaining existing metadata values. The Metadata.insertExif allows updating EXIF using the update parameter but cannot be used with the Metadata.insertMetadata(metaList, fin,fout) where I have created a List in order to update multiple sections within the metadata (EXIF and IPTC) e.g. List metaList = new ArrayList<>();
I assume I can do it using two passes - once to update EXIF and once to update IPTC. Is there a way to do this in one pass i.e. retrieve existing EXIF and then update EXIF and IPTC?
This library is not a photo editing software in itself so it is hard to find a point where the user can achieve most of the goals they want and in the mean while don't get it two complicated in the implementation. This is how it looks for now.
That said, it is not possible to insert with update more than one metadata at the same time. You can definitely do this in two passes as you mentioned in your question. You can also do it a different way which makes manipulating existing metadata more flexible.
To do that, you can use Metadata.removeMetadata () to remove both Exif and IPTC. This method will keep the removed metadata as return value so you can later do whatever you want to them and then use Metadata.insertMetadata () to insert the new Exif and IPTC back to the intermediate file which has the two metadata removed (if any) in one shot.

Extracting image dimensions in the background with Shrine

I have set up direct uploads to S3 with Shrine. This works great. Among others, I have the following plugins enabled:
Shrine.plugin :backgrounding
Shrine.plugin :store_dimensions
Shrine.plugin :restore_cached_data
Correct me if I'm wrong but image dimensions extraction appears to be done synchronously. If I let the user bulk upload images via Uppy and then persist them all, this seems to be taking a long time.
What I'd like to do is perform image dimensions extraction asynchronously - I don't need the dimensions available for the cached file. If possible, I'd like to do that in the background when the file gets promoted to the store. Is there a way to do it?
The way I got this to work is by making use of :refresh_metadata plugin, instead of :restore_cached_data which I used originally. Thanks to Janko for pointing me in the right direction.
Reading into the source code provided some useful insights. :store_dimensions plugin by itself doesn't extract dimensions - it adds width and height to the metadata hash so that when Shrine's base class requests metadata, they get extracted too.
By using :restore_cached_data, this was being done on every assignment. :restore_cached_data uses :refresh_metadata internally so we can use that knowledge to only call it when the file is promoted to the store.
I have :backgrounding and :store_dimensions set up in the initializer so the final uploader can be simplified to this:
class ImageUploader < Shrine
plugin :refresh_metadata
plugin :processing
process(:store) do |io, context|
io.refresh_metadata!(context)
io
end
end
This way persisting data we get from Uppy is super fast and we let the background job extract dimensions when the file is promoted to the store, so they can be used later.
Finally, should you have questions related to Shrine, I highly recommend its dedicated Google Group. Kudos to Janko for not only creating an amazing piece of software (seriously, go read the source), but also for his dedication to supporting the community.

Which format to use for a shader resource view into depth-stencil buffer resource?

The depth-stencil buffer resource is defined as DXGI_FORMAT_D24_UNORM_S8_UINT format.
I would have assumed that to create a shader resource view (SRV) into that resource would require the view format to be described either as:
DXGI_FORMAT_R24_UNORM_X8_TYPELESS where red channel accesses depth value
DXGI_FORMAT_R24G8_TYPELESS where red channel accesses depth and green channel stencil value
However, creating such SRV fails with the following error:
D3D12 ERROR: ID3D12Device::CreateShaderResourceView: For the resource format D24_UNORM_S8_UINT, when making a D3D view, the format name for the view can't be R24_UNORM_X8_TYPELESS. See documentation for the set of valid view format names for this resource format, determining which how the resource (or part of it) will appear to shader. [ STATE_CREATION ERROR #28: CREATESHADERRESOURCEVIEW_INVALIDFORMAT]
Looking into API doc yielded me with the following piece of information:
When viewing a resource, the resource-view description must specify a typed format, that is compatible with the resource format. So that means that you can't create a resource-view description using any format with _TYPELESS in the name. You can however view a typeless resource by specifying a typed format for the view.
I don't really understand why a typeless format is not allowed and which format should I use instead?
It is the opposite, you create the resource with typeless components and you specialize the resource in a view with the final representation you need. Since you gave the resource stencil a uint representation already, you are stuck with it.

Create a file with Windows Property Store (metadata) using win32 API

I'd like to create a new stub file "test.mp3" for instance, and add a Window Property to it ( System.Author for instance).
the solution must be usable for several file extension as text, picture, videos, etc...
If I just create a file and use IShellItem2::GetPropertyStore I get a HRESULT fail for invalid Arguments.
Use IShellItem2::GetPropertyStore on a real music file I can read and write Its properties just fine.
Please test your suggestions first.
Property Stores typically access and store data within the file itself. In your case of a mp3 file, it would be attempting to read and write the ID3 tags. Also, Property Stores are not stored in a database and cannot be arbitrarily added to files that don't support it.
You'll most likely need to implement your own property handlers to do what it appears you're trying to accomplish. For types that already have handlers, you'll have to replace the system handlers with your own.
The most likely reason your mp3 test is failing is that you have an empty file with no data and no valid ID3 tags.

asp.net MVC memory stream DICOM image to session variable

I am generating images on fly from DICOM files using:
public ActionResult Generatemage()
{
FileContentResult data;
.....
objImage = im.Bitmap(outputSize, PixelFormat.Format24bppRgb, m);
using (var memStream = new MemoryStream())
{
objImage.Save(memStream, ImageFormat.Png);
data = this.File(memStream.GetBuffer(), "image/png");
}
return data;
}
Can I store the image as a session variable so I can modify it using Point3D?
I tried to use:
Bitmap data = (Bitmap)Session["newimage"];
Got these two errors:
Cannot implicitly convert type 'System.Drawing.Bitmap' to 'System.Web.Mvc.FileContentResult' and
A local variable named 'data' is already defined in this scope
I would appreciate your suggestions, thanks in advance.
Can I store the image as a session variable so I can modify it using
Point3D?
I suggest to not do that. If you have not read Nathanael's post on image resizing pitfalls then I suggest you do so now. It may be talking about resizing but it also give hints on working with images in general. On point #3 it says:
Serving a file from disk by loading it into memory. Think about how
much RAM your server has, how large a single image is, how long it has
to stay in memory before users fi downloading it, and how many
users you have requesting images.
In your particular case you can replace "before users finish downloading it" with "before Point3D finish processing the image". So, what I suggest is that you get a handle to that file, say maybe there's an Id that uniquely identifies a file per user, use that Id to retrieve the file when it's time to process it with Point3D, load it into a MemoryStream (assuming Point3D can work with mem. stream), process it, then dispose of it. In that manner you are only holding on to the image for the duration of "Point3D processing".
Cannot implicitly convert type 'System.Drawing.Bitmap' to
'System.Web.Mvc.FileContentResult' and A local variable named 'data'
is already defined in this scope
That is most probably because you have defined data as such:
FileContentResult data;
and then you are doing a:
Bitmap data = (Bitmap)Session["newimage"];
same variable of two different types within the same scope.

Resources