How do you resize a Bitmap under .NET CF 2.0

余生颓废 提交于 2019-12-20 05:42:38

问题


I have a Bitmap that I want to enlarge programatically to ~1.5x or 2x to its original size. Is there an easy way to do that under .NET CF 2.0?


回答1:


One "normal" way would be to create a new Bitmap of the desired size, create a Graphics for it and then draw the old image onto it with Graphics.DrawImage(Point, Rectangle). Are any of those calls not available on the Compact Framework?

EDIT: Here's a short but complete app which works on the desktop:

using System;
using System.Drawing;

class Test
{
    static void Main()
    {
        using (Image original = Image.FromFile("original.jpg"))
        using (Bitmap bigger = new Bitmap(original.Width * 2,
                                   original.Height * 2,
                                   original.PixelFormat))
        using (Graphics g = Graphics.FromImage(bigger))
        {
            g.DrawImage(original, new Rectangle(Point.Empty, bigger.Size));
            bigger.Save("bigger.jpg");
        }
    }
}

Even though this works, there may well be better ways of doing it in terms of interpolation etc. If it works on the Compact Framework, it would at least give you a starting point.




回答2:


The CF has access to the standard Graphics and Bitmap objects like the full framework.

  • Get the original image into a Bitmap
  • Create a new Bitmap of the desired size
  • Associate a Graphics object with the NEW Bitmap
  • Call g.DrawImage() with the old image and the overload to specify width/height
  • Dispose of things

Versions: .NET Compact Framework Supported in: 3.5, 2.0, 1.0



来源:https://stackoverflow.com/questions/1082884/how-do-you-resize-a-bitmap-under-net-cf-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!