BitmapSource的字节数组中的OutOfMemoryException

时间:2017-07-28 06:50:19

标签: .net arrays vb.net bitmap

我已经改变了这个问题,因为我现在相信更多的背景会有意义

我正在尝试使用已有图像中的另一个dpi创建一个新位图。

然而,当我试图创建像这样的字节数组时,我在大图像上得到一个OutOfMemoryException

Private Function ConvertBitmapToXDPI(bitmapImage As BitmapImage, newDpi As Integer) As BitmapSource
     Dim width As Integer = bitmapImage.PixelWidth
     Dim height As Integer = bitmapImage.PixelHeight 'value is => 3456

     Dim stride As Integer = width * bitmapImage.Format.BitsPerPixel 'value is => 110592
     Dim pixelData As Byte() = New Byte(stride * height - 1) {} ' <- EXCEPTION!
     bitmapImage.CopyPixels(pixelData, stride, 0)

     Return BitmapSource.Create(width, height, newDpi, newDpi, bitmapImage.Format, Nothing, pixelData, stride)
 End Function

该方法用作转换器以更改图像的DPI。但是它会在标记的行上抛出OutOfMemoryException。

我的问题是,是否有另一种方法可以做我想做的事情?以上情况适用于较小的图像,但只要图像尺寸较大,就会发生这种情况

0 个答案:

没有答案
相关问题