「雲雲フィルター」の編集履歴(バックアップ)一覧はこちら
「雲雲フィルター」(2010/05/28 (金) 10:36:54) の最新版変更点
追加された行は緑色になります。
削除された行は赤色になります。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Bitmap b1 = new Bitmap(pictureBox1.Image); // 変数の宣言
//pictureBox1.Image =b1;
PictToCircle PTC = new WindowsFormsApplication2.PictToCircle(b1);
PTC.changeCircle();
b1 = (PTC.getPict());
pictureBox1.Image = b1;
//b1.Dispose();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
pictureBox1.Image = Image.FromFile("D:/色々/中高生向け戦争小説 ギガンダム討伐/10774542.jpg");
}
}
class PictToCircle
{
Random rnd = new Random();
Bitmap b1 = null;
Bitmap b2 = null;
int h;//絵の高さ
int w;//絵の横幅
int max;//横と高さのうちで大きいほう
int maxSize;//円の最大サイズ
public PictToCircle(Bitmap bmp1)
{
this.b1 = bmp1;
this.h = bmp1.Height;
this.w = bmp1.Width;
this.max = Math.Max(this.h, this.w);
this.b2 = new Bitmap(b1.Width, b1.Height);
for (int i = 0; i < w; i++)
{
for (int j = 0; j < h; j++)
{
b2.SetPixel(i, j, Color.White);
}
}
}
public void changeCircle()
{
int nowSize = (int)Math.Floor(max / 3.0);
this.maxSize = nowSize;
int tUp = 0;
int incK = 1;
while (nowSize > 1)
{
nowSize = (int)(nowSize / 1.717);
for (int i = 0; i < b1.Width / nowSize; i++)
{
for (int j = 0; j < b1.Height / nowSize; j++)
{
if (nowSize > 5)
{
tUp = 8;
}
else
{
tUp = 2;
incK =1;
}
for (int k = 0; k < tUp; k += incK)
{
CellToCircle(rnd.Next(4 * nowSize) - 2 * nowSize + i * nowSize, rnd.Next(4 * nowSize) - 2 * nowSize + j * nowSize, nowSize);
}
}
}
}
Color c3;
for (int i = 0; i < b1.Width; i++)
{
for (int j = 0; j < b1.Height; j++)
{
c3= this.b2.GetPixel(i, j);
if (c3.R + c3.G + c3.B > 764)
{
this.b2.SetPixel(i, j,this.b1.GetPixel(i,j));
}
}
}
}
public void CellToCircle(int x, int y, int size)
{
if (rnd.Next(100) > 95)
{
size += rnd.Next(3);
}
int sx = cutNum(0, this.b1.Width - 1, x - size);
int sy = cutNum(0, this.b1.Height - 1, y - size);
int ex = cutNum(1, this.b1.Width, x + size);
int ey = cutNum(1, this.b1.Height, y + size);
Color c1;
int th = (int)Math.Floor((Math.Sqrt(size * 2)));
int tw = th;
int t1 = ((ex - sx) / tw + 1) * ((ey - sy) / tw + 1);
float aveR = 0;
float aveG = 0;
float aveB = 0;
float count= 0;
for (int i = sx; i < ex; i += tw)
{
for (int j = sy; j < ey; j += th)
{
//各色の明るさを測る
c1 = b1.GetPixel(i, j);
if (c1.R + c1.G + c1.B > 500)
{
aveR += c1.R;
aveG += c1.G;
aveB += c1.B;
count++;
}
}
}
aveR /= (count+1) ;
aveG /= (count+1) ;
aveB /= (count+1) ;
if (rnd.Next(10) > 7)
{
c1 = b1.GetPixel(rnd.Next(ex - sx) + sx, rnd.Next(ey - sy) + sy);
}
else
{
c1 = Color.FromArgb((int)(aveR), (int)(aveG), (int)(aveB));
}
float tUp2 = 0;
if (size > 12)
{
tUp2 = 0.5F;
}
else if (size > 7)
{
tUp2 =0.3F;
}
else
{
tUp2 =0.3F;
}
if (count / t1 > tUp2)
{
cellToCircle2(sx, sy, ex, ey, x, y, size, c1,0);
}
}
void cellToCircle2(int sx, int sy, int ex, int ey, int x, int y, int size, Color c,int mode)
{
Color c2;
int tHeight, sy2, ey2;
int size2 = size * size;
byte r1, g1, b1;
for (int i = sx; i < ex; i++)
{
if (size > 2)
{
tHeight = (int)(Math.Sqrt((double)size2 - (double)((x - i) * (x - i))));
sy2 = cutNum(sy, ey, y - tHeight);
ey2 = cutNum(sy, ey, y + tHeight);
}
else
{
sy2 = sy;
ey2 = ey;
}
if (mode == 0)
{
for (int j = sy2; j < ey2; j++)
{
c2 = this.b1.GetPixel(i, j);
r1 = (byte)cutNum(0, 255, (int)(c.R * 0.8 + c2.R * 0.2));
g1 = (byte)cutNum(0, 255, (int)(c.G * 0.8 + c2.G * 0.2));
b1 = (byte)cutNum(0, 255, (int)(c.B * 0.8 + c2.B * 0.2));
c2 = Color.FromArgb(r1, g1, b1);
this.b2.SetPixel(i, j, c2);
}
}
else
{
for (int j = sy; j < ey; j++)
{
c2 = this.b1.GetPixel(i, j);
r1 = (byte)cutNum(0, 255, (int)(c.R * 0.1 + c2.R * 0.9));
g1 = (byte)cutNum(0, 255, (int)(c.G * 0.1 + c2.G * 0.9));
b1 = (byte)cutNum(0, 255, (int)(c.B * 0.1 + c2.B * 0.9));
c2 = Color.FromArgb(r1, g1, b1);
this.b2.SetPixel(i, j, c2);
}
}
}
}
public Bitmap getPict()
{
return this.b2;
}
private int cutNum(int min, int max, int t)
{
if (t < min)
{
t = min;
}
if (t > max)
{
t = max;
}
return t;
}
}
}
煙や雲っぽいフィルターを実行できるフィルタ。
の予定でした。
フラクタルのことをきちんと勉強しなおして、基礎からコードを練り直す予定。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Bitmap b1 = new Bitmap(pictureBox1.Image); // 変数の宣言
//pictureBox1.Image =b1;
PictToCircle PTC = new WindowsFormsApplication2.PictToCircle(b1);
PTC.changeCircle();
b1 = (PTC.getPict());
pictureBox1.Image = b1;
//b1.Dispose();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
pictureBox1.Image = Image.FromFile("D:/色々/中高生向け戦争小説 ギガンダム討伐/10774542.jpg");
}
}
class PictToCircle
{
Random rnd = new Random();
Bitmap b1 = null;
Bitmap b2 = null;
int h;//絵の高さ
int w;//絵の横幅
int max;//横と高さのうちで大きいほう
int maxSize;//円の最大サイズ
public PictToCircle(Bitmap bmp1)
{
this.b1 = bmp1;
this.h = bmp1.Height;
this.w = bmp1.Width;
this.max = Math.Max(this.h, this.w);
this.b2 = new Bitmap(b1.Width, b1.Height);
for (int i = 0; i < w; i++)
{
for (int j = 0; j < h; j++)
{
b2.SetPixel(i, j, Color.White);
}
}
}
public void changeCircle()
{
int nowSize = (int)Math.Floor(max / 3.0);
this.maxSize = nowSize;
int tUp = 0;
int incK = 1;
while (nowSize > 1)
{
nowSize = (int)(nowSize / 1.717);
for (int i = 0; i < b1.Width / nowSize; i++)
{
for (int j = 0; j < b1.Height / nowSize; j++)
{
if (nowSize > 5)
{
tUp = 8;
}
else
{
tUp = 2;
incK =1;
}
for (int k = 0; k < tUp; k += incK)
{
CellToCircle(rnd.Next(4 * nowSize) - 2 * nowSize + i * nowSize, rnd.Next(4 * nowSize) - 2 * nowSize + j * nowSize, nowSize);
}
}
}
}
Color c3;
for (int i = 0; i < b1.Width; i++)
{
for (int j = 0; j < b1.Height; j++)
{
c3= this.b2.GetPixel(i, j);
if (c3.R + c3.G + c3.B > 764)
{
this.b2.SetPixel(i, j,this.b1.GetPixel(i,j));
}
}
}
}
public void CellToCircle(int x, int y, int size)
{
if (rnd.Next(100) > 95)
{
size += rnd.Next(3);
}
int sx = cutNum(0, this.b1.Width - 1, x - size);
int sy = cutNum(0, this.b1.Height - 1, y - size);
int ex = cutNum(1, this.b1.Width, x + size);
int ey = cutNum(1, this.b1.Height, y + size);
Color c1;
int th = (int)Math.Floor((Math.Sqrt(size * 2)));
int tw = th;
int t1 = ((ex - sx) / tw + 1) * ((ey - sy) / tw + 1);
float aveR = 0;
float aveG = 0;
float aveB = 0;
float count= 0;
for (int i = sx; i < ex; i += tw)
{
for (int j = sy; j < ey; j += th)
{
//各色の明るさを測る
c1 = b1.GetPixel(i, j);
if (c1.R + c1.G + c1.B > 500)
{
aveR += c1.R;
aveG += c1.G;
aveB += c1.B;
count++;
}
}
}
aveR /= (count+1) ;
aveG /= (count+1) ;
aveB /= (count+1) ;
if (rnd.Next(10) > 7)
{
c1 = b1.GetPixel(rnd.Next(ex - sx) + sx, rnd.Next(ey - sy) + sy);
}
else
{
c1 = Color.FromArgb((int)(aveR), (int)(aveG), (int)(aveB));
}
float tUp2 = 0;
if (size > 12)
{
tUp2 = 0.5F;
}
else if (size > 7)
{
tUp2 =0.3F;
}
else
{
tUp2 =0.3F;
}
if (count / t1 > tUp2)
{
cellToCircle2(sx, sy, ex, ey, x, y, size, c1,0);
}
}
void cellToCircle2(int sx, int sy, int ex, int ey, int x, int y, int size, Color c,int mode)
{
Color c2;
int tHeight, sy2, ey2;
int size2 = size * size;
byte r1, g1, b1;
for (int i = sx; i < ex; i++)
{
if (size > 2)
{
tHeight = (int)(Math.Sqrt((double)size2 - (double)((x - i) * (x - i))));
sy2 = cutNum(sy, ey, y - tHeight);
ey2 = cutNum(sy, ey, y + tHeight);
}
else
{
sy2 = sy;
ey2 = ey;
}
if (mode == 0)
{
for (int j = sy2; j < ey2; j++)
{
c2 = this.b1.GetPixel(i, j);
r1 = (byte)cutNum(0, 255, (int)(c.R * 0.8 + c2.R * 0.2));
g1 = (byte)cutNum(0, 255, (int)(c.G * 0.8 + c2.G * 0.2));
b1 = (byte)cutNum(0, 255, (int)(c.B * 0.8 + c2.B * 0.2));
c2 = Color.FromArgb(r1, g1, b1);
this.b2.SetPixel(i, j, c2);
}
}
else
{
for (int j = sy; j < ey; j++)
{
c2 = this.b1.GetPixel(i, j);
r1 = (byte)cutNum(0, 255, (int)(c.R * 0.1 + c2.R * 0.9));
g1 = (byte)cutNum(0, 255, (int)(c.G * 0.1 + c2.G * 0.9));
b1 = (byte)cutNum(0, 255, (int)(c.B * 0.1 + c2.B * 0.9));
c2 = Color.FromArgb(r1, g1, b1);
this.b2.SetPixel(i, j, c2);
}
}
}
}
public Bitmap getPict()
{
return this.b2;
}
private int cutNum(int min, int max, int t)
{
if (t < min)
{
t = min;
}
if (t > max)
{
t = max;
}
return t;
}
}
}