-
Notifications
You must be signed in to change notification settings - Fork 1
/
CScannedImage.cs
89 lines (76 loc) · 2.48 KB
/
CScannedImage.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing.Imaging;
using System.Drawing;
namespace Snapsy
{
public class CScannedImage
{
private Bitmap baseImage;
private Bitmap thumbnail;
public static int thumbnailWidth = 256;
public static int thumbnailHeight = 256;
private CScanSettings.BitDepth bitDepth;
public CScanSettings.BitDepth BitDepth
{
get { return bitDepth; }
set { bitDepth = value; }
}
public Bitmap Thumbnail
{
get
{
return thumbnail;
}
}
public Bitmap BaseImage
{
get { return baseImage; }
set { baseImage = value; thumbnail = null; }
}
private Bitmap resizeBitmap(Bitmap b, int nWidth, int nHeight)
{
Bitmap result = new Bitmap(nWidth, nHeight);
Graphics g = Graphics.FromImage((Image)result);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
if (b.Width > b.Height)
{
double nheight = (double)b.Height * ((double)nWidth / (double)b.Width);
double ntop = ((double)nHeight - nheight) / 2;
g.DrawImage(b, 0, (int)ntop, nWidth, (int)nheight);
}
else
{
double nwidth = (double)b.Width * ((double)nHeight / (double)b.Height);
double nleft = ((double)nWidth - nwidth) / 2;
g.DrawImage(b, (int)nleft, 0, (int)nwidth, nHeight);
}
g.Dispose();
return result;
}
public CScannedImage()
{
}
public CScannedImage(Bitmap img, CScanSettings.BitDepth BitDepth)
{
baseImage = (Bitmap)img.Clone();
thumbnail = resizeBitmap(img, thumbnailWidth, thumbnailHeight);
if (bitDepth == CScanSettings.BitDepth.BLACKWHITE)
{
baseImage = CImageHelper.CopyToBpp((Bitmap)img, 1);
img.Dispose();
}
else
{
baseImage = img;
}
this.BitDepth = BitDepth;
}
internal void RotateFlip(RotateFlipType rotateFlipType)
{
baseImage.RotateFlip(rotateFlipType);
thumbnail = resizeBitmap(baseImage, thumbnailWidth, thumbnailHeight);
}
}
}