How to Convert IPicture to Image - .NET 4.5 TagLib Sharp - .net-4.5

I am wanting to display the album artwork of a song (accessed via the taglib-sharp library) within a Windows Forms picture box. The problem I'm running into is that the taglib-library returns an image of type TagLib.IPicture whereas the picture box requires an object of type System.Drawing.Image.
I have scoured the internet for many hours now, looking for a way to convert from an IPicture to Image, but to no avail. The best lead I have is this: http://msdn.microsoft.com/en-us/library/system.windows.forms.axhost.getpicturefromipicture.aspx, but I have yet to see a successful example of how to implement this.
Any help as to how to convert between these two types would be much appreciated. Note: IPicture is not analogous to IPictureDisp in this case.

I've done the opposite before - turning an existing .jpg into an IPicture for embedding in an .mp3 file. I just tried reversing that operation and, after tweaking and testing, came up with this:
TagLib.File tagFile = TagLib.File.Create(mp3FilePath);
MemoryStream ms = new MemoryStream(tagFile.Tag.Pictures[0].Data.Data);
System.Drawing.Image image = System.Drawing.Image.FromStream(ms);
Thanks for the question - I already know how I'm going to use this myself!
Update: Here's the other way (.jpg to IPicture that I've done before):
tagFile.Tag.Pictures = new TagLib.IPicture[]
{
new TagLib.Picture(new TagLib.ByteVector((byte[])new System.Drawing.ImageConverter().ConvertTo(System.Drawing.Image.FromFile(jpgFilePath), typeof(byte[]))))
};

Related

keep/copy XMP with libexif

I try to add a thumbnail to a JPEG picture using libexif.
For now I'm borrowing the code from exif (the command line tool that is shipped by the libexif team).
However I noticed the XMP tags get deleted from the metadata. There is an old bugreport here.
I tried to see how to achieve this anyway with libexif but I don't really understand how to get the XMP from input file and put it in the output file. I just want to copy all XMP data, I don't need to extract anything of it.
I saw there is a TAG EXIF_TAG_XML_PACKET in exif_tag.h but couldn't figure out how to read/write this tag.
A related solution is in this SO answer but it looks complicated. I'm not familiar coding in C.
Is it actually possible to keep all XMP when using only libexif API? Have things changed in recent years on that? How would you write this in code?
Thanks
I believe it should be somewhat straightforward. XMP fields are described in the ISO/Adobe standard. Regular Kotlin/Java/Android file I/O and some string manipulation should be all that is required.
I would start out by becoming intimately familiar with ISO 16684-1:2019. Then, write a method for your jpeg file class that grabs all the XMP fields. Store those fields in a temp file (to prevent difficult to recover data loss in the event of your code or libexif crashing). Hand the file off to libexif. Generate the thumbnail. Finally, when that's done you can restore the XMP fields. If the thumbnail is stored in an XMP field as well (and it sounds like it is), it may be easier to concatenate that field with the other ones which were already grabbed, updating the temp file so that it contains EVERY XMP field, before adding all of the XMP fields back to the jpeg.
Unfortunately, I do not currently have the time to read a 50 page ISO standard, synthesize the information, and then write the code to implement the solution. Here's a link to the standard at least, to get you started.
https://www.iso.org/obp/ui/#iso:std:iso:16684:-1:ed-2:v1:en

In Powershell with Taglib#, how get xiph Rating value for Flac file?

OK, I have exhausted my (somewhat limited) abilities in Powershell to try to do this. I am hoping someone can help.
I am happily using taglib-sharp for various tags - getting and setting - for Flac and MP3. But, I cannot figure out how to get or set the RATING tag value that is stored in the xiph tags.
The closest I come is this:
$tags = [taglib.file]::create("d:\songs\ASong.flac")
$xiph = $tags.gettag("xiph")
$xiph then contains the list of tags but no values. It's Powershell type is XiphComment.
Help? Thanks
PS: I would also like to get the Rating value on MP3 so if the solution above isn't easily translatable for those please provide tips. I currently retrieve Rating for MP3 through the Windows Shell namespace "GetDetailsOf" but would prefer to use taglib#.

Dicominfo not giving all metadata

