How can I modify an XMP meta of a file? - metadata-extractor

I'm interested in seeing if I can modify some XMP within an image file. I'm using the following code:
var items = MetadataExtractor.ImageMetadataReader.ReadMetadata(_filename);
foreach (var item in items)
{
if(item.Name == "XMP")
{
var y = new XmpCore.Impl.XmpMeta();
var xmp = item as MetadataExtractor.Formats.Xmp.XmpDirectory;
foreach(var xd in xmp.XmpMeta.Properties)
{
if(xd.Path == "drone-dji:AbsoluteAltitude")
{
var alt = Convert.ToDecimal(xd.Value.Substring(1,xd.Value.Length-1));
alt -= 100;
xmp.XmpMeta.SetProperty(xd.Namespace, xd.Path, alt.ToString());
}
}
xmp.SetXmpMeta(xmp.XmpMeta);
}
}
I know I'm missing something breathtakingly obvious but I don't know this library well enough to figure it out.
No exceptions come up but when I open up the file the XMP field is still the same. When I iterate thru the xmp properties after I set the property it does reflect correctly but when I end the program the file stays the same. I'm sure there's something to do with writing back to the image path but I have no idea where in this library I do that. Any help would be greatly appreciated.

MetadataExtractor doesn't support modifying files. You can update the data structure, as you show, but there's no way to write those changes back to your original file.

Related

I need to pull the text of an image file name from an array but am only getting "pyimage#" or "tkinter.PhotoImage object at X" as replies

I'm trying to create an array with an assortment of different randomized image files in it to display on a set of buttons in Tkinter. When a given button is clicked I'd like to add the text of that file's name to a new array. Basically, when button with imageX is clicked add "imageX" to a new array.
Unfortunately, I always get a return that isn't the image's filename, or the variable that I've set to correspond to that image, but instead either:
"tkinter.PhotoImage object at X" (where is X is a location like "0x0000020FC894D2E0") if the command is populationbeta.append (population[0])
or
"pyimage#" (where # is an integer that seems to relate to the number of images in the source file), if I change the command to populationbeta.append (str(population[0]))
I feel like there should be a simple way of doing this and I've tried every work around I can think of but I'm not getting it to work. Any help would be very much appreciated! Thanks!
Here's a shortened/simplified version of the code in question:
master=tkinter.Tk()
master.title("Not working")
a1b1c1 = PhotoImage(file = r"C:/users/jdavis319/documents/bushesoflove/BoLdraw/a1b1c1.png")
a1b1c2 = PhotoImage(file = r"C:/users/jdavis319/documents/bushesoflove/BoLdraw/a1b1c2.png")
a1b1c3 = PhotoImage(file = r"C:/users/jdavis319/documents/bushesoflove/BoLdraw/a1b1c3.png")
a1b2c1 = PhotoImage(file = r"C:/users/jdavis319/documents/bushesoflove/BoLdraw/a1b2c1.png")
a1b2c2 = PhotoImage(file = r"C:/users/jdavis319/documents/bushesoflove/BoLdraw/a1b2c2.png")
population = [a1b1c1, a1b1c2, a1b1c3, a1b2c1, a1b2c2]
populationbeta = []
populationbeta.append(population[0])
print(populationbeta)
This gives the result: "[<tkinter.PhotoImage object at 0x000001A419D4F070>]"
This gives the result: "[<tkinter.PhotoImage object at 0x000001A419D4F070>]"
Correct. That shows that you have a list of PhotoImage objects. If you want the filenames you can use .cget('file') on the objects. cget is a common tkinter method for getting the value of a configured option.
filenames = [image.cget('filename') for image in population]
Or, if you don't want to use a list comprehension to create a list of filenames, you can do it on an individual image like so:
populationbeta.append(population[0].cget("file"))

Determining the movieclip assigned to a variable in an array AS3

Please forgive my terminology, Im not educated on the proper.
Lets say I have multiple movieclip variables
var rblock1:MovieClip = new Rblock();
var rblock2:MovieClip = new Rblock();
var rblock3:MovieClip = new Rblock();
var yblock1:MovieClip = new Yblock();
var yblock2:MovieClip = new Yblock();
var yblock3:MovieClip = new Yblock();
I have them added to an array
var blockarray:Array = new Array(rblock1, rblock2, rblock3, yblock1, yblock2, yblock3);
var block
I want to create a for loop with an if statement that triggers if a variable is Rblock and not Yblock, for example
for each (block in blockarray)
{
if (block==Rblock)
{
trace("rblock");
}
}
The issue is that obviously "if (block==Rblock)" doesnt work.
How should this be written?
You apparently want to check if a block is red or yellow by checking against its class name. You can do it with this:
if (block is Rblock) {...} // yes, red
I have figured out a work around not really a perfect solution, which will only work for certain scenarios...
if each class has a unique trait you can identify it that way, for example...
if all variables defined by the Rblock class are wider than the Yblock class you could say
if (block.width>x) { trace(Rblock); }
Like I said this is only a work around though and only works for movieclip variables defined by classes that are different, if anyone has the actual solution please post

Need to figure out how to use DeepZoomTools.dll to create DZI

I am not familiar with .NET coding.
However, I must create DZI sliced image assets on a shared server and am told that I can instantiate and use DeepZoomTools.dll.
Can someone show me a very simple DZI creation script that demonstrates the proper .NET coding technique? I can embellish as needed, I'm sure, but don't know where to start.
Assuming I have a jpg, how does a script simply slice it up and save it?
I can imagine it's only a few lines of code. The server is running IIS 7.5.
If anyone has a simple example, I'd be most appreciative.
Thanks
I don't know myself, but you might ask in the OpenSeadragon community:
https://github.com/openseadragon/openseadragon/issues
Someone there might know.
Does it have to be DeepZoomTools.dll? There are a number of other options for creating DZI files. Here are a few:
http://openseadragon.github.io/examples/creating-zooming-images/
Example of building a Seadragon Image from multiple images.
In this, the "clsCanvas" objects and collection can pretty much be ignored, it was an object internal to my code that was generating the images with GDI+, then putting them on disk. The code below just shows how to get a bunch of images from file and assemble them into a zoomable collection. Hope this helps someone :-).
CollectionCreator cc = new CollectionCreator();
// set default values that make sense for conversion options
cc.ServerFormat = ServerFormats.Default;
cc.TileFormat = ImageFormat.Jpg;
cc.TileSize = 256;
cc.ImageQuality = 0.92;
cc.TileOverlap = 0;
// the max level should always correspond to the log base 2 of the tilesize, unless otherwise specified
cc.MaxLevel = (int)Math.Log(cc.TileSize, 2);
List<Microsoft.DeepZoomTools.Image> aoImages = new List<Microsoft.DeepZoomTools.Image>();
double fLeftShift = 0;
foreach (clsCanvas oCanvas in aoCanvases)
{
//viewport width as a function of this canvas, so the width of this canvas is 1
double fThisImgWidth = oCanvas.MyImageWidth - 1; //the -1 creates a 1px overlap, hides the seam between images.
double fTotalViewportWidth = fTotalImageWidth / fThisImgWidth;
double fMyLeftEdgeInViewportUnits = -fLeftShift / fThisImgWidth; ; //please don't ask me why this is a negative numeber
double fMyTopInViewportUnits = -fTotalViewportWidth * 0.3;
fLeftShift += fThisImgWidth;
Microsoft.DeepZoomTools.Image oImg = new Microsoft.DeepZoomTools.Image(oCanvas.MyFileName.Replace("_Out_Tile",""));
oImg.ViewportWidth = fTotalViewportWidth;
oImg.ViewportOrigin = new System.Windows.Point(fMyLeftEdgeInViewportUnits, fMyTopInViewportUnits);
aoImages.Add(oImg);
}
// create a list of all the images to include in the collection
cc.Create(aoImages, sMasterOutFile);

