本文介绍了InkPicture控件 - 如何将墨迹和图像保存到图像文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过文章证明墨水可以与背景图像一起保存,以便墨水重叠在图像上,然后保存为单个图像文件。但是,不幸的是,我所看到的文章没有详细说明它是如何完成的。
我可以使用以下语句轻松保存背景图像:

I've seen articles demonstrating that the ink can be saved with the background image so that the ink is overlayed onto the image and then saved as a single image file. But, unfortunately the articles I've seen don't go into any detail about how it is done.I can save the background image easy enough with the following statement:

axInkPicture1.Picture.Save(@"\path\to\file.gif");

...但背景图片上没有墨水重叠

...but there is no ink overlayed onto the background image

我不知道有任何保存墨水的直接方法,但这就是我目前的做法:

I don't know of any direct method to save the ink, but this is how I am currently doing it:

string tempPath = Path.GetTempPath();
string tempFile = tempPath + @"\file.gif";
// save to a temp file
if (axInkPicture1.Ink.Strokes.Count > 0)
    {
        byte[] bytes = (byte[])axInkPicture1.Ink.Save(InkPersistenceFormat.IPF_GIF, InkPersistenceCompressionMode.IPCM_Default);

        using (MemoryStream ms = new MemoryStream(bytes))
        {
            using (Bitmap gif = new Bitmap(ms))
            {
                gif.Save(tempFile);
            }
        }

    }

此节省墨水,但没有背景图片。

This saves the ink, but there is no background image.

如何将墨水和图像保存到一个文件中?

How do I save both the ink and image into a single file?

感谢任何帮助或方向指示...

Any help or direction pointing is appreciated...

这是我到目前为止所尝试的其他内容

Here is what else I have tried so far

 InkRectangle inkBox = axInkPicture1.Ink.GetBoundingBox();
        byte[] gifbits = (byte[])axInkPicture1.Ink.Save(InkPersistenceFormat.IPF_GIF, InkPersistenceCompressionMode.IPCM_Default);
        using (System.IO.MemoryStream buffer = new System.IO.MemoryStream(gifbits))
        using (var inkImage = new Bitmap(buffer))
        using (var picture = new Bitmap(axInkPicture1.Picture))
        using (var g = Graphics.FromImage(picture))
        {
            g.DrawImage(inkImage, new Rectangle(inkBox.Left, inkBox.Right, axInkPicture1.Picture.Width, axInkPicture1.Height));
            picture.Save(tempFile, System.Drawing.Imaging.ImageFormat.Gif);
        }

...但我仍然没有运气。这样只保存背景图片而不保存墨水。我有什么想法吗?

...but I'm still not having any luck. This saves only the background picture and not the ink. Any ideas what I'm doing wrong?

提前致谢

推荐答案

我想我没有足够的50个评论的声誉,所以我会回答这个评论给其他人可能会像我一样在google搜索之后落在这里:

I guess I don't have enough 50 reputation to comment, so I will answer with this comment for others that might land here after a google search like I did:

这非常有帮助。我翻译成VB并且它工作了。

This was very helpful. I translated to VB and it worked.

在我发现DLL后,我发现了DLL:

After some flailing around I found the DLL at:

C: \Program Files(x86)\ Common Files\Microsoft Shared\Ink\Microsoft.Ink.dll

C:\Program Files (x86)\Common Files\Microsoft Shared\Ink\Microsoft.Ink.dll

显然我并不是唯一拥有定位DLL的问题,因为有许多谷歌条目如何获得它 - 许多是错误的,大多数都不是这么简单。

Apparently I am not the only one to have a problem locating the DLL as there are many google entries on how to get it -- many are wrong and most are not this simple.

如果你刚开始签名捕获,记得向控件添加背景图像,否则它将在此行失败:

If you are just starting out with signature capture, remember to add a background image to your control or it will fail on this line:

使用bmp =新位图(InkPicture1.BackgroundImage)

Using bmp = New Bitmap(InkPicture1.BackgroundImage)

这篇关于InkPicture控件 - 如何将墨迹和图像保存到图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 00:27