📄 photoeditor.cs
字号:
this.Controls.Add(this.vSb);
this.Controls.Add(this.hSb);
this.Controls.Add(this.pControls);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "PhotoEditor";
this.Text = "PhotoEditor";
this.Resize += new System.EventHandler(this.PhotoEditor_Resize);
this.Closing += new System.ComponentModel.CancelEventHandler(this.PhotoEditor_Closing);
this.Load += new System.EventHandler(this.PhotoEditor_Load);
this.Closed += new System.EventHandler(this.PhotoEditor_Closed);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.PhotoEditor_Paint);
this.pControls.ResumeLayout(false);
this.pButtons.ResumeLayout(false);
this.tabControl1.ResumeLayout(false);
this.tabGen.ResumeLayout(false);
this.tabProp.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numSat)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numGamma)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numCont)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numBright)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.tbSat)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.tbGamma)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.tbCont)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.tbBright)).EndInit();
this.tabResize.ResumeLayout(false);
this.tabCrop.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numTop)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numRight)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numLeft)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numBottom)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void PhotoEditor_Paint(object sender, System.Windows.Forms.PaintEventArgs e) {
DrawPhoto();
}
private void PhotoEditor_Resize(object sender, System.EventArgs e) {
AdjustSBars();
DrawPhoto();
}
private void PhotoEditor_Closed(object sender, System.EventArgs e) {
// save size-related settings
Settings settings = new Settings();
if (this.WindowState == FormWindowState.Maximized)
settings.PhotoEditorMax = true;
else {
settings.PhotoEditorMax = false;
settings.PhotoEditorWidth = this.Width;
settings.PhotoEditorHeight = this.Height;
}
settings.SaveSettings();
// dispose the Image
Image.Dispose();
}
private void tbBright_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) {
numBright.Value = tbBright.Value;
}
private void tbCont_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) {
numCont.Value = tbCont.Value;
}
private void tbGamma_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) {
numGamma.Value = tbGamma.Value;
}
private void tbSat_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) {
numSat.Value = tbSat.Value;
}
private void numBright_ValueChanged(object sender, System.EventArgs e) {
if (Resetting == false) {
tbBright.Value = (int) numBright.Value;
Image.AdjustBrightness((int) numBright.Value);
DrawPhoto();
bReset.Enabled = true;
ImageChanged = true;
}
}
private void numCont_ValueChanged(object sender, System.EventArgs e) {
if (Resetting == false) {
Image.AdjustContrast((int) numCont.Value);
tbCont.Value = (int) numCont.Value;
DrawPhoto();
bReset.Enabled = true;
ImageChanged = true;
}
}
private void numGamma_ValueChanged(object sender, System.EventArgs e) {
if (Resetting == false) {
Image.AdjustGamma((int) numGamma.Value);
tbGamma.Value = (int) numGamma.Value;
DrawPhoto();
bReset.Enabled = true;
ImageChanged = true;
}
}
private void numSat_ValueChanged(object sender, System.EventArgs e) {
if (Resetting == false) {
Image.AdjustSaturation((int) numSat.Value);
tbSat.Value = (int) numSat.Value;
DrawPhoto();
bReset.Enabled = true;
ImageChanged = true;
}
}
private void bGraysc_Click(object sender, System.EventArgs e) {
if (Resetting == false) {
Image.ConvertToGrayscale();
DrawPhoto();
bReset.Enabled = true;
ImageChanged = true;
}
}
private void bSepia_Click(object sender, System.EventArgs e) {
if (Resetting == false) {
Image.ConvertToSepia();
DrawPhoto();
bReset.Enabled = true;
ImageChanged = true;
}
}
private void bReset_Click(object sender, System.EventArgs e) {
// reset the ui
ResetUi();
// reset the image property values
Image.ResetValues();
// redraw the original image
Image.Reset();
DrawPhoto();
}
private void tbTitle_TextChanged(object sender, System.EventArgs e) {
if (Resetting == false) {
bReset.Enabled = true;
TextChanged = true;
}
}
private void rtbDesc_TextChanged(object sender, System.EventArgs e) {
if (Resetting == false) {
bReset.Enabled = true;
TextChanged = true;
}
}
private void cbChooseFilter_CheckedChanged(object sender, System.EventArgs e) {
cobFilt.Enabled = cbChooseFilter.Checked;
}
private void bResize_Click(object sender, System.EventArgs e) {
// create an interpolation mode var
InterpolationMode im;
// create the sizes var
int nwidth = Convert.ToInt32(tbNWidth.Text);
int nheight = Convert.ToInt32(tbNHeight.Text);
if (cobFilt.Enabled == true) // does the user want to choose the interpolation mode himself?
{
switch (cobFilt.SelectedIndex) {
case 0: im = InterpolationMode.Bicubic;
break;
case 1: im = InterpolationMode.HighQualityBicubic;
break;
case 2: im = InterpolationMode.Bilinear;
break;
case 3: im = InterpolationMode.HighQualityBilinear;
break;
case 4: im = InterpolationMode.NearestNeighbor;
break;
default: im = FindRightInterpolationMode(nwidth, nheight);
break;
}
} else // find the right mode automatically
{
im = FindRightInterpolationMode(nwidth, nheight);
switch (im) {
case InterpolationMode.Bicubic: cobFilt.SelectedIndex = 0;
break;
case InterpolationMode.Bilinear: cobFilt.SelectedIndex = 2;
break;
default:
break;
}
}
// Resize the image and enable the reset button
Image.Resize(nwidth, nheight, im);
bReset.Enabled = true;
ImageChanged = true;
ImageChanged = true;
DrawPhoto();
}
private void bZOut_Click(object sender, System.EventArgs e) {
int sbHPos = -1;
int sbVPos = -1;
if (ZoomLevel - 1 < 1) // if half the current zoom level would be less than 1, set zooming to false and the zoomlevel to 1
{
Zooming = false;
bZOut.Enabled = false;
ZoomLevel = 1;
} else {
ZoomLevel -= 1; // just half the zoomlevel
double modifier = (double) ZoomLevel / (ZoomLevel + 1);
sbHPos = (int) Math.Round(hSb.Value * modifier);
sbVPos = (int) Math.Round(vSb.Value * modifier);
}
bZIn.Enabled = true;
AdjustSBars(); // adjust the scrollBars
if (sbVPos != -1) {
if (sbHPos <= hSb.Maximum) {
if (sbHPos >= hSb.Minimum)
hSb.Value = sbHPos;
else
hSb.Value = hSb.Minimum;
} else
hSb.Value = hSb.Maximum;
if (sbVPos <= vSb.Maximum) {
if (sbVPos >= vSb.Minimum)
vSb.Value = sbVPos;
else
vSb.Value = vSb.Minimum;
} else
vSb.Value = vSb.Maximum;
}
DrawPhoto();
}
private void bZIn_Click(object sender, System.EventArgs e) {
int sbVPos = -1;
int sbHPos = -1;
if (Zooming == false) // if zooming was disabled before, enable it and set the zoom level to display the image's original size
{
Zooming = true;
bZOut.Enabled = true;
ZoomLevel = 1;
if (ZoomLevel == 48) // if we've reached the maximum zoom level disable the ZoomIn button
bZIn.Enabled = false;
} else {
ZoomLevel += 1; // increase the ZoomLevel
double modifier = (double) ZoomLevel / (ZoomLevel - 1);
sbHPos = (int) Math.Round(hSb.Value * modifier);
sbVPos = (int) Math.Round(vSb.Value * modifier);
}
AdjustSBars(); // adjust the scrollBars
if (sbVPos != -1) {
if (sbHPos <= hSb.Maximum) {
if (sbHPos >= hSb.Minimum)
hSb.Value = sbHPos;
else
hSb.Value = hSb.Minimum;
} else
hSb.Value = hSb.Maximum;
if (sbVPos <= vSb.Maximum) {
if (sbVPos >= vSb.Minimum)
vSb.Value = sbVPos;
else
vSb.Value = vSb.Minimum;
} else
vSb.Value = vSb.Maximum;
} else {
hSb.Value = (hSb.Maximum - hSb.Minimum) / 2 + hSb.Minimum;
vSb.Value = (vSb.Maximum - vSb.Minimum) / 2 + vSb.Minimum;
}
DrawPhoto();
}
private void bPrev_Click(object sender, System.EventArgs e) {
if (ImageChanged == true || TextChanged == true) // if the image was changed ask the user if he wished to discard the changes
{
DialogResult dr = GetClosingDR();
if (dr == DialogResult.Yes) {
if (SaveImage() == false)
return;
} else {
if (dr == DialogResult.Cancel)
return;
}
}
if (CurrIndex == 0)
CurrIndex = Photos.Count - 1;
else
CurrIndex--;
Path = "";
OpenPhoto();
}
private void bNext_Click(object sender, System.EventArgs e) {
if (ImageChanged == true || TextChanged == true) // if the image was changed ask the user if he wished to discard the changes
{
DialogResult dr = GetClosingDR();
if (dr == DialogResult.Yes) {
if (SaveImage() == false)
return;
} else {
if (dr == DialogResult.Cancel)
return;
}
}
if (CurrIndex == Photos.Count - 1)
CurrIndex = 0;
else
CurrIndex++;
Path = "";
OpenPhoto();
}
private void bRotRight_Click(object sender, System.EventArgs e) {
if (ImageChanged == true) // if the image was changed ask the user if he wished to discard the changes
{
DialogResult dr = GetClosingDR();
if (dr == DialogResult.Yes) {
if (SaveImage() == false)
return;
} else {
if (dr == DialogResult.Cancel)
return;
}
}
Image.Dispose();
// rotate the image
Resizer r = new Resizer();
if (Path == "" || Path == Photos[CurrIndex].Path) // if the photo is part of an album
{
r.Rotate(Photos[CurrIndex].Path, RotateFlipType.Rotate90FlipNone, 100);
// recreate the thumbnail
PhotosP.RecreateThumbnail(CurrIndex, Photos[CurrIndex]);
} else // just rotate the image
r.Rotate(Path, RotateFlipType.Rotate90FlipNone, 100);
OpenPhoto();
}
private void bRotLeft_Click(object sender, System.EventArgs e) {
if (ImageChanged == true) // if the image was changed ask the user if he wished to discard the changes
{
DialogResult dr = GetClosingDR();
if (dr == DialogResult.Yes) {
if (SaveImage() == false)
return;
} else {
if (dr == DialogResult.Cancel)
return;
}
}
Image.Dispose();
// rotate the image
Resizer r = new Resizer();
if (Path == "" || Path == Photos[CurrIndex].Path) // if the photo is part of an album
{
r.Rotate(Photos[
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -