/// <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(); }