public void StretchHistogram() { CreateHistogram(); int newR; int newG; int newB; int diffR = maxR - minR; int diffG = maxG - minG; int diffB = maxB - minB; try { bitmapData = BasicImageOpertions.BitmapToBitmapData(bitmap); int bytesPerPixel = System.Drawing.Bitmap.GetPixelFormatSize(bitmap.PixelFormat) / 8; int heightInPixels = bitmapData.Height; int widthInBytes = bitmapData.Width * bytesPerPixel; unsafe // C# doesn't support pointer arithmetic { byte *PtrFirstPixel = (byte *)bitmapData.Scan0; // Point to first pixel for (int y = 0; y < heightInPixels; y++) { byte *currentLine = PtrFirstPixel + (y * bitmapData.Stride); for (int x = 0; x < widthInBytes; x += bytesPerPixel) { newR = (int)((currentLine[x + 2] - minR) * 255 / diffR); newG = (int)((currentLine[x + 1] - minG) * 255 / diffG); newB = (int)((currentLine[x] - minB) * 255 / diffB); currentLine[x + 2] = (byte)newR; currentLine[x + 1] = (byte)newG; currentLine[x] = (byte)newB; } } bitmap.UnlockBits(bitmapData); } } catch { System.Windows.Forms.MessageBox.Show("Please select image first", "Error"); } caller.SetImageAndHist(bitmap); }
private void btnAccept_Click(object sender, EventArgs e) { caller.SetImageAndHist(output); this.Close(); }
private void btnOK_Click(object sender, EventArgs e) { originalImage = ChangeImage(originalImage); caller.SetImageAndHist(originalImage); this.Dispose(); }