save and close images without asking - dm-script

I try to write some code to save and close top 7 images, as it is below, but when I execute the code, the DM still ask “Save changes to xxx before closing? What command or code I need to add then the code can automatically save the changes of top 7 images without any pop-up ask window. Thanks
image temp:=getfrontimage()
string imgname=getname(temp)
string currentpath, currentdirectory
if(!SaveAsDialog("Save As",imgname,currentpath))exit(0)
currentdirectory=pathextractdirectory(currentpath,2)
number i
string newname, startstring
for(i=0; i<7; i++)
{
image front:=getfrontimage()
string imgname=getname(front)
string thispath=pathconcatenate(currentdirectory, imgname)
saveasgatan(front, thispath)
hideimage(front)
closeimage(front)
}

If you want to remove an image from memory, you can delete it rather than close it. The following removes the front most image without prompting:
image img := GetFrontImage()
DeleteImage( img )
It is also good to know that image objects are the actual data array, but imageDocuments are the objects which are linked to file and window. It is therefore a command of the imageDocument class which is needed. To close an image (or rather it's imageDocument) without asking to save, you can use:
image img := GetFrontImage()
imageDocument iDoc = img.ImageGetOrCreateImageDocument()
iDoc.ImageDocumentClose( 0 ) // parameter is Boolean for "askToSave"
There is also a command to get you the front most imageDocument right away, so you may also use:
GetFrontImageDocument().ImageDocumentClose(0)

Related

How can i show the image name when i taking a picture?

Im trying to show the name of the image i take with my Camera but i dont know how.
Do i need a another function to show the image name?
My Code for taking picture:
Public Function takePicture() As String
Dim url = THETA_URL & "commands/execute"
Dim payload = New Dictionary(Of Object, Object) From {
{"name", "camera.takePicture"}
}
Dim request As Net.WebRequest = Net.WebRequest.Create(url)
request.Credentials = New Net.NetworkCredential(THETA_ID, THETA_PASSWORD)
Dim resp As Net.WebResponse = request.GetResponse()
End Function
See the line where is says:
End Function
Look in the line numbers margin; next to it there is a blank bar (mine is dark gray in my theme) - click in it to put a red dot:
End Function will go red too..
Then run your code and retrieve your image. The code will stop with a yellow bar pointing to End Function
Take a look at the bottom of VS - you'll either have an Autos window or a Locals window - either one will do. It will show the response object and you can drill into it like a tree, open the headers collection, have a look if anything in it contains the data you want.. It also thus tells you how to get the data you want out of it..
e.g. if I wanted the "Content-Disposition" value I could say resp.Headers("Content-Disposition") - AllKeys is showing me what available strings I can use to index the headers collection
Content-Disposition probably won't list a filename on its own - it'll be something more involved like "attachment; filename=someimage.jpg" so you'll need to pull the data you want out of it. Don't get your hopes up if this is a basic cam; it's unlikely to have any meaningful sort of filename. It might be IMG_0001 etc, if it's there at all - I think you should instead make your own name up, as you'll be able to put more info into it, it will be more meaningful than what you get from the cam (and if the cam doesn't send a filename you'll have to do it anyway)

How do you add a picture to the ID3 Album tag using taglib#

I've been searching the internet and trying various methods to save a picturbox image to the the id3 Album picture tag. One sample code says the Album cover tag name is taglib.ipicture another says taglibVariable.Image and yet another says taglibVariable.picture(0).
I am becoming so confused I'm starting to repeat sample test code.
Where is the documentation that will explain what I have to do.?
What little information I can find are dead links to sample code or incomplete code using variables without explanations. When I look up the commands and try to format or convert to the needed data type, I get an error. Usually system.image.bmp cannot be converted to iPicture.
Can anyone give me some working code or a pointer on how to word the proper search term to add a picturebox.image to the Album picture tag. Saving the image as a file then opening as image to put in tag then deleting file is not an option. I need to create a memory image and add that to the picture tag.
This is what I use:
public void SavePicture(string fileName, string picName) {
try {
IPicture[] pics = new TagLib.IPicture[1];
pics[0] = new TagLib.Picture(picName);
using (var songTag = TagLib.File.Create(fileName)) {
songTag.Tag.Pictures = pics;
songTag.Save();
}
}
catch {
// process
// mpeg header is corrupt
}
}
fileName is the full path to the audio file;
picName is the full path to the picture.
You can add multiple pics by setting the array size for the IPicture array accordingly...

what is the difference between DeleteImage() and closeImage()?

If I use DeleteImage() within a thread versus CloseImage(), there seems to be a difference - but I can only guess. Does anyone have a clear definition?
More detail:
Within the thread, an image A has an ROI. If the user deletes the ROI, I also want to close the image A, but still use it again later in the thread.
It seems that when I use A.deleteImage(), I have to redefine that image, whereas if I use A.CloseImage() - I don't.
It looks like that is what is happening, but if anyone knows for sure, please let me know.
Thanks
In order to undestand the commands you need to understand how memory objects are managed.
Anything will remain a valid memory object as long as there is a valid reference to it.
In case of images, this tanslates to:
An image will stay in memory as long as at least one of the following
is true:
The image is displayed on the screen
A script variable points to the image
Any other DM routine has a variable that points to the image
A single image can have multiple of the above conditions fulfilled at the same time. The only way to remove an image from memory is, to ensure all references to it are removed.
For displayed images this means to "close" the display. As a user, you would click the "X" of the window. The same functionality is invoked by the script command CloseImage(). Note that using this command on an image which isn't displayed, doesn't do anything. Note further, that closing an image does not remove any variables or their references to this image.
For script variables this mean you somehow have to "unlink" the variable from the image. (The opposite from using := to assing it.). This is done with the DeleteImage() command. Alternatively, one could also direclty assign the variable to the NULL-pointer as in img := NULL
For held references from DM there is nothing you can do, and you shouldn't. If a certain routine requires an image to be there, it will remain. You may be able to close the Display, but you can never remove it. That's why you can often 'find' images, and even show them using their label. Camera refernece images are a good example for this, but there are others as well.
Visually:
With the explanation given above, you should be able to understand the different behavior in the following examples:
void CloseTest( number ShowItFirst )
{
image img := realImage( "Test", 4, 100, 100 )
Result( "\n Assignment: Image is valid:" + img.ImageIsValid() )
if ( ShowItFirst )
{
img.ShowImage()
Result( "\n Displaying: Image is valid:" + img.ImageIsValid() )
}
img.CloseImage()
Result( "\n Closing: Image is valid:" + img.ImageIsValid() )
img.ShowImage()
Result( "\n Displaying: Image is valid:" + img.ImageIsValid() )
}
void DeleteTest( number ShowItFirst )
{
image img := realImage( "Test", 4, 100, 100 )
Result( "\n Assignment: Image is valid:" + img.ImageIsValid() )
if ( ShowItFirst )
{
img.ShowImage()
Result( "\n Displaying: Image is valid:" + img.ImageIsValid() )
}
img.DeleteImage() // This is the same as: img := NULL
Result( "\n Deleting: Image is valid:" + img.ImageIsValid() )
// img.ShowImage() // This fails, because image is no longer valid!
}
It should now also be clear, why one can use CloseImage( A ) but not DeleteImage( A ) for a displayed image of label A:
The first command only wants to close the image display of the image which is referenced by the label. The second, however, wants to 'unlink' the script variable from the image. But the label 'A' is not a script-variable!

VB.NET - How to correctly load a resource icon with API

I need to extract an icon resource from a file. I have a structure (Resource) that contains the byte array, size, find handle, load handle, lock handle (from FindResource, LoadResource and LockResource, respectively).
I know that I need to obtain the Icon handle of my icon. Then I need to use GetIconInfo to retrieve the bit-mask. Then I use Image.FromHbitmap(h) to get an image. I then use the dimensions of the image as parameters to CreateIconFromResourceEx to retrieve a properly sized Icon.
Does anyone have some code to do this? I can declare all P/Invoke myself. Thanks!
My original code is returning a 32x32 every time.
Dim out As ICONINFO
Dim h As IntPtr = res.hLock
GetIconInfo(h, out)
Dim s As Image = Image.FromHbitmap(out.hbmMask)
h = ResourceExplorer.CreateIconFromResourceEx(res.bArray, res.hSize, True, &H30000, s.Width, s.Height, 0)
PictureBox1.Image = Icon.FromHandle(h).ToBitmap

WinJS / WinRT: detect corrupt image file

I'm building a Win8/WinJS app that loads pictures from the local pictures library. Everything is generally working fine for loading valid images and displaying them in a list view.
Now I need to detect corrupt images and disable parts of the app for those images.
For example, open a text file and enter some text in it. Save the file as .jpg, which is obviously not going to be a valid jpg image. My app still loads the file because of the .jpg name, but now I need to disable certain parts of the app because the image is corrupt.
Is there a way I can check to see if a given image that I've loaded is a valid image file? To check if it's corrupt or not?
I'm using standard WinRT / WinJS objects like StorageFile, Windows.Storage.Search related objects, etc, to load up my image list based on searches for file types.
I don't need to filter out corrupt images from the search results. I just need to be able to tell if an image is corrupt after someone selects it in a ListView.
One possible solution would be to check the image's width and height properties to determine whether it is valid or not.
Yeah, the contentType property will return whatever the file extension is. The best way I can find it to look at the image properties:
file.properties.getImagePropertiesAsync()
.done(function(imageProps) {
if(imageProps.width === 0 && imageProps.height === 0) {
// I'm probably? likely? invalid.
});
where SelectImagePlaceholder is an Image Control.. =)
StorageFile file;
using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
{
try
{
// Set the image source to the selected bitmap
BitmapImage bitmapImage = new BitmapImage();
await bitmapImage.SetSourceAsync(fileStream);
SelectImagePlaceholder.Source = bitmapImage;
//SelectImagePlaceholder.HorizontalAlignment = HorizontalAlignment.Center;
//SelectImagePlaceholder.Stretch = Stretch.None;
this.SelectImagePlaceholder.DataContext = file;
_curMedia = file;
}
catch (Exception ex)
{
//code Handle the corrupted or invalid image
}
}