El TecnoBaúl de Kiquenet

Kiquenet boring stories

Posts Tagged ‘memorystream’

Imagen y Bytes

Posted by kiquenet en 8 junio 2010

 

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

 

public Image byteArrayToImage(byte[] byteArrayIn)
{
     MemoryStream ms = new MemoryStream(byteArrayIn);
     Image returnImage = Image.FromStream(ms);
     return returnImage;
}

http://www.codeproject.com/KB/recipes/ImageConverter.aspx

Anuncios

Posted in .NET | Etiquetado: , | Leave a Comment »

Downloading a remote file to a MemoryStream using C#

Posted by kiquenet en 7 junio 2010

// Sample Url, Watch for Line Breaks
static string pdfUrl = 
  @"http://download.microsoft.com/download/c/a/9/
  ca927411-504e-498a-ad2e-490ca4d9cd27/Journal_4_web.pdf";

// Member variable to store the MemoryStream Data
private MemoryStream pdfMemoryStream;

// Public MemoryStream property containing PDF Data
public MemoryStream PdfMemoryStream 
{
    get 
    {
        // Check to see if the MemoryStream has already been created,
        // if not, then create memory stream
        if (this.pdfMemoryStream == null) 
        {
            WebClient client = new WebClient();    
            try 
            {
                this.pdfMemoryStream = 
                  new MemoryStream(client.DownloadData(pdfUrl));
            } 
            finally 
            {
                client.Dispose();
            }
        }
        return this.pdfMemoryStream;
    }
}


Fuente: http://www.jaydouglas.com/Articles/DownloadToMemoryStream.aspx

Posted in .NET | Etiquetado: , | Leave a Comment »