Thanks for Downloading Dynamic Web TWAIN 30-Day Trial!
Your download will start shortly. If your download does not begin, click here to retry.
Image Viewer
How can I insert an image after a selected image in the viewer?
By default, when you scan or load images, they are appended to the end of the image array in buffer. However, in some business scenarios, the user may want to insert these new images to a specified index. Unfortunately, Dynamic Web Twain does not provide a native method for that. The following code snippet shows how this functionality can be implemented.
1. Insert when acquiring
function acquireToIndex(index) {
DWTObject.IfAppendImage = false;
DWTObject.CurrentImageIndexInBuffer = index;
DWTObject.RegisterEvent("OnPostTransfer", function () {
DWTObject.CurrentImageIndexInBuffer++;
});
DWTObject.RegisterEvent("OnPostAllTransfers", function () {
DWTObject.IfAppendImage = true;
});
DWTObject.AcquireImage();
}
2. Insert when loading
function loadToIndex(index) {
var oldCount = DWTObject.HowManyImagesInBuffer;
DWTObject.RegisterEvent("OnPostLoad", function () {
var newCount = DWTObject.HowManyImagesInBuffer;
for (var j = 0; j < newCount - oldCount; j++)
DWTObject.MoveImage(oldCount + j, index + j);
});
DWTObject.LoadImageEx("", 5);
}