如何在.NET CF 2.0下调整位图大小 [英] How do you resize a Bitmap under .NET CF 2.0

查看:137
本文介绍了如何在.NET CF 2.0下调整位图大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个位图,我想以编程方式放大到〜1.5x或2x到原始大小。在.NET CF 2.0下有一种简单的方法吗?

解决方案

一种常规方式是创建一个新的位图然后用 Graphics.DrawImage(Point,Rectangle)将旧图像绘制到它上面。是否有任何这些调用在Compact Framework上不可用?



编辑:这是一个简短但完整的应用程序,它在桌面上工作:

 使用System; 
使用System.Drawing;

class Test
{
static void Main()
{
using(Image original = Image.FromFile(original.jpg))
使用(位图更大=新位图(original.Width * 2,
original.Height * 2,
original.PixelFormat))
using(Graphics g = Graphics.FromImage(larger ))
{
g.DrawImage(original,new Rectangle(Point.Empty,larger.Size));
larger.Save(larger.jpg);





即使这样做,在那里可能是更好的插值方式等等。如果它在Compact Framework上工作,它至少会给你一个起点。


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?

解决方案

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.

这篇关于如何在.NET CF 2.0下调整位图大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