本文整理汇总了C#中FastBitmap.LockBitmap方法的典型用法代码示例。如果您正苦于以下问题:C# FastBitmap.LockBitmap方法的具体用法?C# FastBitmap.LockBitmap怎么用?C# FastBitmap.LockBitmap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FastBitmap
的用法示例。
在下文中一共展示了FastBitmap.LockBitmap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawGraph
public FastBitmap DrawGraph(string StatName, double MaxVal)
{
Bitmap bitmap = new Bitmap(200, 200, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
FastBitmap bmp = new FastBitmap(bitmap);
bmp.LockBitmap();
ProfilerValueManager statManager = GetStat(StatName);
double ScaleFactor = 1 / (MaxVal / 200); //We multiply by this so that the graph uses the full space
double[] Stats = statManager.GetInfos();
for (int x = 200; x > 0; x--)
{
for (int y = 200; y > 0; y--)
{
//Note: we do 200-y to flip the graph on the Y axis
if (IsInGraphBar(x, y, Stats, ScaleFactor))
bmp.SetPixel(x, 200 - y, BarColor);
else
{
//Check whether the line needs drawn
if (DrawLine(y, ScaleFactor))
bmp.SetPixel(x, 200 - y, LineColor);
else
bmp.SetPixel(x, 200 - y, BackgroundColor);
}
}
}
bmp.UnlockBitmap();
return bmp;
}
示例2: FastBitmapEnumerator
public FastBitmapEnumerator(FastBitmap fastBitmap)
{
fastBitmap.LockBitmap();
locked = true;
this.fastBitmap = fastBitmap;
x = -1;
y = 0;
pCurrentPixel = fastBitmap[x, y];
}
示例3: getImage
public Bitmap getImage()
{
try
{
ReadHeader();
}
catch(Exception)
{
throw new IOException("Open PPM Exception - Couldn't read header!");
}
Bitmap bitmap = new Bitmap( width, height );
FastBitmap fb = new FastBitmap(bitmap);
fb.LockBitmap();
int x;
int y;
try
{
for(y = 0; y < height; y++ )
{
for(x = 0; x < width; x++)
{
unsafe
{
PixelData* pd = fb[x, y];
pd->red = (byte)ReadByte();
pd->green = (byte)ReadByte();
pd->blue = (byte)ReadByte();
}
//bitmap.SetPixel( x, y, Color.FromArgb( makeRgb( ReadByte(), ReadByte(), ReadByte() ) ) ) ;
}
}
}
catch(Exception)
{
throw new IOException("Open PPM Exception - Couldn't read image data!");
}
fb.UnlockBitmap();
_images.Clear();
_images.Add(bitmap);
return bitmap;
}
示例4: DrawGraph
public FastBitmap DrawGraph(string StatName)
{
Bitmap bitmap = new Bitmap(200, 200, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
FastBitmap bmp = new FastBitmap(bitmap);
bmp.LockBitmap();
ProfilerValueManager statManager = GetStat(StatName);
double MaxVal = statManager.GetMaxValue();
double ScaleFactor = 1 / (MaxVal / 200); //We multiply by this so that the graph uses the full space
ProfilerValueInfo[] Stats = new ProfilerValueInfo[10];
int i = 0;
foreach (ProfilerValueInfo info in statManager.GetInfos())
{
Stats[i] = info;
i++;
}
for (i = 0; i < Stats.Length; i++)
{
//Update the scales
Stats[i].Value = Stats[i].Value * ScaleFactor;
}
for (int x = 200; x > 0; x--)
{
for (int y = 200; y > 0; y--)
{
//Note: we do 200-x and 200-y to flip the graph on the X and Y axises
if (IsInGraphBar(x, y, Stats))
bmp.SetPixel(200 - x, 200 - y, BarColor);
else
{
//Check whether the line needs drawn
if (DrawLine(y, ScaleFactor))
bmp.SetPixel(200 - x, 200 - y, LineColor);
else
bmp.SetPixel(200 - x, 200 - y, BackgroundColor);
}
}
}
bmp.UnlockBitmap();
return bmp;
}
示例5: DrawGraph
public FastBitmap DrawGraph(string StatName)
{
Bitmap bitmap = new Bitmap(200, 200, PixelFormat.Format24bppRgb);
FastBitmap bmp = new FastBitmap(bitmap);
bmp.LockBitmap();
ProfilerValueManager statManager = GetStat(StatName);
double MaxVal = 0;
if (statManager != null)
MaxVal = statManager.GetMaxValue();
double ScaleFactor = 1/(MaxVal/200); //We multiply by this so that the graph uses the full space
double[] Stats2 = new double[0];
if (statManager != null)
Stats2 = statManager.GetInfos();
for (int i = 0; i < Stats2.Length; i++)
{
//Update the scales
Stats2[i] = Stats2[i]*ScaleFactor;
}
for (int x = 200; x > 0; x--)
{
for (int y = 200; y > 0; y--)
{
//Note: we do 200-y to flip the graph on the Y axis
if (IsInGraphBar(x, y, Stats2, ScaleFactor))
bmp.SetPixel(x, 200 - y, BarColor);
else
{
//Check whether the line needs drawn
bmp.SetPixel(x, 200 - y, DrawLine(y, ScaleFactor) ? LineColor : BackgroundColor);
}
}
}
bmp.UnlockBitmap();
return bmp;
}
示例6: MakeWarpMap
public static Bitmap MakeWarpMap(ProjectorEntry pe, double domeSize, bool radialDistortion, List<GroundTruthPoint> gtPointList, ScreenTypes screenType)
{
List<Vector2d> PointTo = new List<Vector2d>();
List<Vector2d> PointFrom = new List<Vector2d>();
double xFactor = pe.Width / 512.0;
double yFactor = pe.Height / 512.0;
Bitmap bmp = new Bitmap(512, 512);
FastBitmap fastBmp = new FastBitmap(bmp);
SolveProjector spProjector = new SolveProjector(pe, domeSize, ProjectionType.Projector, screenType, SolveParameters.Default);
spProjector.RadialDistorion = radialDistortion;
SolveProjector spView = new SolveProjector(pe, domeSize, ProjectionType.View, ScreenTypes.Spherical, SolveParameters.Default);
spView.RadialDistorion = false;
foreach (GroundTruthPoint gt in gtPointList)
{
PointFrom.Add(new Vector2d((double)gt.X / (double)pe.Width * 512, (double)gt.Y / (double)pe.Height * 512));
Vector2d pntOutTarget = spView.ProjectPoint(new Vector2d(gt.Az, gt.Alt));
Vector2d AltAzMapped = spProjector.GetCoordinatesForScreenPoint(gt.X,gt.Y);
Vector2d pntOutMapped = spView.ProjectPoint(new Vector2d(AltAzMapped.X, AltAzMapped.Y));
pntOutTarget.X = pntOutTarget.X *(512 / 2.0) + (512 / 2.0);
pntOutTarget.Y = pntOutTarget.Y *(-512 / 2.0) + (512 / 2.0);
pntOutMapped.X = pntOutMapped.X *(512 / 2.0) + (512 / 2.0);
pntOutMapped.Y = pntOutMapped.Y *(-512 / 2.0) + (512 / 2.0);
PointTo.Add(new Vector2d(pntOutTarget.X - pntOutMapped.X, pntOutTarget.Y - pntOutMapped.Y));
}
//Matrix3d projMat = spView.GetCameraMatrix();
unsafe
{
fastBmp.LockBitmap();
for (int y = 0; y < 512; y++)
{
for (int x = 0; x < 512; x++)
{
Vector2d pnt = spProjector.GetCoordinatesForScreenPoint(x * xFactor, y * yFactor);
Vector2d pntOut = spView.ProjectPoint(pnt);
// Map
pntOut.X = pntOut.X * (512 / 2.0) + (512 / 2.0);
pntOut.Y = pntOut.Y * (-512 / 2.0) + (512 / 2.0);
pntOut = MapPoint(new Vector2d(x,y), pntOut, PointTo, PointFrom);
pntOut.X = (pntOut.X - (512 / 2.0)) / (512 / 2.0);
pntOut.Y = (pntOut.Y - (512 / 2.0)) / (-512 / 2.0);
// End Map
double xo = pntOut.X * (4096 / 2.0) + (4096 / 2.0);
double yo = pntOut.Y * (-4096 / 2.0) + (4096 / 2.0);
int blue = (int)xo & 255;
int green = (int)yo & 255;
int red = (((int)yo) >> 4 & 240) + (((int)xo) >> 8 & 15);
*fastBmp[x, y] = new PixelData(red, green, blue, 255);
}
}
fastBmp.UnlockBitmap();
}
return bmp;
}
示例7: TerrainToBitmap
public Bitmap TerrainToBitmap(Bitmap mapbmp)
{
FastBitmap unsafeBMP = new FastBitmap(mapbmp);
unsafeBMP.LockBitmap();
//DateTime start = DateTime.Now;
//MainConsole.Instance.Info("[MAPTILE]: Generating Maptile Step 1: Terrain");
// These textures should be in the AssetCache anyway, as every client conneting to this
// region needs them. Except on start, when the map is recreated (before anyone connected),
// and on change of the estate settings (textures and terrain values), when the map should
// be recreated.
RegionSettings settings = m_scene.RegionInfo.RegionSettings;
// the four terrain colors as HSVs for interpolation
HSV hsv1 = new HSV(computeAverageColor(settings.TerrainTexture1, defaultColor1));
HSV hsv2 = new HSV(computeAverageColor(settings.TerrainTexture2, defaultColor2));
HSV hsv3 = new HSV(computeAverageColor(settings.TerrainTexture3, defaultColor3));
HSV hsv4 = new HSV(computeAverageColor(settings.TerrainTexture4, defaultColor4));
float levelNElow = (float) settings.Elevation1NE;
float levelNEhigh = (float) settings.Elevation2NE;
float levelNWlow = (float) settings.Elevation1NW;
float levelNWhigh = (float) settings.Elevation2NW;
float levelSElow = (float) settings.Elevation1SE;
float levelSEhigh = (float) settings.Elevation2SE;
float levelSWlow = (float) settings.Elevation1SW;
float levelSWhigh = (float) settings.Elevation2SW;
float waterHeight = (float) settings.WaterHeight;
ITerrainChannel heightmap = m_scene.RequestModuleInterface<ITerrainChannel>();
float sizeRatio = m_scene.RegionInfo.RegionSizeX/(float) Constants.RegionSize;
for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += sizeRatio)
{
float rowRatio = y/(m_scene.RegionInfo.RegionSizeY - 1); // 0 - 1, for interpolation
for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += sizeRatio)
{
float columnRatio = x/(m_scene.RegionInfo.RegionSizeX - 1); // 0 - 1, for interpolation
float heightvalue = getHeight(heightmap, (int) x, (int) y);
if (heightvalue > waterHeight)
{
// add a bit noise for breaking up those flat colors:
// - a large-scale noise, for the "patches" (using an doubled s-curve for sharper contrast)
// - a small-scale noise, for bringing in some small scale variation
//float bigNoise = (float)TerrainUtil.InterpolatedNoise(x / 8.0, y / 8.0) * .5f + .5f; // map to 0.0 - 1.0
//float smallNoise = (float)TerrainUtil.InterpolatedNoise(x + 33, y + 43) * .5f + .5f;
//float hmod = heightvalue + smallNoise * 3f + S(S(bigNoise)) * 10f;
float hmod =
heightvalue; // 0 - 10
// find the low/high values for this point (interpolated bilinearily)
// (and remember, x=0,y=0 is SW)
float low = levelSWlow*(1f - rowRatio)*(1f - columnRatio) +
levelSElow*(1f - rowRatio)*columnRatio +
levelNWlow*rowRatio*(1f - columnRatio) +
levelNElow*rowRatio*columnRatio;
float high = levelSWhigh*(1f - rowRatio)*(1f - columnRatio) +
levelSEhigh*(1f - rowRatio)*columnRatio +
levelNWhigh*rowRatio*(1f - columnRatio) +
levelNEhigh*rowRatio*columnRatio;
if (high < low)
{
// someone tried to fool us. High value should be higher than low every time
float tmp = high;
high = low;
low = tmp;
}
HSV hsv;
if (hmod <= low) hsv = hsv1; // too low
else if (hmod >= high) hsv = hsv4; // too high
else
{
// HSV-interpolate along the colors
// first, rescale h to 0.0 - 1.0
hmod = (hmod - low)/(high - low);
// now we have to split: 0.00 => color1, 0.33 => color2, 0.67 => color3, 1.00 => color4
if (hmod < 1f/3f) hsv = interpolateHSV(ref hsv1, ref hsv2, hmod*3f);
else if (hmod < 2f/3f) hsv = interpolateHSV(ref hsv2, ref hsv3, (hmod*3f) - 1f);
else hsv = interpolateHSV(ref hsv3, ref hsv4, (hmod*3f) - 2f);
}
//get the data from the original image
Color hsvColor = hsv.toColor();
unsafeBMP.SetPixel((int) (x/sizeRatio),
(int) (((m_scene.RegionInfo.RegionSizeY - 1) - y)/sizeRatio), hsvColor);
}
else
{
// We're under the water level with the terrain, so paint water instead of land
unsafeBMP.SetPixel((int) (x/sizeRatio),
(int) (((m_scene.RegionInfo.RegionSizeY - 1) - y)/sizeRatio), WATER_COLOR);
}
}
}
if (m_mapping != null)
//.........这里部分代码省略.........
示例8: HandleInterleaved
private void HandleInterleaved(String fileName)
{
BinaryReader reader = new BinaryReader(
File.Open( fileName, FileMode.Open ) );
for( int k = 0; k < nImages; k++ )
{
Bitmap retBitmap = new Bitmap( width, height );
FastBitmap fb = new FastBitmap(retBitmap);
//Skip the offset
if( offset > 0 )
reader.ReadBytes( offset );
fb.LockBitmap();
for( int j=0; j < height; j++ )
{
for( int i=0; i < width; i++ )
{
unsafe
{
Color c = ReadColor(reader);
PixelData* pd = fb[i, j];
pd->red = c.R;
pd->green = c.G;
pd->blue = c.B;
}
//retBitmap.SetPixel( i,j, ReadColor( reader ) );
}
}
fb.UnlockBitmap();
Images.Add( retBitmap );
}
reader.BaseStream.Seek(0, SeekOrigin.Begin);
_imageData = reader.ReadBytes( (int)reader.BaseStream.Length );
reader.Close();
}
示例9: BlurBitmap
public static void BlurBitmap(Bitmap bmp, int blur)
{
unsafe
{
if ((blur & 1) == 0)
{
blur += 1;
}
FastBitmap fastBmp = new FastBitmap(bmp);
Bitmap temp = new Bitmap(bmp.Height, bmp.Height);
FastBitmap fastTemp = new FastBitmap(temp);
fastBmp.LockBitmap();
fastTemp.LockBitmap();
int height = bmp.Height;
int width = bmp.Width;
int offset = (blur) / 2;
int back = blur - offset;
{
// First blur on x Direction
for (int y = 0; y < height; y++)
{
int currentRed = 0;
int currentGreen = 0;
int currentBlue = 0;
// prime the running sum
for (int x = 0 - offset; x < offset; x++)
{
PixelData* pixelIn = fastBmp[x, y];
currentRed += pixelIn->red;
currentGreen += pixelIn->green;
currentBlue += pixelIn->blue;
}
for (int x = offset; x < (width + back); x++)
{
// Bring in the new data
PixelData* pixelIn = fastBmp[x, y];
currentRed += pixelIn->red;
currentGreen += pixelIn->green;
currentBlue += pixelIn->blue;
PixelData* pixelOut = fastTemp[x - offset, y];
// Move the average value to the center pixel output
pixelOut->alpha = 255;
pixelOut->red = (byte)(currentRed / blur);
pixelOut->green = (byte)(currentGreen / blur);
pixelOut->blue = (byte)(currentBlue / blur);
// Clear out the oldest
pixelIn = fastBmp[x - (offset * 2), y];
currentRed -= pixelIn->red;
currentGreen -= pixelIn->green;
currentBlue -= pixelIn->blue;
}
}
}
// Now with X & Y reveresed
{
for (int y = 0; y < width; y++)
{
int currentRed = 0;
int currentGreen = 0;
int currentBlue = 0;
// prime the running sum
for (int x = 0 - offset; x < offset; x++)
{
PixelData* pixelIn = fastTemp[y, x];
currentRed += pixelIn->red;
currentGreen += pixelIn->green;
currentBlue += pixelIn->blue;
}
for (int x = offset; x < (height + back); x++)
{
// Bring in the new data
PixelData* pixelIn = fastTemp[y, x];
currentRed += pixelIn->red;
currentGreen += pixelIn->green;
currentBlue += pixelIn->blue;
PixelData* pixelOut = fastBmp[y, x - offset];
// Move the average value to the center pixel output
pixelOut->alpha = 255;
pixelOut->red = (byte)(currentRed / blur);
pixelOut->green = (byte)(currentGreen / blur);
pixelOut->blue = (byte)(currentBlue / blur);
// Clear out the oldest
pixelIn = fastTemp[y , x - (offset * 2)];
currentRed -= pixelIn->red;
currentGreen -= pixelIn->green;
currentBlue -= pixelIn->blue;
}
}
//.........这里部分代码省略.........
示例10: GetBitmapFloat
private Bitmap GetBitmapFloat(double min, double max, ScaleMap scale)
{
float[] buf = (float[])DataBuffer;
double factor = max - min;
int stride = AxisSize[0];
int page = AxisSize[0] * AxisSize[1];
Bitmap bmp = new Bitmap(AxisSize[0], AxisSize[1]);
FastBitmap fastBmp = new FastBitmap(bmp);
fastBmp.LockBitmap();
unsafe
{
for (int y = 0; y < AxisSize[1]; y++)
{
int indexY = ((AxisSize[1] - 1) - y);
PixelData* pData = fastBmp[0, y];
for (int x = 0; x < AxisSize[0]; x++)
{
if (color)
{
double datR = buf[(x + indexY * stride)];
double datG = buf[(x + indexY * stride) + page];
double datB = buf[(x + indexY * stride) + page * 2];
if (ContainsBlanks && (double)datR == BlankValue)
{
*pData++ = new PixelData(0, 0, 0, 0);
}
else
{
int r = scale.Map(datR);
int g = scale.Map(datG);
int b = scale.Map(datB);
*pData++ = new PixelData(r, g, b, 255);
}
}
else
{
double dataValue = buf[x + indexY * stride];
if (ContainsBlanks && (double)dataValue == BlankValue)
{
*pData++ = new PixelData(0, 0, 0, 0);
}
else
{
Byte val = scale.Map(dataValue);
*pData++ = new PixelData(val, val, val, 255);
}
}
}
}
}
fastBmp.UnlockBitmap();
return bmp;
}
示例11: SculptMap
public SculptMap(Bitmap bm, int lod)
{
int bmW = bm.Width;
int bmH = bm.Height;
if (bmW == 0 || bmH == 0)
throw new Exception("SculptMap: bitmap has no data");
int numLodPixels = lod*2*lod*2; // (32 * 2)^2 = 64^2 pixels for default sculpt map image
bool needsScaling = false;
bool smallMap = bmW*bmH <= lod*lod;
width = bmW;
height = bmH;
while (width*height > numLodPixels)
{
width >>= 1;
height >>= 1;
needsScaling = true;
}
try
{
if (needsScaling)
bm = ScaleImage(bm, width, height,
InterpolationMode.NearestNeighbor);
}
catch (Exception e)
{
throw new Exception("Exception in ScaleImage(): e: " + e);
}
if (width*height > lod*lod)
{
width >>= 1;
height >>= 1;
}
int numBytes = (width + 1)*(height + 1);
redBytes = new byte[numBytes];
greenBytes = new byte[numBytes];
blueBytes = new byte[numBytes];
FastBitmap unsafeBMP = new FastBitmap(bm);
unsafeBMP.LockBitmap(); //Lock the bitmap for the unsafe operation
int byteNdx = 0;
try
{
for (int y = 0; y <= height; y++)
{
for (int x = 0; x <= width; x++)
{
Color pixel;
if (smallMap)
pixel = unsafeBMP.GetPixel(x < width ? x : x - 1,
y < height ? y : y - 1);
else
pixel = unsafeBMP.GetPixel(x < width ? x*2 : x*2 - 1,
y < height ? y*2 : y*2 - 1);
redBytes[byteNdx] = pixel.R;
greenBytes[byteNdx] = pixel.G;
blueBytes[byteNdx] = pixel.B;
++byteNdx;
}
}
}
catch (Exception e)
{
throw new Exception("Caught exception processing byte arrays in SculptMap(): e: " + e);
}
//All done, unlock
unsafeBMP.UnlockBitmap();
width++;
height++;
}
示例12: bitmap2Coords
/// <summary>
/// converts a bitmap to a list of lists of coords, while scaling the image.
/// the scaling is done in floating point so as to allow for reduced vertex position
/// quantization as the position will be averaged between pixel values. this routine will
/// likely fail if the bitmap width and height are not powers of 2.
/// </summary>
/// <param name = "bitmap"></param>
/// <param name = "scale"></param>
/// <param name = "mirror"></param>
/// <returns></returns>
private List<List<Coord>> bitmap2Coords(Bitmap bitmap, int scale, bool mirror)
{
int numRows = bitmap.Height/scale;
int numCols = bitmap.Width/scale;
List<List<Coord>> rows = new List<List<Coord>>(numRows);
float pixScale = 1.0f/(scale*scale);
pixScale /= 255;
int imageX, imageY = 0;
int rowNdx, colNdx;
FastBitmap unsafeBMP = new FastBitmap(bitmap);
unsafeBMP.LockBitmap(); //Lock the bitmap for the unsafe operation
for (rowNdx = 0; rowNdx < numRows; rowNdx++)
{
List<Coord> row = new List<Coord>(numCols);
for (colNdx = 0; colNdx < numCols; colNdx++)
{
imageX = colNdx*scale;
int imageYStart = rowNdx*scale;
int imageYEnd = imageYStart + scale;
int imageXEnd = imageX + scale;
float rSum = 0.0f;
float gSum = 0.0f;
float bSum = 0.0f;
for (; imageX < imageXEnd; imageX++)
{
for (imageY = imageYStart; imageY < imageYEnd; imageY++)
{
Color pixel = unsafeBMP.GetPixel(imageX, imageY);
if (pixel.A != 255)
{
pixel = Color.FromArgb(255, pixel.R, pixel.G, pixel.B);
unsafeBMP.SetPixel(imageX, imageY, pixel);
}
rSum += pixel.R;
gSum += pixel.G;
bSum += pixel.B;
}
}
row.Add(mirror
? new Coord(-(rSum*pixScale - 0.5f), gSum*pixScale - 0.5f, bSum*pixScale - 0.5f)
: new Coord(rSum*pixScale - 0.5f, gSum*pixScale - 0.5f, bSum*pixScale - 0.5f));
}
rows.Add(row);
}
unsafeBMP.UnlockBitmap();
return rows;
}
示例13: Shade
public Bitmap Shade (Bitmap source, Color shade, float percent, bool greyScale)
{
FastBitmap bmp = new FastBitmap (source);
bmp.LockBitmap ();
for (int y = 0; y < source.Height; y++) {
for (int x = 0; x < source.Width; x++) {
Color c = bmp.GetPixel (x, y);
if (greyScale) {
int luma = (int)(c.R * 0.3 + c.G * 0.59 + c.B * 0.11);
bmp.SetPixel (x, y, Color.FromArgb (c.A, luma, luma, luma));
} else {
float amtFrom = 1 - percent;
int lumaR = (int)(c.R * amtFrom + shade.R * percent);
int lumaG = (int)(c.G * amtFrom + shade.G * percent);
int lumaB = (int)(c.B * amtFrom + shade.B * percent);
bmp.SetPixel (x, y, Color.FromArgb (c.A, lumaR, lumaG, lumaB));
}
}
}
bmp.UnlockBitmap ();
return bmp.Bitmap ();
}
示例14: HandlePlanar
private void HandlePlanar(String fileName)
{
BinaryReader reader = new BinaryReader(
File.Open( fileName, FileMode.Open ) );
for( int k = 0; k < nImages; k++ )
{
Bitmap retBitmap = new Bitmap( width, height );
FastBitmap fb = new FastBitmap(retBitmap);
//Skip the offset
if( offset > 0 )
reader.ReadBytes( offset );
int totalPixels = width * height;
int []r = new int[ totalPixels ];
int []g = new int[ totalPixels ];
int []b = new int[ totalPixels ];
// Read all R colors
for( int i=0; i < totalPixels; i++ )
{
r[i] = ReadPixel( reader );
}
// Read all G colors
for( int i=0; i < totalPixels; i++ )
{
g[i] = ReadPixel( reader );
}
// Read all B colors
for( int i=0; i < totalPixels; i++ )
{
b[i] = ReadPixel( reader );
}
if( colorOrder == ColorOrder.BGR )
{
int []temp = r;
r = b;
b = temp;
}
int index = 0;
fb.LockBitmap();
for( int j=0; j < height; j++ )
{
for( int i=0; i < width; i++ )
{
unsafe
{
PixelData* pd = fb[i, j];
pd->red = (byte)r[index];
pd->green = (byte)g[index];
pd->blue = (byte)b[index];
}
//retBitmap.SetPixel( i,j, Color.FromArgb(r[index], g[index], b[index] ) );
index ++;
}
}
fb.UnlockBitmap();
Images.Add( retBitmap );
}
reader.BaseStream.Seek(0, SeekOrigin.Begin);
_imageData = reader.ReadBytes( (int)reader.BaseStream.Length );
reader.Close();
}
示例15: ReadAndApplyLUT
public static void ReadAndApplyLUT( Stream file , Bitmap b)
{
BinaryReader reader = new BinaryReader( file );
int []R = new int[256];
int []G = new int[256];
int []B = new int[256];
byte []LUT = reader.ReadBytes( 768 );
// Read the look up table info
for(int i = 0; i < 256; i++ )
{
R[i] = LUT[i];
G[i] = LUT[i + 256];
B[i] = LUT[i + 512];
}
// Close the reader
reader.Close();
FastBitmap fb = new FastBitmap(b);
//Bitmap newBitmap = b;
//Color color;
//Color newColor;
fb.LockBitmap();
unsafe
{
// Apply the look up table
for (int i = 0; i < fb.Bitmap.Width; i++)
{
for (int j = 0; j < fb.Bitmap.Height; j++)
{
PixelData* pd = fb[i, j];
//color = newBitmap.GetPixel(i,j);
//newColor = Color.FromArgb( R[ color.R ], G[ color.G ], B[ color.B ] );
//newBitmap.SetPixel(i,j, newColor );
pd->red = (byte)R[pd->red];
pd->green = (byte)G[pd->green];
pd->blue = (byte)B[pd->blue];
}
}
}
fb.UnlockBitmap();
R = null;
G = null;
B = null;
LUT = null;
}