裁剪图像到护照大小 [英] Crop Image to Passport size

查看:87
本文介绍了裁剪图像到护照大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们好!


我需要帮助才能为我的项目实现一个autocrop功能,因为我完全混淆并且不知道如何开始。所以我的目标是创建ID大小和正确定位的脸部图像。捕获图片是自动的,工作正常,它以jpeg格式输出
图像。我可以使用面部跟踪器来确定眼睛的坐标或面部长度或宽度。脸部应在中间,脸部长度在32-36毫米之间。



以下是保存img的一些代码示例:



  String filename = @" C:\ Users \Admin \Desktop\FotostudioBilder \" ;;

     ;                   的FileStream流=新的FileStream(文件名+ DateTime.Now.ToString(QUOT; YYYYMMDD_HHMMSS")+" .JPG" ;,
FileMode.Create);

   &NBSP ;                    JpegBitmapEncoder encoder = new JpegBitmapEncoder();

                        的TextBlock myTextBlock =新的TextBlock();

                         myTextBlock.Text =" Codec Author is:" + encoder.CodecInfo.Author.ToString();

               &NBSP ;        encoder.FlipHorizo​​ntal = TRUE;

                         encoder.FlipVertical = FALSE;

                         encoder.QualityLevel = 30;

                        日期时间Tthen = DateTime.Now;

                 &NBSP ;     做

                    &NBSP ;   {

                    &NBSP ;       System.Windows.Forms.Application.DoEvents();

                         }而(Tthen.AddSeconds(1.5)> DateTime.Now);

                             encoder.Frames.Add(BitmapFrame.Create(latest_img));

                             encoder.Save(stream);


我非常感谢所有有用的答案并感谢你的帮助!

解决方案

< blockquote>


据我所知,你可以在WPF中定义一个图像片段,使用Geometry(例如,EllipseGeometry来设置元素的Clip属性)。只有几何区域内的区域才可见。



您可以保存剪裁后的图像,如下所示。 

 RenderTargetBitmap renderTargetBitmap = 
new RenderTargetBitmap((int)image.ActualWidth,(int)image.ActualHeight,96,96,PixelFormats.Default);

renderTargetBitmap.Render(image);

PngBitmapEncoder encoder = new PngBitmapEncoder();

encoder.Frames.Clear();

encoder.Frames.Add(BitmapFrame.Create(renderTargetBitmap));

使用(FileStream fs = File.Create(@" xxx"))
{
encoder.Save(fs);
}


您还可以使用 <裁剪图像a href ="https://msdn.microsoft.com/en-us/library/system.windows.media.imaging.croppedbitmap(v=vs.85)\"style =""> CroppedBitmap


https://msdn.microsoft.com/en-us/library/ms752345%28v=vs.85%29?f=255&MSPPError=-2147217396


最好的问候,


Bob


Hello friends!

I need help to implement an autocrop function to my project as I´m completly confused and don´t really know how to start. So my goal is to create ID sized and right positioned images of faces. The capture of the picture is automatic and works fine it puts the images out in jpeg format. I can get with use of a face tracker the coordinates of the eyes for or the face length or width. The face should be in the middle and the length of the face between 32-36 mm.

Here is some code example for saving the img:

 String filename = @"C:\Users\Admin\Desktop\FotostudioBilder\";
                        FileStream stream = new FileStream(filename + DateTime.Now.ToString("yyyyMMdd_hhmmss") + ".jpg", FileMode.Create);
                        JpegBitmapEncoder encoder = new JpegBitmapEncoder();
                        TextBlock myTextBlock = new TextBlock();
                        myTextBlock.Text = "Codec Author is: " + encoder.CodecInfo.Author.ToString();
                        encoder.FlipHorizontal = true;
                        encoder.FlipVertical = false;
                        encoder.QualityLevel = 30;
                        DateTime Tthen = DateTime.Now;
                        do
                        {
                            System.Windows.Forms.Application.DoEvents();
                        } while (Tthen.AddSeconds(1.5) > DateTime.Now);
                            encoder.Frames.Add(BitmapFrame.Create(latest_img));
                            encoder.Save(stream);

Im very thankful for all useful answers and appreciate your help!!

解决方案

Hi,

As far as know, you can define a image clip in WPF, use a Geometry (for example, an EllipseGeometry to set the element's Clip property). Only the area that is within the region of the geometry will be visible.

You can save the clipped image as below. 

 RenderTargetBitmap renderTargetBitmap =
                new RenderTargetBitmap((int)image.ActualWidth, (int)image.ActualHeight, 96, 96, PixelFormats.Default);

            renderTargetBitmap.Render(image);

            PngBitmapEncoder encoder = new PngBitmapEncoder();

            encoder.Frames.Clear();

            encoder.Frames.Add(BitmapFrame.Create(renderTargetBitmap));

            using (FileStream fs = File.Create(@"xxx"))
            {
                encoder.Save(fs);
            }

.

You can also crop an image using CroppedBitmap.

https://msdn.microsoft.com/en-us/library/ms752345%28v=vs.85%29?f=255&MSPPError=-2147217396

Best Regards,

Bob


这篇关于裁剪图像到护照大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