Note that there are some explanatory texts on larger screens.

plurals
  1. POCropping a bitmap gives an empty bitmap
    text
    copied!<p>I've taken a code from here (SO) that crops images. I tried it on bitmaps containing black text on white font. The result i get in return is a completely white output with no content.</p> <pre><code> // create new bitmap with desired size and same pixel format Bitmap croppedBitmap = new Bitmap(rect.Width, rect.Height, bitmap.PixelFormat); // create Graphics "wrapper" to draw into our new bitmap // "using" guarantees a call to gfx.Dispose() using (Graphics gfx = Graphics.FromImage(croppedBitmap)) { // draw the wanted part of the original bitmap into the new bitmap gfx.DrawImage(bitmap, 0, 0, rect, GraphicsUnit.Pixel); } return croppedBitmap; </code></pre> <p>Any guess?</p> <p><strong>PS</strong> if i crop in paint of course it does work</p> <p><strong>edit</strong></p> <p>If I crop a picture of me for example it works....</p> <p><strong>Appendix</strong></p> <p>Code:</p> <p><strong>Rectangles</strong>:</p> <pre><code> Rectangle 1: 8 50, 95, 80, 30 // invoice number Rectangle 2: 625, 778, 475, 22 // Total amount </code></pre> <p><strong>CropImage():</strong></p> <pre><code> public static Bitmap CropImage(Bitmap bitmap, Rectangle rect) { Bitmap croppedBitmap = new Bitmap(rect.Width, rect.Height, bitmap.PixelFormat); using (Graphics gfx = Graphics.FromImage(croppedBitmap)) { gfx.DrawImage(bitmap, 0, 0, rect, GraphicsUnit.Pixel); } return croppedBitmap; } </code></pre> <p>Image: (Sensitive data is hidden, I only left the part I'm trying to crop) <a href="http://img33.imageshack.us/img33/5703/modelx.png" rel="nofollow">http://img33.imageshack.us/img33/5703/modelx.png</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload