c# - byte[] to gray scale BitmapImage -
I start with the 128 x 128 array pair and for each double, in the bytes of 1d array with proportional values Change me
Then I take this array of bytes and I am trying to convert it to a memory stream ( datastream
below) and assign it to a bitmapImage
Has been added to:
imgScan.Width = 128; ImgScan.Height = 128; Bitmapmaz by = new bitmap image (); Bi.SourceRect = New Int32Rect (0, 0, width, height); Bi.StreamSource = datastream; ImgScan.Source = bi;
here imgScan is a
system. Windows Control. Image
This does not produce the desired image (I just get a white square)
How should I go about this?
I think you will find in your code, there must be a full image file in the stream, of data Not a raw block. Here's a bitmap from a block of data (this is not a grayscale, but you might get this idea):
const int bytesPerPixel = 4; Int Stride = Bitespixel * PixelPerline; UInt32 [] pixelbites = new UIT [lincoln * pixelpelleline]; For (int y = 0; y and lt; line count; y ++) {int destinationLineStart = y * pixelsPerLine; Int sourceLineStart = y * pixels on line; For (int x = 0; x & lt; pixelsPerLine; x ++) {pixelBytes [x] = _rgb pixels [x] .Pbgr32; }} Var BMP = Bitmapsource.Creat (PixelPerline, LineCount, 96, 96, Pixel Formats. Pg 32, Blank, PixelBayte, Stride); Bmp.Freeze (); Return BMP;
You have already made bits (byte array) in nested loops, but I have left it so that you can see what comes before creating
Comments
Post a Comment