0% found this document useful (0 votes)
24 views3 pages

Design Form: Using Using Using Using Using Using Using Using Using Using Namespace Public Partial Class Public

This document contains C# code for a Windows form application that allows users to open an image, adjust its brightness level using a horizontal scroll bar, and apply different resizing modes to the image using menu options. The form contains two picture boxes, one menu strip, one open file dialog, and one horizontal scroll bar. The code handles opening an image, adjusting brightness by modifying pixel values, and updating the brightness label when the scroll bar is moved. Resizing modes like normal, fit, center, and stretch can be applied by clicking options in the menu strip.

Uploaded by

Rany Ayu Lestari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views3 pages

Design Form: Using Using Using Using Using Using Using Using Using Using Namespace Public Partial Class Public

This document contains C# code for a Windows form application that allows users to open an image, adjust its brightness level using a horizontal scroll bar, and apply different resizing modes to the image using menu options. The form contains two picture boxes, one menu strip, one open file dialog, and one horizontal scroll bar. The code handles opening an image, adjusting brightness by modifying pixel values, and updating the brightness label when the scroll bar is moved. Resizing modes like normal, fit, center, and stretch can be applied by clicking options in the menu strip.

Uploaded by

Rany Ayu Lestari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Design Form

Form1.cs
using
using
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Drawing.Imaging;
System.Linq;
System.Text;
System.Threading.Tasks;
System.Windows.Forms;

namespace brightening
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
label1.Text = "Brightness " + hScrollBar1.Value;
}
private void clearChecked()
{
normalToolStripMenuItem.Checked = false;
fitToolStripMenuItem.Checked = false;
centerToolStripMenuItem.Checked = false;
stretchToolStripMenuItem.Checked = false;
}

private void openToolStripMenuItem_Click(object sender, EventArgs e)


{
FileDialog fileDialog = new OpenFileDialog();
fileDialog.ShowDialog(this);
string fileName = fileDialog.FileName;
if (fileName == string.Empty) return;
initialPicture.Image = Image.FromFile(fileName);
sizeToolStripMenuItem.Enabled = (initialPicture.Image != null);
convertToolStripMenuItem.Enabled = (initialPicture.Image != null);
}
private void normalToolStripMenuItem_Click(object sender, EventArgs e)
{
initialPicture.SizeMode = PictureBoxSizeMode.Normal;
initialPicture.SizeMode = PictureBoxSizeMode.Normal;
clearChecked();
normalToolStripMenuItem.Checked = true;
}
private void fitToolStripMenuItem_Click(object sender, EventArgs e)
{
initialPicture.SizeMode = PictureBoxSizeMode.Zoom;
convertedPicture.SizeMode = PictureBoxSizeMode.Zoom;
clearChecked();
fitToolStripMenuItem.Checked = true;
}
private void centerToolStripMenuItem_Click(object sender, EventArgs e)
{
initialPicture.SizeMode = PictureBoxSizeMode.CenterImage;
convertedPicture.SizeMode = PictureBoxSizeMode.CenterImage;
clearChecked();
centerToolStripMenuItem.Checked = true;
}
private void stretchToolStripMenuItem_Click(object sender, EventArgs e)
{
initialPicture.SizeMode = PictureBoxSizeMode.StretchImage;
convertedPicture.SizeMode = PictureBoxSizeMode.StretchImage;
clearChecked();
stretchToolStripMenuItem.Checked = true;
}
private void convertToolStripMenuItem_Click(object sender, EventArgs e)
{
brighten bright = new brighten();
int brightness = hScrollBar1.Value;
Bitmap image = new Bitmap(initialPicture.Image);
bright.process(image, brightness);
convertedPicture.Image = image;
}
private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
label1.Text = "Brightness " + hScrollBar1.Value;
}
}

Add class: brighten.cs


using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.Drawing;
System.Drawing.Imaging;
System.Linq;
System.Text;
System.Threading.Tasks;

namespace brightening
{
class brighten
{
public bool process(Bitmap b, int nBrightness)
{
BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height),
ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int stride = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
unsafe
{
int nVal;
byte* p = (byte*)(void*)Scan0;
int nOffset = stride - b.Width * 3;
int nWidth = b.Width * 3;
for (int y = 0; y < b.Height; ++y)
{
for (int x = 0; x < nWidth; ++x)
{
nVal = (int)(p[0] + nBrightness);
p[0] = (byte)nVal;
++p;
}
p += nOffset;
}
}
b.UnlockBits(bmData);
return true;
}
}
}

Component:
PictureBox jumlah 2
MenuStrip jumlah 1
OpenFileDialog jumlah 1
HscrollBarr jumlah 1

You might also like