2 回答

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超5個(gè)贊
我將定義一個(gè)抽象類 Filter 并將每個(gè)過(guò)濾器實(shí)現(xiàn)為該類的繼承人。
public abstract class Filter
{
public Bitmap Image { get; set; }
public abstract void Apply();
}
一個(gè)實(shí)現(xiàn)是:
public class SliderKernel : Filter
{
public overrides void Apply()
{
//manipulates the Image property
}
}
如果您想在任何地方使用該圖像,您應(yīng)該將其聲明為類的靜態(tài)成員:
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貢獻(xiàn)1719條經(jīng)驗(yàn) 獲得超6個(gè)贊
我認(rèn)為你應(yīng)該將圖像轉(zhuǎn)換為字節(jié)數(shù)組
使用以下代碼并將其存儲(chǔ)在靜態(tài)類中
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
并使用此代碼轉(zhuǎn)為圖形顯示在pictureBox中
public Image byteArrayToImage(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
- 2 回答
- 0 關(guān)注
- 146 瀏覽
添加回答
舉報(bào)