ARUP.IssueTracker.Revit.AddIssueRevit.ConvertBitmapTo96DPI C# (CSharp) Method

ConvertBitmapTo96DPI() public static method

public static ConvertBitmapTo96DPI ( BitmapImage bitmapImage ) : System.Windows.Media.Imaging.BitmapSource
bitmapImage System.Windows.Media.Imaging.BitmapImage
return System.Windows.Media.Imaging.BitmapSource
        public static BitmapSource ConvertBitmapTo96DPI(BitmapImage bitmapImage)
        {
            try
            {
                double dpi = 96;
                int width = bitmapImage.PixelWidth;
                int height = bitmapImage.PixelHeight;

                int stride = width * 4; // 4 bytes per pixel
                byte[] pixelData = new byte[stride * height];
                bitmapImage.CopyPixels(pixelData, stride, 0);

                return BitmapSource.Create(width, height, dpi, dpi, PixelFormats.Bgra32, null, pixelData, stride);
            }

            catch (System.Exception ex1)
            {
                TaskDialog.Show("Error!", "exception: " + ex1);
            }
            return null;
        }