LoaderMax: setting array as a container (ImageLoader)

So, I have a LoaderMax instance loading images from various URLs. I want to add all loaded images to an array.
Here's my code:
var photosArray:Array = new Array(5);
var imageLoadingQueue:LoaderMax = new LoaderMax({name:"mainQueue", onComplete:completeHandler});
for (var g:uint=0; g<5; g++)
{
imageLoadingQueue.append(new ImageLoader("/img" + g + ".jpg", {name:"photo", container:photosArray[g], noCache:false, smoothing:true, width:126, height:126, scaleMode:"proportionalOutside"}));
}
imageLoadingQueue.load();
private function completeHandler(e:LoaderEvent):void
{
trace("finished loading pictures!");
//the next two lines will return an error (saying that photosArray[1] is null)
stage.addChild(photosArray[1]);
photosArray[1].x = 250;
}
A few problems:
If I set the container of the image being loaded to the Array, it won't work. I'm not being able to access the image inside the array because it says it's null.
If I set the container of the image being loaded to "this" (using the container property when appending a new ImageLoader) and, on the completeHandler, set my array equal to event.target.content, it kinda works (but it's not the ideal). The problem is that, by doing so, the images are appearing on the stage as they are loaded, and I do no want them to do so.
Any help would be heavily appreciated.
Thanks!!
David is correct, but I also wanted to mention that the LoaderMax's "content" is actually an array of all of its children's content, so you could just use that for simplicity. Keep in mind that ImageLoaders automatically create a Sprite (technically called a "ContentDisplay") to drop the image into so you probably don't need to create ANOTHER Sprite (a container for the container).
var photos:Array = imageLoadingQueue.content;
stage.addChild(photos[1]);
The other nice thing is that it creates the ContentDisplay Sprites immediately, even before any content is loaded into them, so you can place them and size them however you want while (or before or after) loading occurs.
The container needs to be a DisplayObjectContainer. ImageLoader will try to add the image to the container using addChild(), so obviously this won't work with an empty array. Create a new Sprite for each image and add it into the array first:
for (var g:uint=0; g<5; g++)
{
photosArray[g] = new Sprite();
imageLoadingQueue.append(new ImageLoader("/img" + g + ".jpg", {name:"photo", container:photosArray[g], noCache:false, smoothing:true, width:126, height:126, scaleMode:"proportionalOutside"}));
}

Using HTMLDocument to manipulate HTML and show it in WebBrowser-control

I am trying to manipulate a requested document in the WPF WebBrowser-control. I already managed it to invoke JavaScript on loaded document, but I am not able to change the shown HTML-code in the control itself.
My (very simplified) code in the OnNavigating-Handler looks like this:
mshtml.HTMLDocument doc = (mshtml.HTMLDocument)View.browser.Document;
HTMLTableClass table = doc.getElementById("someTable") as HTMLTableClass;
if (table != null)
{
table.appendChild((IHTMLDOMNode)(doc.createElement("<tr>") as IHTMLElement));
}
doc.close();
The -element doesn't get appended to displayed document in the control.
Any hints are very appreciated!
I finally got it. Its only possible to change the content of the table by adding rows and cells which i wanted to avoid in first place. My approach was to directly change the content of the -tag, which didnt work.
mshtml.IHTMLTableRow row = table.IHTMLTable_insertRow(-1) as mshtml.IHTMLTableRow;
mshtml.IHTMLElement c = (mshtml.IHTMLElement)row.insertCell(0);
c.innerText = "some";
mshtml.IHTMLElement c1 = (mshtml.IHTMLElement)row.insertCell(1);
c1.innerText = "text";

Resources