2

I will get image in byte from database and using system.drawing.graphic to add some necessary stuff , and after this i need to save this image in byte[] and send to front end (silver light 4) to print.

note(I am not going to save this in physical file).

I appreciate every help or you guys and provide example code if possible.

NoNaMe
  • 6,020
  • 30
  • 82
  • 110
Nelson
  • 31
  • 1
  • 7
  • http://www.codeproject.com/Articles/15460/C-Image-to-Byte-Array-and-Byte-Array-to-Image-Conv – yue shi Oct 19 '15 at 03:31
  • this was just the conversion from byte > image > byte. my problem is how to use system.drawstring to customize my stuff and convert it to byte[] and send to front end to print – Nelson Oct 19 '15 at 03:40
  • I have no idea how can this work, previous i was doing all the system.drawstring inside the printDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) event. now i am looking for move the function to back end and only return image to front end – Nelson Oct 19 '15 at 03:48
  • 1
    http://stackoverflow.com/questions/6311545/c-sharp-write-text-on-bitmap should give you (or whoever want to provide complete copy-paste-ready answer) head start. If not enough info search - https://www.bing.com/search?q=c%23+draw+text+bitmap ... – Alexei Levenkov Oct 19 '15 at 03:51

1 Answers1

7
byte[] result;
using (Image newImage = new Bitmap(origImage))
{
    using (Graphics graphics = Graphics.FromImage(newImage))
    {
        // do some drawing
    }

    using (MemoryStream ms = new MemoryStream())
    {
        newImage.Save(ms, ImageFormat.Png);
        result = ms.ToArray();
    }
}

To restore the image from the byte[]:

Image restored = Image.FromStream(new MemoryStream(result));
György Kőszeg
  • 17,093
  • 6
  • 37
  • 65