2using System.Drawing.Imaging;
13 byte[] buffer = image.GetByteArray();
15 BinaryWriter writer =
new BinaryWriter(outStream);
23 writer.Write((
int)(122 + buffer.Length));
26 writer.Write( (
int)0 );
30 writer.Write((
int)0x7A);
34 writer.Write( (
int)108 );
37 writer.Write( image.Width );
38 writer.Write( image.Height );
41 writer.Write( (
short)1 );
44 writer.Write( (
short)32 );
48 writer.Write( (
int)3 );
51 writer.Write( (
int)buffer.Length );
54 writer.Write( (
int)2835 );
55 writer.Write( (
int)2835 );
58 writer.Write( (
int)0 );
61 writer.Write( (
int)0 );
64 writer.Write(
new byte[] { 0xFF, 0x00, 0x00, 0x00 } );
65 writer.Write(
new byte[] { 0x00, 0xFF, 0x00, 0x00 } );
66 writer.Write(
new byte[] { 0x00, 0x00, 0xFF, 0x00 } );
67 writer.Write(
new byte[] { 0x00, 0x00, 0x00, 0xFF } );
76 writer.Write(
new byte[36] );
77 writer.Write( (
int)0 );
78 writer.Write( (
int)0 );
79 writer.Write( (
int)0 );
90 public static void EncodePng(Stream outStream, Stream inStream)
92 var encoders = ImageCodecInfo.GetImageEncoders();
94 Bitmap bmp =
new Bitmap(inStream);
95 bmp.Save(outStream, ImageFormat.Png);
98 public static void EncodeJpeg(Stream outStream, Stream inStream)
100 var bitmap =
new Bitmap(inStream);
103 Encoder encoder2 =
System.Drawing.Imaging.Encoder.Quality;
104 EncoderParameters parameters =
new System.Drawing.Imaging.EncoderParameters(1);
105 EncoderParameter parameter =
new EncoderParameter(encoder2, 50
L);
106 parameters.Param[0] = parameter;
110 bitmap.Save(outStream, jpgEncoder, parameters);
125 using (var image =
System.Drawing.Image.FromStream(img.
AsJpeg()))
133 foreach ( var codec
in ImageCodecInfo.GetImageEncoders().FindAll(x => x.FormatDescription ==
"JPEG") )
138 throw new IOException(desc +
" codec not found");
Stream AsJpeg()
Palauttaa kuvan jpeg-muodossa, jossa se voidaan esimerkiksi tallentaa DataStorage....
static void WriteBmp(Stream outStream, Jypeli.Image image)
static void EncodeJpeg(Stream outStream, Stream inStream)
static void EncodePng(Stream outStream, Stream inStream)
static ImageCodecInfo GetCodecByDescription(string desc)
static void SaveJPG(string fname, Image img)
Tallentaa kuvan jpg-muodossa.