Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Tiff, I quickly wrote this during my lunch break from various sites. It's in no way normalised and there are things that you can do better but given all the run-around you've had on this I thought giving you something that works would be good enough for now.</p> <p>So here it is. I have run and tested it and it works no probs.</p> <pre><code>using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.IO; using System.Drawing.Drawing2D; using System.Drawing.Imaging; namespace ImageResize { class Program { private static byte[] ImageData; private static byte[] SmallImageData; private static Bitmap bmp; static void Main(string[] args) { LoadImageIntoByteArray(); LoadByteArrayAsBitmap(); SaveFromStream(); } private static void SaveFromStream() { using (Image img = Image.FromStream(new MemoryStream(SmallImageData))) { img.Save(@"flowers_thumb.jpg", ImageFormat.Jpeg); } } private static void LoadByteArrayAsBitmap() { MemoryStream ms = new MemoryStream(ImageData); bmp = new Bitmap(ms); System.Drawing.Image oImg = System.Drawing.Image.FromStream(ms); System.Drawing.Image oThumbNail = new Bitmap(100, 100); Graphics oGraphic = Graphics.FromImage(oThumbNail); oGraphic.CompositingQuality = CompositingQuality.HighQuality; oGraphic.SmoothingMode = SmoothingMode.HighQuality; oGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic; Rectangle oRectangle = new Rectangle (0, 0, 100, 100); oGraphic.DrawImage(oImg, oRectangle); MemoryStream ms2 = new MemoryStream(); oThumbNail.Save(ms2, ImageFormat.Jpeg); ms2.Position = 0; SmallImageData = new byte[ms2.Length]; ms2.Read(SmallImageData, 0, Convert.ToInt32(ms2.Length)); oGraphic.Dispose(); oImg.Dispose(); ms2.Close(); ms2.Dispose(); } private static void LoadImageIntoByteArray() { FileStream fs = File.OpenRead(@"flowers.jpg"); ImageData = new byte[fs.Length]; fs.Read(ImageData, 0, ImageData.Length); fs.Close(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload