调整位图图像 [英] Resize bitmap image

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

问题描述

我想在保存的图像有更小的尺寸。
我该如何调整呢?
我用这个code为redering图像:

 尺寸大小=新的大小(surface.Width,surface.Height);
surface.Measure(大小);
surface.Arrange(新矩形(尺寸));
//创建一个渲染位图和表面推到它
RenderTargetBitmap renderBitmap =
    新RenderTargetBitmap(
        (INT)size.Width,
        (INT)size.Height,96D,96D,
        PixelFormats.Default);
renderBitmap.Render(面);BmpBitmapEn codeR EN codeR =新BmpBitmapEn codeR();
//呈现的位图推到它
EN coder.Frames.Add(BitmapFrame.Create(renderBitmap));
//数据保存到流
EN coder.Save(outStream);


解决方案

请问你面的视觉已经扩展能力?你可以用它在视框如果没有,则使视框中你想要的大小。

当你调用测量并安排在表面上,你应该提供你想要的位图是大小。

要使用视框,您的code更改为类似以下内容:

  Viewbox控件视框=新Viewbox控件();
大小desiredSize =新的大小(surface.Width / 2,surface.Height / 2);viewbox.Child =表面;
viewbox.Measure(desiredSize);
viewbox.Arrange(新矩形(desiredSize));RenderTargetBitmap renderBitmap =
    新RenderTargetBitmap(
    (INT)desiredSize.Width,
    (INT)desiredSize.Height,96D,96D,
    PixelFormats.Default);
renderBitmap.Render(视框中);

I want to have smaller size at image saved. How can I resize it? I use this code for redering the image:

Size size = new Size(surface.Width, surface.Height);
surface.Measure(size);
surface.Arrange(new Rect(size));
// Create a render bitmap and push the surface to it
RenderTargetBitmap renderBitmap =
    new RenderTargetBitmap(
        (int)size.Width,
        (int)size.Height, 96d, 96d,
        PixelFormats.Default);
renderBitmap.Render(surface);

BmpBitmapEncoder encoder = new BmpBitmapEncoder();
// push the rendered bitmap to it
encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
// save the data to the stream
encoder.Save(outStream);

解决方案

Does your "surface" visual have scaling capability? You can wrap it in a Viewbox if not, then render the Viewbox at the size you want.

When you call Measure and Arrange on the surface, you should provide the size you want the bitmap to be.

To use the Viewbox, change your code to something like the following:

Viewbox viewbox = new Viewbox();
Size desiredSize = new Size(surface.Width / 2, surface.Height / 2);

viewbox.Child = surface;
viewbox.Measure(desiredSize);
viewbox.Arrange(new Rect(desiredSize));

RenderTargetBitmap renderBitmap =
    new RenderTargetBitmap(
    (int)desiredSize.Width,
    (int)desiredSize.Height, 96d, 96d,
    PixelFormats.Default);
renderBitmap.Render(viewbox);

这篇关于调整位图图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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