2010-09-27 71 views
0
public byte[] imageToByteArray(System.Drawing.Image imageIn) 
{ 
    Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); 
    dlg.FileName = "Document"; // Default file name 
    dlg.DefaultExt = ".txt"; // Default file extension 
    dlg.Filter = "Text documents (.txt)|*.txt"; // Filter files by extension 
    Nullable<bool> result = dlg.ShowDialog(); // Show open file dialog box 

    // Process open file dialog box results 
    if (result == true) 
    { 
     // Open document 
     string filename = dlg.FileName; 
     txtBrowse.Text = filename; 
    } 
    ImageSource imageSource = new BitmapImage(new Uri(txtBrowse.Text)); 
    imgImageAdlut.Source = imageSource; ; 
    byte[] array1 = null; 
    //array1 = imageToByteArray(); 
} 

public byte[] imageToByteArray(System.Drawing.Image imageIn) 
{ 
    MemoryStream ms = new MemoryStream(); 
    imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); 
    return ms.ToArray(); 
} 
+0

什么是你的问题?阅读关于tinyurl.com/so-hints的一些提示,并重写你的问题,以明确你想要做的事情。 – 2010-09-27 06:19:13

回答

0

试试这个:

var img = new System.Drawing.Bitmap(@"D:\Your image path\your image.bmp"); 
byte[] array1 = imageToByteArray(img);