繁体   English   中英

如何调整位图图像的大小并将其设置为Windows Phone 8中网格的背景

[英]How to resize a Bitmap Image and set it as the backgroound of a grid in Windows Phone 8

我尝试这样做,但是在将ImageBrush设置为网格背景之前,我不知道如何设置ImageBrush的高度和宽度。

BitmapImage bmp= new BitmapImage(new Uri(imagePath, UriKind.Relative));
int height = bmp.DecodePixelHeight;
int width = bmp.DecodePixelWidth;

ImageBrush imgBrush = new ImageBrush();
imgBrush.ImageSource = bmp;
MainGrid.Background = imgBrush    // MainGrid is the name of the Grid

如果您只是想将imageBrush设置为适当地填充网格,则将imageBrush的Stretch属性设置为均匀(保持比例,但可能会留空点)或统一填充(保持比例,不会留空点,但整个图片可能不适合网格)。

否则,这里有更复杂的代码来设置imageBrush的确切像素宽度和高度。

http://msdn.microsoft.com/en-us/library/ms742114.aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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