0

我用 TWAIN 扫描了一张双面图像,它得到了一组图片,我可以单独保存它们。我需要将这两个图像并排组合并将其保存为单个 TIFF 文件。

你能告诉我如何打开 TIFF 图像并将它们保存为一个文件,并排包含它们吗?

4

2 回答 2

1

您是否正在根据 TWAIN 规范编写自己的应用程序?如果是,您可以使用 TWFF_TIFFMULTI 获取多页 TIFF 文件。

于 2012-06-05T03:14:31.960 回答
0
var tmpFolder = _configManager.TmpFolder;
bool isUnHandleException;
//tranfer each image that's scann0ed and insert him to array,also dialogbox for a progress bar Indication  
ArrayList pics = tw.TransferPictures(out isUnHandleException);
EndingScan(); tw.CloseSrc();
if (isUnHandleException)   ShowException(Consts.RestartWIA);

string strFileName = "";
// join all the images that's scanned  to one image tiff file
var encoder = new TiffBitmapEncoder();
BitmapFrame frame=null;
Bitmap bp = null;
IntPtr bmpptr,pixptr;
if (!(pics != null && pics.Count != 0))
{
    ShowException("No Has Any pages");
    return;
}
// create temp folder 
CreateDirectory(tmpFolder);
int picsCount = pics.Count;
for (int i = 0; i < pics.Count; i++)
{
    IntPtr img = (IntPtr)pics[i];
    //Locks a global memory object and returns a pointer to the first byte of the object's memory block 
    bmpptr = Twain.GlobalLock(img);
    //Get Pixel Info by handle
    pixptr = GdiWin32.GetPixelInfo(bmpptr);
    // create bitmap type
    bp = GdiWin32.BitmapFromDIB(bmpptr, pixptr);

    // get bitmap frame for insert him TiffBitmapEncoder
    frame = Imaging.GetBitmapFrame(bp);
    if (frame != null)
        encoder.Frames.Add(frame);
    //decease pointer reference so the gc will see there is no refernce to this obj and realse him from memory
    Twain.GlobalUnlock(img);
    // Get the last error and display it.
    //int error = Marshal.GetLastWin32Error();

    GC.Collect();
    GC.WaitForPendingFinalizers();
}
// genrate file name to temp folder 
strFileName = GenerateFileTemp(tmpFolder);
string strNewFileName = strFileName;
_output = new FileStream(strNewFileName, FileMode.OpenOrCreate);
encoder.Save(_output);
于 2013-06-04T15:41:35.767 回答