Tình hình là em làm bộ lọc ảnh Pixelate để làm mờ 1 bức ảnh với việc gom các điểm ảnh có m x m điểm ảnh thành 1 điểm ảnh lớn có cùng màu (quy định bởi 1 thanh trượt từ 1 tới 10) > mục đích làm nhòe ảnh.
Em sài hàm theo hướng dẫn ở link nè ạ:
http:/otes.ericwillis.com/2009/11/...e-with-csharp/
Nhưng khi gọi hàm thì có vẻ nó không ổn, nó chả mờ tý nào cả (khi chọn số điểm ảnh gom bằng cách lăn thanh trượt, và ấn nút biến đổi).
Form của em nó có dạng nè ạ:
Còn đây là project cho các pro tiện giúp em ạ [IMG]images/smilies/biggrin.png[/IMG]
http://www.mediafire.com/?2k8n8isax5uhp59
Đây là code của em ạ [IMG]images/smilies/biggrin.png[/IMG]
Mã:
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;
using System.IO;
namespace demo_boloc
{
public partial class frmBiendoiloc : Form
{
public static int biendoi = 1;
public frmBiendoiloc()
{
InitializeComponent();
}
private void frmBiendoiloc_Load(object sender, EventArgs e)
{
ptbAnhgoc.Image = Image.FromFile(System.IO.Directory.GetCurrentDirectory() + @"/temp/xuly.bmp");
ptbAnhgoc.SizeMode = PictureBoxSizeMode.CenterImage;
Image img = Image.FromFile(System.IO.Directory.GetCurrentDirectory() + @"/temp/xuly.bmp");
lblKichthuoc.Text = img.Size.ToString() + "; ";
string duongdan = System.IO.Directory.GetCurrentDirectory() + @"/temp/xuly.bmp";
FileInfo thongtinfile = new FileInfo(duongdan);
lblKichco.Text = thongtinfile.Length.ToString() + "Byte";
}
private void btnLuuAnh_Click(object sender, EventArgs e)
{
saveFileDialog1.Title = "Lưu file ảnh định dạng bmp";
saveFileDialog1.InitialDirectory = "D:\\";
saveFileDialog1.DefaultExt = "bmp";
saveFileDialog1.Filter = "All files (*.*)|*.*|bmp files (*.bmp)|*.bmp";
saveFileDialog1.OverwritePrompt = true;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
ptbAnhdoi.Image.Save(saveFileDialog1.FileName);
}
private void btnThoat_Click(object sender, EventArgs e)
{
this.Close();
}
private static Bitmap Pixelate(Bitmap image, Rectangle rectangle, Int32 pixelateSize)
{
Bitmap pixelated = new System.Drawing.Bitmap(image.Width, image.Height);
// make an exact copy of the bitmap provided
using (Graphics graphics = System.Drawing.Graphics.FromImage(pixelated))
graphics.DrawImage(image, new System.Drawing.Rectangle(0, 0, image.Width, image.Height),
new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
// look at every pixel in the rectangle while making sure we're within the image bounds
for (Int32 xx = rectangle.X; xx < rectangle.X + rectangle.Width && xx < image.Width; xx += pixelateSize)
{
for (Int32 yy = rectangle.Y; yy < rectangle.Y + rectangle.Height && yy < image.Height; yy += pixelateSize)
{
Int32 offsetX = pixelateSize / 2;
Int32 offsetY = pixelateSize / 2;
// make sure that the offset is within the boundry of the image
while (xx + offsetX >= image.Width) offsetX--;
while (yy + offsetY >= image.Height) offsetY--;
// get the pixel color in the center of the soon to be pixelated area
Color pixel = pixelated.GetPixel(xx + offsetX, yy + offsetY);
// for each pixel in the pixelate size, set it to the center color
for (Int32 x = xx; x < xx + pixelateSize && x < image.Width; x++)
for (Int32 y = yy; y < yy + pixelateSize && y < image.Height; y++)
pixelated.SetPixel(x, y, pixel);
}
}
return pixelated;
}
private void tbDiemanh_Scroll(object sender, EventArgs e)
{
biendoi = (int)tbDiemanh.Value;
lblDiemanh.Text = biendoi.ToString();
}
private void btnBiendoi_Click(object sender, EventArgs e)
{
ptbAnhdoi.Image = Image.FromFile(System.IO.Directory.GetCurrentDirectory() + @"/temp/xuly.bmp");
ptbAnhdoi.SizeMode = PictureBoxSizeMode.CenterImage;
Bitmap bm = new Bitmap(ptbAnhdoi.Image);
Bitmap bitmap = new Bitmap(bm);
Pixelate(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height), biendoi);
ptbAnhdoi.Image = bitmap;
ptbAnhdoi.SizeMode = PictureBoxSizeMode.CenterImage;
}
}
}
View more random threads:
Vệ sinh cá nhân là một phần quan yếu của sức khỏe nam giới. Dùng dung dịch vệ sinh mỗi ngày mang lại nhiều ích, giúp loại bỏ vi khuẩn và vi sinh vật gây hại, giúp khu vực cơ quan sinh dục luôn sạch...
Gel vệ sinh cu, bạn trai có nên...