2 回答
TA贡献1876条经验 获得超5个赞
我将定义一个抽象类 Filter 并将每个过滤器实现为该类的继承人。
public abstract class Filter
{
public Bitmap Image { get; set; }
public abstract void Apply();
}
一个实现是:
public class SliderKernel : Filter
{
public overrides void Apply()
{
//manipulates the Image property
}
}
如果您想在任何地方使用该图像,您应该将其声明为类的静态成员:
public static class ImageContainer
{
public static Bitmap Image { get; set; }
}
您可以在表单代码中使用所有这些,如下所示:
private void btn_BROWSE_Click(object sender, EventArgs e)
{
OpenFileDialog imge = new OpenFileDialog();
imge.Filter = "Extensions |*.bmp;*.jpg;*.jpeg;*.png;*.tif;*.tiff|"
+ "BMP|*.bmp|GIF|*.gif|JPG|*.jpg;*.jpeg|PNG|*.png|TIFF|*.tif;*.tiff|"
+ "Zip Files|*.zip;*.rar";
imge.ShowDialog();
string imgepath = imge.FileName;
pBox_SOURCE.ImageLocation = imgepath;//i'm browsing an image
//save the image to the container
ImageContainer.Image = new Bitmap(pBox_SOURCE.Image);
}
private void sliderKernel_MouseUp(object sender, MouseEventArgs e)
{
Filter filter = new SliderKernel () { Image = ImageContainer.Image };
filter.Apply();
}
TA贡献1719条经验 获得超6个赞
我认为你应该将图像转换为字节数组
使用以下代码并将其存储在静态类中
public byte[] ImageToByteArray(System.Drawing.Image imageIn)
{
using (var ms = new MemoryStream())
{
imageIn.Save(ms,imageIn.RawFormat);
return ms.ToArray();
}
}
https://www.codeproject.com/Articles/15460/C-Image-to-Byte-Array-and-Byte-Array-to-Image-Conv
并使用此代码转为图形显示在pictureBox中
public Image byteArrayToImage(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
- 2 回答
- 0 关注
- 108 浏览
添加回答
举报