相关疑难解决方法(0)

将BitmapImage转换为Byte数组

我想在Windows Phone 7应用程序中将BitmapImage转换为ByteArray.所以我尝试了这个,但它抛出了运行时异常"无效的指针异常".任何人都可以解释为什么我要做的事情抛出异常.您能为此提供替代解决方案吗?

    public static byte[] ConvertToBytes(this BitmapImage bitmapImage)
    {
        byte[] data;
        // Get an Image Stream
        using (MemoryStream ms = new MemoryStream())
        {
            WriteableBitmap btmMap = new WriteableBitmap(bitmapImage);

            // write an image into the stream
            Extensions.SaveJpeg(btmMap, ms,
                bitmapImage.PixelWidth, bitmapImage.PixelHeight, 0, 100);

            // reset the stream pointer to the beginning
            ms.Seek(0, 0);
            //read the stream into a byte array
            data = new byte[ms.Length];
            ms.Read(data, 0, data.Length);
        }
        //data now holds the bytes of the image
        return data;
    }
Run Code Online (Sandbox Code Playgroud)

c# windows-phone-7

13
推荐指数
2
解决办法
4万
查看次数

在运行时获取图像的宽度和高度 - WP8

我正在使用Windows Phone 8应用程序.

我有一条通往图像的道路 - /Data/Images/image1.png.我能够在屏幕上显示此图像,但我想在渲染之前更改图像的宽度和高度.

这就是我在显示图像的方式 webbrowser control

webbrowser.Append("<img src=""+path+ width=\"250\" height=\"250\" style=\"vertical-align:middle\" alt=\"\"></img>"/>"
Run Code Online (Sandbox Code Playgroud)

在这里我设置宽度和高度,250x250但我想改变高度和宽度,因为一些图像不好看.

c# silverlight image windows-phone windows-phone-8

0
推荐指数
1
解决办法
805
查看次数