1-) C# - resim şifreleme ve çözme görüntü işleme
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GoruntuIsleme
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnResimSec_Click(object sender, EventArgs e)
{
using (OpenFileDialog dlg = new OpenFileDialog())
{
dlg.Title = "Open Image";
dlg.Filter = "Image Files (*.bmp;*.jpg;*.jpeg,*.png)|*.BMP;*.JPG;*.JPEG;*.PNG";
if (dlg.ShowDialog() == DialogResult.OK)
{
pictureBox_resimSec.Image = new Bitmap(dlg.FileName);
}
}
}
public Color[][] getBitmapColorMatrix(Bitmap bmp)
{
Color[][] matrix;
int height = bmp.Height;
int width = bmp.Width;
if (height > width)
{
matrix = new Color[bmp.Width][];
for (int i = 0; i <= bmp.Width - 1; i++)
{
matrix[i] = new Color[bmp.Height];
for (int j = 0; j < bmp.Height - 1; j++)
{
matrix[i][j] = bmp.GetPixel(i, j);
}
}
}
else
{
matrix = new Color[bmp.Height][];
for (int i = 0; i <= bmp.Height - 1; i++)
{
matrix[i] = new Color[bmp.Width];
for (int j = 0; j < bmp.Width - 1; j++)
{
matrix[i][j] = bmp.GetPixel(i, j);
}
}
}
return matrix;
}
/*
resim.Width = colorArray.Length
resim.Height = colorArray[0].Length
*/
private void btnResimSifrele_Click(object sender, EventArgs e)
{
Bitmap resim = new Bitmap(pictureBox_resimSec.Image);
//Color[][] colorArray = getBitmapColorMatrix(resim);
//sifreleColor(colorArray, resim);
sifreleColor(resim);
}
private void sifreleColor(Bitmap bmp)
{
for (int y = 0; y < bmp.Height; y++)
{
for (int x = 0; x < bmp.Width; x++)
{
Color color = bmp.GetPixel(x, y);
int R_sifre = sifrelemeAlgoritmasi(color.R);
int G_sifre = sifrelemeAlgoritmasi(color.G);
int B_sifre = sifrelemeAlgoritmasi(color.B);
Color color1 = new Color();
color1 = Color.FromArgb(R_sifre, G_sifre, B_sifre); // 255 0 100 -> 100 0 255
bmp.SetPixel(x, y, color1);
}
}
pictureBox_resimSifrele.Image = bmp;
}
int sayac = 0;
public int sifrelemeAlgoritmasi(int pixel)
{
sayac = sayac + 100;
if (sayac>255)
{
sayac = sayac - 255;
}
pixel = pixel - sayac;
if (pixel < 0)
{
pixel = pixel + 255;
}
return pixel;
}
int sayacCoz = 0;
public int cozmeAlgoritmasi(int pixel)
{
sayacCoz = sayacCoz + 100;
if (sayacCoz >255)
{
sayacCoz = sayacCoz - 255;
}
pixel = pixel + sayacCoz;
if (pixel >255)
{
pixel = pixel - 255;
}
return pixel;
}
private void cozColor(Bitmap bmp)
{
for (int y = 0; y < bmp.Height; y++)
{
for (int x = 0; x < bmp.Width; x++)
{
Color color = bmp.GetPixel(x, y);
int R_sifre = cozmeAlgoritmasi(color.R);
int G_sifre = cozmeAlgoritmasi(color.G);
int B_sifre = cozmeAlgoritmasi(color.B);
if (R_sifre < 125)
{
}
Color color1 = new Color();
color1 = Color.FromArgb(R_sifre, G_sifre, B_sifre); // 255 0 100 -> 100 0 255
bmp.SetPixel(x, y, color1);
}
}
pictureBox_resimCoz.Image = bmp;
}
private void btnResimSifreCoz_Click(object sender, EventArgs e)
{
Bitmap resim = new Bitmap(pictureBox_resimSifrele.Image);
//Color[][] colorArray = getBitmapColorMatrix(resim);
//sifreleColor(colorArray, resim);
cozColor(resim);
}
}
}