C# 将图片保存在与手机大小相同的媒体库中';windows phone中的屏幕大小
在我的windows phone应用程序中,我想将媒体库中的图片保存为与手机屏幕大小相同的大小。C# 将图片保存在与手机大小相同的媒体库中';windows phone中的屏幕大小,c#,windows-phone-7,windows-phone-8,C#,Windows Phone 7,Windows Phone 8,在我的windows phone应用程序中,我想将媒体库中的图片保存为与手机屏幕大小相同的大小。 我正在这样做 WriteableBitmap wb = new WriteableBitmap(480, 800); wb.Render(myitem, null); // myItem is a UI Element wb.Invalidate(); // create temporary image from it
我正在这样做
WriteableBitmap wb = new WriteableBitmap(480, 800);
wb.Render(myitem, null); // myItem is a UI Element
wb.Invalidate();
// create temporary image from it
Image tmpImg = new Image();
tmpImg.Source = wb;
// this is required by WriteableBitmap
tmpImg.Measure(new Size(480, 800));
tmpImg.Arrange(new Rect(0, 0, 100, 100));
WriteableBitmap writeableBitmap = new WriteableBitmap(480, 800);
writeableBitmap.Render(tmpImg, null);
writeableBitmap.Invalidate();
using (var mediaLibrary = new MediaLibrary())
{
using (var stream = new MemoryStream())
{
writeableBitmap .SaveJpeg(stream, writeableBitmap .PixelWidth, writeableBitmap
.PixelHeight, 0, 100);
stream.Seek(0, SeekOrigin.Begin);
var picture = mediaLibrary.SavePicture("chk.jpg", stream);
}
}
我明白了
我想要这个
如果您的问题是关于如何获得手机的物理像素大小,请尝试以下方法:
var frame = Window.Current.Content as Frame;
var width = frame.ActualWidth;
var height = frame.ActualHeight;
double resolutionscale;
#if WINDOWS_APP
resolutionscale = ((int)Windows.Graphics.Display.DisplayInformation.GetForCurrentView().ResolutionScale / 100d);
#elif WINDOWS_PHONE_APP
resolutionscale = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
resolutionscale = Math.Pow(resolutionscale, 2d);
#elif WINDOWS_PHONE
resolutionscale = ((int)Windows.Graphics.Display.DisplayProperties.ResolutionScale / 100d);
#endif
var physicalSize = new Size(width * resolutionscale, height * resolutionscale);
手机的屏幕大小不一定是480x800,它可以高达1080x1920。是的。我应该使用什么方法来获得所需的结果?你意识到你必须在接近最后一步之前裁剪图像。以及上下文裁剪。您应该设置
图像
控件的宽度
和高度
属性,并决定拉伸方法,因为设备具有不同的纵横比。我将尝试此方法…我的方法正确吗。?我的意思是,有没有其他实际的方法或东西可以用正确的图像大小来完成保存过程?好吧,如果它编译了,并且你得到了任何结果,那么你就走上了一条非常好的道路。但老实说,我不知道我在截图上看到了什么。。。