mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Issue 1175 fix toBitmap() to ignore padding bytes
git-svn-id: https://zxing.googlecode.com/svn/trunk@2217 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
b73a4af77b
commit
99d4b42b91
|
@ -139,35 +139,35 @@ namespace com.google.zxing.common
|
|||
{
|
||||
const byte BLACK = 0;
|
||||
const byte WHITE = 255;
|
||||
sbyte[][] array = this.Array;
|
||||
int width = this.Width;
|
||||
int height = this.Height;
|
||||
byte[] pixels = new byte[width * height];
|
||||
int width = Width;
|
||||
int height = Height;
|
||||
|
||||
// create the bitmap and lock the bits because we need the stride
|
||||
// which is the width of the image and possible padding bytes
|
||||
var bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
|
||||
var bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat);
|
||||
try
|
||||
{
|
||||
var pixels = new byte[bmpData.Stride*height];
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
int offset = y * width;
|
||||
for (int x = 0; x < width; x++)
|
||||
var offset = y*bmpData.Stride;
|
||||
for (var x = 0; x < width; x++)
|
||||
{
|
||||
pixels[offset + x] = array[y][x] == 0 ? BLACK : WHITE;
|
||||
pixels[offset + x] = this[x, y] ? BLACK : WHITE;
|
||||
}
|
||||
}
|
||||
|
||||
//Here create the Bitmap to the known height, width and format
|
||||
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
|
||||
|
||||
//Create a BitmapData and Lock all pixels to be written
|
||||
BitmapData bmpData =
|
||||
bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
|
||||
ImageLockMode.WriteOnly, bmp.PixelFormat);
|
||||
|
||||
//Copy the data from the byte array into BitmapData.Scan0
|
||||
Marshal.Copy(pixels, 0, bmpData.Scan0, pixels.Length);
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
//Unlock the pixels
|
||||
bmp.UnlockBits(bmpData);
|
||||
}
|
||||
|
||||
//Return the bitmap
|
||||
return bmp;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue