/// <summary> /// /// </summary> void buildImage() { if (busy) { return; } if (imagePixelated != null && (imagePixelated.Width == rect.Width && imagePixelated.Height == rect.Height)) { return; } imagePixelated = null; this.Invalidate(); new System.Threading.Thread(new System.Threading.ThreadStart(delegate() { ImageCreator newImage = new ImageCreator(rect.Width, rect.Height); for (int y = 0; y < newImage.Height; y++) { for (int x = 0; x < newImage.Width; x++) { double sx = x / (double)newImage.Width; double sy = y / (double)newImage.Height; sx *= source.Width; sy *= source.Height; sx = Math.Max(0, sx); sy = Math.Max(0, sy); sx = Math.Min(sx, source.Width - 1); sy = Math.Min(sy, source.Height - 1); newImage.SetPixel(x, y, source.GetPixel((int)sx, (int)sy)); } } if (newImage.Width == rect.Width && newImage.Height == rect.Height) { // Create image Image tmp = newImage.Image; lock (this) { imagePixelated = newImage; } this.Invalidate(); } else { busy = false; buildImage(); } })).Start(); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void ImageViewer_Load(object sender, EventArgs e) { new System.Threading.Thread(new System.Threading.ThreadStart(delegate() { ImageContext ic = new ImageContext(image.Width, image.Height, image); ImageCreator source = new ImageCreator(image.Width, image.Height); ic.Lock(); for (int y = 0; y < image.Height; y++) { for (int x = 0; x < image.Width; x++) { source.SetPixel(x, y, ic.GetPixel(x, y)); } } ic.Unlock(); lock (this) { this.source = source; } })).Start(); }
public ImageViewer(Bitmap image, Image background = null) { InitializeComponent(); this.image = image; this.background = background; this.state = State.Idle; this.zoom = 1.0; font = new Font("Arial", 14, FontStyle.Bold, GraphicsUnit.Pixel); shadow = new SolidBrush(Color.FromArgb(128, Color.Black)); line = new Pen(new SolidBrush(Color.Red), 1); timer = new Timer(); timer.Interval = 40; timer.Tick += new EventHandler(timer_Tick); timer.Enabled = true; this.busy = false; this.imagePixelated = null; this.source = null; }