88 lines
2.9 KiB
C#
88 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Drawing.Imaging;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Security.Policy;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using static McBitFont.MainForm;
|
|
|
|
namespace McBitFont {
|
|
public partial class FrameScreenshot : Form {
|
|
|
|
private FrameMiniature f;
|
|
|
|
public FrameScreenshot(FrameMiniature frame) {
|
|
InitializeComponent();
|
|
f = frame;
|
|
}
|
|
|
|
private Bitmap GenerateScreenshot() {
|
|
int upscale = (int)nudUpscale.Value;
|
|
int x, y;
|
|
bool transp = chkTransparent.Checked;
|
|
bool blackBG = chkBlackBG.Checked;
|
|
|
|
Bitmap bmp = new(f.width * upscale, f.height * upscale);
|
|
SolidBrush bb = new(Color.Black);
|
|
SolidBrush bw = new(Color.White);
|
|
using (Graphics g = Graphics.FromImage(bmp)) {
|
|
for (x = 0; x < f.width; x++) {
|
|
for (y = 0; y < f.height; y++) {
|
|
if (f.data[x, y]) {
|
|
if (!transp || (transp && !blackBG)) g.FillRectangle(bb, x * upscale, y * upscale, upscale, upscale);
|
|
} else
|
|
if (!transp || (transp && blackBG)) g.FillRectangle(bw, x * upscale, y * upscale, upscale, upscale);
|
|
}
|
|
}
|
|
}
|
|
|
|
return bmp;
|
|
}
|
|
|
|
private void btnOK_Click(object sender, EventArgs e) {
|
|
if (dlgSaveImage.ShowDialog() == DialogResult.OK) {
|
|
|
|
Bitmap bmp = GenerateScreenshot();
|
|
|
|
bool err = false;
|
|
try {
|
|
bmp.Save(dlgSaveImage.FileName, ImageFormat.Png);
|
|
}
|
|
catch (Exception ex) {
|
|
err = true;
|
|
MessageBox.Show("There was an error during image save: " + ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
if (!err) MessageBox.Show("Screenshot has been saved!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
}
|
|
}
|
|
|
|
private void FrameScreenshot_Load(object sender, EventArgs e) {
|
|
btnOK.Focus();
|
|
}
|
|
|
|
private void btnClose_Click(object sender, EventArgs e) {
|
|
DialogResult = DialogResult.OK;
|
|
}
|
|
|
|
private void chkTransparent_CheckedChanged(object sender, EventArgs e) {
|
|
chkBlackBG.Enabled = chkTransparent.Checked;
|
|
}
|
|
|
|
private void btnCopy_Click(object sender, EventArgs e) {
|
|
Bitmap bmp = GenerateScreenshot();
|
|
using MemoryStream stream = new();
|
|
bmp.Save(stream, ImageFormat.Png);
|
|
DataObject data = new("PNG", stream);
|
|
data.SetImage(bmp);
|
|
Clipboard.SetDataObject(data, true);
|
|
}
|
|
}
|
|
}
|