Tattakashi123 / t

Automatically exported from code.google.com/p/twaindotnet
0 stars 0 forks source link

Converting Image in Sample Project #34

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
A suggestion for your sample app when transferring and converting the image.

If you use the BitmapSource.Create method below it will preserve the resolution 
captured by the scanner. Your current project always renders the bitmap at 96 
dpi.

        void WPFTwainCommands_TransferImage(object sender, TransferImageEventArgs e)
        {
            try
            {
                if (e.Image != null)
                {
                    System.Drawing.Imaging.BitmapData data =
                        e.Image.LockBits(new System.Drawing.Rectangle(0, 0, e.Image.Width, e.Image.Height),
                                         System.Drawing.Imaging.ImageLockMode.ReadOnly, e.Image.PixelFormat);

                    img = BitmapSource.Create(e.Image.Width, e.Image.Height, e.Image.HorizontalResolution,
                                              e.Image.VerticalResolution, PixelFormats.Bgr32, null, data.Scan0, data.Stride*e.Image.Height, data.Stride);
                    e.Image.UnlockBits(data);
...rest of your code.

Original issue reported on code.google.com by ni...@we-solveit.com on 27 Dec 2011 at 7:03