I have a dicom from a GE MRI scanner and there are a few pieces of information in the header I require (namely the relative position of the scan). I tried using info = dicominfo(filename) but, for some reason, this piece of information does not show up. I know that this information is saved, however. It might be a private data, but I'm not completely sure. If anyone has any information on how to resolve this issue that would be greatly appreciated.
Try using the dicomread function instead, it should be more versatile than dicominfo and it reads the information files too. If this doesn't work then it means that the information you are trying to obtain is not made available by GE.
Or use gdcm to dump the private GE header:
$ gdcmdump --pdb input.dcm

phpThumb is not setting parameter – fltr[] usm

I am using Brett's Mr. PHP thumb caching script along with phpThumb to create my thumbs. It works extremely well, except for one thing... I cannot get it to set and process the UnSharpMask filter. The relevant part of the script looks like this:
// generate the thumbnail
require('../phpthumb/phpthumb.class.php');
$phpThumb = new phpThumb();
$phpThumb->setSourceFilename($image);
$phpThumb->setParameter('w',$width);
$phpThumb->setParameter('h',$height);
$phpThumb->setParameter('q','95'); // set the quality to 95%
$phpThumb->setParameter('fltr[]','usm|80|0.5|3'); // <--- THIS SHOULD SET THE USM FILTER
$phpThumb->setParameter('f',substr($thumb,-3,3)); // set the output file format
if (!$phpThumb->GenerateThumbnail()) {
error('cannot generate thumbnail');
}
I'm guessing there's a problem with my syntax, since the fltr[] parameter requires brackets. I have tried escaping the brackets like so: 'fltr[]' but that didn't work either.
I've used several other possible parameters with good success (zoom cropping, max height, max width, etc...) Everything seems to work except the filters (including usm - UnSharpMask).
I don't get any errors. It spits out thumbs all day long. They're just not sharpened.
For reference, here's the official phpThumb readme file that discusses all the possible settings and filters.
Thanks for looking.
Well after much trial, error, and aggravation, I finally discovered the solution buried in one of the demo files that come with phpThumb.
It's a matter of removing the brackets all together. Basically changing this line:
$phpThumb->setParameter('fltr[]','usm|80|0.5|3');
to this:
$phpThumb->setParameter('fltr','usm|80|0.5|3');
After that, it's only a matter of tweaking the settings to get the desired amount of sharpness.

How do I use IPTC/EXIF metadata to categorise photos?

Many photo viewing and editing applications allow you to examine and change EXIF and IPTC data in JPEG and other image files. For example, I can see things like shutter speed, aperture and orientation in the picture files that come off my Canon A430. There are many, many name/value pairs in all this metadata. But...
What do I do if I want to store some data that doesn't have a build-in field name. Let's say I'm photographing an athletics competition and I want to tag every photo with the competitor's bib number. Can I create a "bib_number" field and assign it a values of "0001", "5478", "8124" etc, and then search for all photos with bib_number="5478"?
I've spent a few hours searching and the best I can come up with is to put this custom information in the "keywords" field but this isn't quite what I'm after. With this socution I'd have to craft a query like "keywords contains bib_number_5478" whereas what I want it "bib_number is 5478".
So do the EXIF and/or IPTC standards allow addtional user-defined field names?
Thanks
Kev
It can be used for that, but it really shouldn't: it's meant to be user-editable and so isn't a safe place to put critical metadata. Using an XMP sidecar is better for this kind of thing: in XMP, any field added that a given app does not understand is, according to the standard, supposed to be ignored by that app and not destroyed.
I don't know if there are applications to do this but by the standards described for JPEG files there is a field called Comments where you can assign values that could act like tags.
C# code:
using System.Windows.Media.Imaging;
using System.IO;
...
FileStream fs = new FileStream(#"<img_path>", FileMode.Open, FileAccess.ReadWrite);
BitmapMetadata bmd = (BitmapMetadata)BitmapFrame.Create(fs).Metadata;
bmd.Comment = "Some Comment Here";
also if you are looking for an application that already has this functionality built into it, then might i recommend Irfan View (open pic, go to Image menu, click on Comments button).
Hope this helps.