How to display Grayscale image after changing the indexing in C# -


is a grayscale image I am who I pull dB (it is in bytes). I want to draw some boxes on it using the graphics object and then display this image. {Load // a bitmap object through the first image public byte (TransactionFieldList, BLLImageType imageType; ImagingTransaction.ImagingTransactionField & gt byte [] & lt) buffer, list

 [] DrawOverlayOnGreyscaleImage - What this was coded before was MemoryStream MemoryStream msBitmap = going into new MemoryStream (buffer); Bitmap bitmap obz = null; Bitmap obz = new bitmap (msbitmap); Int bmwidth = bitmap obj width; Int bmheight = Bitmap obz. height; // Drag some text on top graphics g = graphics.frame image (bitmap oz);   

The way the image now object graphics (Format8bppIndexed) changes occur is thrown an exception - "can not be made from an image of a graphics object is an indexed pixel format" . So I changed bitmap to format 24 bprgb. Now, there is no exception. But when I drew boxes on the image to go and try to save her, my image black black is so because "in the case of grayscale" images R = G = B. It is lost after being indexed. I change the bitmap to be indexed again (Format8bbIndexed). Change ColorPalette, but please do not help but I still get a completely black color image. My new address is as follows: -

  public byte [] DrawOverlayOnGreyscaleImage (byte [] buffer, the list & lt; ImagingTransaction.ImagingTransactionField & gt; TransactionFieldList, BLLImageType imageType) through {// first Load image in a bitmap object from MemoryStream MemoryStream msBitmap = going into new MemoryStream (buffer); Bitmap bitmap obz = null; Bitmap obz = new bitmap (msbitmap); Int bmwidth = bitmap obj width; Int bmheight = Bitmap obz. height; Bitmap tmp = new Bitmap (BitmapObj.Width, BitmapObj.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Graphics G = Graphics. Frame Image (TMP); Rectangle Int RectWidth; Int RectHeight; Pen myPen = new pen (system, drawing collar, red, 3); Foreach (Fields in ImagingTransaction.ImagingTransactionField TransactionFieldList) {// First of all, do they want to see rectangles if (imageType == BLLImageType.GreyScale_With_FieldRectangles || imageType == BLLImageType.GreyScale_With_FieldRectangles_and_Field_Data) {RectWidth = Field.LowerRightX - Field.UpperLeftX; Rectite = field. LowerRight Y - field.overreact y; // Check the discretion for negative standards if (Reactavath & lt; = 0) readwd = 10; If (Reichhite & lt; = 0) Rectit = 10; SrcRect = new rectangle (field. Top-left X, field. Top-left Y, readwd, recthite); G.DrawRectangle (myPen, srcRect); } // Now, they want to see the text to the bottom right of the area (imageType == BLLImageType.GreyScale_With_Field_Data || imageType == BLLImageType.GreyScale_With_FieldRectangles_And_Field_Data) {g.DrawString (Field.FieldValue, New Font ("Tahoma ", 12), Brush. Reed, New Point (field.waterwaterxt, field.waterwater.it);) ; }} MemoryStream msBitmapWithRectangle = New MemoryStream (); // Save JPEG format using bitmap tmp2 = new bitmap (tmp.Width, tmp.Height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); Color palette pal = tmp2 Palette; For (int i = 0; i & lt; pal.Entries.Length; i ++) {// Create greyscale color table pal.Entries [i] = Color.FromArgb (i, i, i); } Tmp2.Palette = pal; Tmp2.Save (msBitmapWithRectangle, System.Drawing.imaging.ImageFormat.Jpeg); Read to finish // byte [] byterereththereactengal = msBitmapWithRectangle.GetBuffer (); // cleanup tmp.Dispose (); Tmp2.Dispose (); BitmapObj.Dispose (); MsBitmap.Close (); MsBitmapWithRectangle.Close (); Return byterethroughrectengel; }    

It seems that tmp2 has been created but never filled with original bitmap , So you can completely rectangle the black

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -