Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27449

VS 2010 Bitmap Stride.

$
0
0
Hi All,
In my project I am trying to implement Crop feature. Till now I am able to crop the image for the rectangle drawn (for selection of region of interest(ROI)) and get the raw data of the ROI. Now I am trying to the display the image. The pixelformat of the image is 8bppIndexed format.

Now I'm trying to display the image with the following code:
Code:


Dim _p8BitPixelData as Intptr
Dim ImagePalette As System.Drawing.Imaging.ColorPalette
Dim Stride As Integer

If _p8BitPixelData = IntPtr.Zero Then
            _p8BitPixelData = AllocHGlobal(RowsCount * ColumnsCount)
End If

        Marshal.Copy(ImageData_8Bit, 0, _p8BitPixelData, RowsCount * ColumnsCount)
        ImageFrom8BitPixelData = New Bitmap(RowsCount, ColumnsCount, Stride, System.Drawing.Imaging.PixelFormat.Format8bppIndexed, _p8BitPixelData)

      ImagePalette = ImageFrom8BitPixelData.Palette

        For i As Integer = 0 To ImagePalette.Entries.Length - 1
            ImagePalette.Entries(i) = Color.FromArgb(MaxPixelValue_EightBitImg, i, i, i)
        Next

        ImageFrom8BitPixelData.Palette = ImagePalette
        Picturebox1.Image = ImageFrom8BitPixelData

But I'm not able to calculate the Stride correctly for various cropped dimensions.

Can anybody please tell me how to exactly calculate the Bitmap's Stride so that I can display image of any cropped width on the picturebox?

Regards,
Susheelss

Viewing all articles
Browse latest Browse all 27449

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>