getting the properties from an image preview box

aworonow

Well-known member
Hello all,
I've rewritten my question, since the last incarnation got no response:

I need to make a separate image from a preview. Here is the code I'm trying...I've tried others. This was my best guess as to how to do it:

function Supervisor () {
var targetWindow = ImageWindow.activeWindow;
var targetView = targetWindow.mainView;
var previews = targetWindow.previews;

with (Neutralizer) {
// identify the preview that holds the background info
for ( var i = 0; i < previews.length; i++ ) {
if (ReferenceImage.id === previews.id)
console.writeln ("Using preview: ", previews.id);
var LumV = View.viewById(previews.id);
break;
};
...

But it does not work...at least I do not see a new image, even if I add
LumV.window.show();

So, how does one create a new image from a from a preview?
Thanks for the help!!!!
Alex
 
Last edited:
Hi Alex,

Lets write a generic answer to your initial question first, since it is of general interest. A preview is a view, and hence it is represented by the View object in our JavaScript framework. You can get the set of previews defined in a given ImageWindow with the following method:

Array ImageWindow.previews

This method returns an array where each array element is a View object representing one of the previews defined in the image window. For example:

JavaScript:
let window = ImageWindow.activeWindow;
let previews = window.previews;
for ( let i = 0; i < previews.length; ++i )
   console.writeln( previews[i].id );

This function allows you to access a preview if you know its identifier:

View ImageWindow.previewById( String id )

Now your specific question:

So, how does one create a new image from a from a preview?

You need to invoke the following constructor of the ImageWIndow object to do this:

new ImageWindow( int width, int height[, int numberOfChannels[, int bitsPerSample[, Boolean floatSample[, Boolean color[, String id]]]]] )

For example:

JavaScript:
#include <pjsr/UndoFlag.jsh>

let window = ImageWindow.activeWindow;
let preview = window.previewById( "foo" );
if ( !preview.isNull )
{
   let newWindow = new ImageWindow( 1, 1, 1, 32/*bitsPerSample*/, true/*floatSample*/ );
   newWindow.mainView.beginProcess( UndoFlag_NoSwapFile );
   newWindow.mainView.image.assign( preview.image );
   newWindow.mainView.endProcess();
   newWindow.zoomToOptimalFit();
   newWindow.show();
}

Note that the use of the ImageWindow constructor is purely conventional here: we construct an image with a single pixel (hence the 1,1,1 first arguments) in 32-bit floating point format, then we copy the preview's image to the new image with the call to Image.assign().

Let me know if this answers your questions.
 
Excellent...I think I can do it now. After I posted I went down a route like this, only not like this, if you know what I mean. I had a lot of things wrong and may never have gotten there without your help!

Thanks again, Alex
 
Back
Top