简体   繁体   中英

Change an image dpi without changing it's pixal format

Every time I try to change the image's dpi, the pixel format (Color scheme - RGB, CMYK and such...) seems to change. The only time I did succeed in saving the pixel format, the dpi, on debug mode, seems to change, but after the process is complete, it is changed back to it's original settings.

the code I tried is as followed:

        using (var ms = new MemoryStream())
        {
            using (var bmpInput = Image.FromFile(path) as Bitmap)
            {
                using (var bmpOutput = (Bitmap)bmpInput.Clone())                        
                {
                    foreach (var id in bmpInput.PropertyIdList)
                        bmpOutput.SetPropertyItem(bmpInput.GetPropertyItem(id));                        
                    if (doResize)
                        bmpOutput.SetResolution(dpi, dpi);

                    bmpOutput.Save(ms, bmpInput.RawFormat);
                    return ms.ToArray();
                }
            }
        } 
Application.DoEvents();

在将代码保存到代码中之前,请尝试此操作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM