01.
private
void
DisplayImage(
string
ImagePath)
02.
{
03.
byte
[] imageBytes = Security.DecryptStream(ImagePath, SecretKey);
04.
05.
Image myImage = Image.FromStream(
new
MemoryStream(imageBytes));
06.
Size fitImageSize = ScaledImageDimensions(myImage.Width, myImage.Height, PictureBox1.Width, PictureBox1.Height);
07.
Bitmap imgOutput =
new
Bitmap(myImage, fitImageSize.Width, fitImageSize.Height);
08.
09.
PictureBox1.Image =
null
;
10.
PictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
11.
PictureBox1.Image = imgOutput;
12.
}
13.
14.
private
Size ScaledImageDimensions(
int
currentImageWidth,
int
currentImageHeight,
int
desiredImageWidth,
int
desiredImageHeight)
15.
{
16.
17.
18.
19.
double
scaleImageMultiplier = 0;
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
if
(currentImageHeight > currentImageWidth)
30.
{
31.
32.
if
(desiredImageHeight > desiredImageWidth)
33.
{
34.
scaleImageMultiplier = (
double
)desiredImageWidth / (
double
)currentImageWidth;
35.
}
36.
else
37.
{
38.
scaleImageMultiplier = (
double
)desiredImageHeight / (
double
)currentImageHeight;
39.
}
40.
}
41.
else
42.
{
43.
44.
if
(desiredImageWidth > desiredImageHeight)
45.
{
46.
scaleImageMultiplier = (
double
)desiredImageWidth / (
double
)currentImageWidth;
47.
}
48.
else
49.
{
50.
scaleImageMultiplier = (
double
)desiredImageHeight / (
double
)currentImageHeight;
51.
}
52.
}
53.
54.
55.
56.
57.
58.
59.
60.
61.
int
outputWidth = (
int
)(currentImageWidth * scaleImageMultiplier);
62.
int
outputHight = (
int
)(currentImageHeight * scaleImageMultiplier);
63.
64.
return
new
Size((currentImageWidth > outputWidth) ? outputWidth : currentImageWidth, (currentImageHeight > outputHight) ? outputHight : currentImageHeight);
65.
}