将图像从python转换为c# - 图像尺寸太不同了

时间:2011-09-26 15:14:06

标签: c# .net python bitmap

我正在尝试将图像从python转换为c#,python创建的图像尺寸要小得多,而.net创建的图像尺寸要大得多。我不想降低图像的质量,也不确定它为什么会发生。

这是python代码。

        if img.mode != "RGB":
        img = img.convert("RGB")
        img = img.resize((width,height), Image.ANTIALIAS)

        resampled_image_name = os.path.splitext(resampled_image_name)[0] + "." + format
        img.save(resampled_image_name)

这是我的c#代码

        Bitmap bitmap = new Bitmap(width, height);

        using (Graphics gr = Graphics.FromImage(bitmap))
        {
            gr.DrawImage(srcImage, new Rectangle(0, 0, width, height));
        }

        FileInfo info = new FileInfo(resampledImageName);
        resampledImageName = resampledImageName.Replace(info.Extension, "." + format);

        bitmap.Save(@resampledImageName);

0 个答案:

没有答案