0

这是我的代码:

// create image1
var tileControl1 = new FlipCycleTileSmallControl("");
tileControl1.Measure(newSize(159, 159));
tileControl1.Arrange(newRect(0d, 0d, 159, 159));
var writeableBitmap1 = new System.Windows.Media.Imaging.WriteableBitmap(tileControl1, null);
image1.Source = writeableBitmap1;

// create image2 
var tileControl2 = new FlipCycleTileMediumControl("");
tileControl2.Measure(newSize(336, 336));
tileControl2.Arrange(newRect(0d, 0d, 336, 336));
var writeableBitmap2 = new System.Windows.Media.Imaging.WriteableBitmap(tileControl2, null);
image2.Source = writeableBitmap2;

// create image3
var tileControl3 = new FlipCycleTileMediumControl("");
tileControl3.Measure(newSize(691, 336));
tileControl3.Arrange(newRect(0d, 0d, 691, 336));
var writeableBitmap3 = new System.Windows.Media.Imaging.WriteableBitmap(tileControl3, null);
image3.Source = writeableBitmap3;

使用此代码,我想创建一个图像

用户控件(FlipCycleTileSmallControl、FlipCycleTileMediumControl、FlipCycleTileMediumControl)

并将其保存到独立存储。

Image1 很好,但是 image2 和 image3 在黑色背景下不好。

我能做些什么?

4

1 回答 1

0

我不确定你是如何从你提供的代码中得到任何结果的,但它类似于我使用的一些类似的代码。在下面的示例中,我使用用户控制并将图像保存到独立存储中。稍后我可以很容易地参考这条路径。

如果这不是您所希望的,我希望它能激发一个适合您的解决方案。

public static void SaveToIsolatedStorage(this UserControl control, string filename, Size size = new Size())
    {

        var controlWidth = (int) size.Width;
        var controlHeight = (int) size.Height;

        control.Height = controlHeight;
        control.Width = controlWidth;

        control.Arrange(new Rect(0, 0, controlWidth, controlHeight));

        // Create writeable bitmap to save as image
        var wb = new WriteableBitmap(controlWidth, controlHeight);

        // Position child objects
        control.Arrange(new Rect(0, 0, controlWidth, controlHeight));

        // Render element to bitmap
        wb.Render(control, new CompositeTransform());

        // Draw
        wb.Invalidate();

        // At this point you can do what you want with the output of writeable bitmap
        // I recommend saving to isolated storage, the access it locally.

         // Save to isolated storage
        using (var isfs = new IsolatedStorageFileStream(string.Format("/Shared/ShellContent/{0}.jpg", filename), FileMode.Create, IsolatedStorageFile.GetUserStoreForApplication()))
        {
            wb.SaveJpeg(isfs, controlWidth, controlHeight, 0, 100);
        }

    }
于 2014-01-22T04:19:14.223 回答