GDI+ using setResolution always results in resolution of 96x96
- From: "j" <mr.jawright@xxxxxxxxx>
- Date: 18 Jan 2007 13:50:43 -0800
I am using a Bitmap object to modify JPEG images of variing
resolutions.
We'd decided (albeit arbitrarily) to refactor the images at a
resolution of 200x200, and then rescale the images' dimensions.
The process seems to work, but the images' resoluion is always 96x96,
not 200x200.
I've found no documentation stating any specific, valid resolutions for
a Bitmap object, so it's vexing me that it is not what I specified it
to be.
Any help either explaining why this is so and/or how to fix it would be
greatly appreciated.
Thanks in Advance.
Relevant Bits of the Code (possibly some overkill in it, as I've been
trying differeing methods to get it to work):
System.Collections.Hashtable imageOutputFormatsTable = new
System.Collections.Hashtable();
imageOutputFormatsTable.Add(System.Drawing.Imaging.ImageFormat.Gif.Guid,System.Drawing.Imaging.ImageFormat.Gif);
imageOutputFormatsTable.Add(System.Drawing.Imaging.ImageFormat.Jpeg.Guid,System.Drawing.Imaging.ImageFormat.Jpeg);
imageOutputFormatsTable.Add(System.Drawing.Imaging.ImageFormat.Bmp.Guid,System.Drawing.Imaging.ImageFormat.Bmp);
imageOutputFormatsTable.Add(System.Drawing.Imaging.ImageFormat.Tiff.Guid,System.Drawing.Imaging.ImageFormat.Tiff);
imageOutputFormatsTable.Add(System.Drawing.Imaging.ImageFormat.Png.Guid,System.Drawing.Imaging.ImageFormat.Png);
Bitmap outputImage = new Bitmap(newWidth, newHeight);
outputImage.SetResolution(newHRes, newVRes);
Graphics g = Graphics.FromImage(outputImage);
g.DrawImage(origBitmap, new Rectangle(0, 0,
outputImage.Width, outputImage.Height)
, 0, 0, origBitmap.Width, origBitmap.Height,
GraphicsUnit.Pixel);
g.Dispose();
ImageFormat outputFormat =
(ImageFormat)imageOutputFormatsTable[origBitmap.RawFormat.Guid];
using (MemoryStream ms = new MemoryStream())
{
ImageCodecInfo outputCodec=null;
ImageCodecInfo[] codecs =
ImageCodecInfo.GetImageDecoders();
foreach (ImageCodecInfo codec in codecs)
{
if (codec.MimeType.Contains("jpeg"))
{
outputCodec = codec;
}
}
EncoderParameters outputCodecParams = new
EncoderParameters(1);
System.Drawing.Imaging.Encoder qualityEncoder =
System.Drawing.Imaging.Encoder.Quality;
EncoderParameter encoderParam0 = new
EncoderParameter(qualityEncoder, 85L);
outputCodecParams.Param[0] = encoderParam0;
if (outputCodec != null)
{
outputImage.Save(ms, outputCodec,
outputCodecParams);
//outputImage.Save(ms, outputFormat);
outputImage.Dispose();
origBitmap.Dispose();
_image = Image.FromStream(ms, true);
return _image;
}
}
.
- Prev by Date: Re: PictureBox ReSize occurs when assigning Image
- Next by Date: Metafile surface size
- Previous by thread: Q: Why PictureBox takes SO MUCH memory ??
- Next by thread: Metafile surface size
- Index(es):
Relevant Pages
|