private string InvertFilter(ICanvasRenderingContext2D ctx) { var di = new DirectoryInfo(Application.StartupPath); string url = di.Parent.Parent.Parent.FullName + "\\SharpCanvas.Tests\\" + @"Originals\Filters\initial.jpg"; ctx.drawImage(url, 0, 0); var data = (ImageData) ctx.getImageData(0, 0, 121, 121); /* var chain = (FilterChain) ctx.createFilterChain(); var filter = new InvertFilter(); chain.AddFilter(filter); data.applyFilters(chain); ctx.putImageData(data, 0, 0); */ return @"Originals\Filters\InvertFilter.png"; }
private void grayscale(ImageData image, ICanvasRenderingContext2D ctx) { ctx.drawImage(image, 0, 0); uint imgWidth = image.width; uint imgHeight = image.height; var imageData = (ImageData) ctx.getImageData(0, 0, imgWidth, imgHeight); for (ulong i = 0; i < imageData.height; i++) { for (ulong j = 0; j < imageData.width; j++) { ulong index = (i*4)*imageData.width + (j*4); var red = (byte) imageData.data[index]; var green = (byte) imageData.data[index + 1]; var blue = (byte) imageData.data[index + 2]; var alpha = (byte) imageData.data[index + 3]; var average = (byte) ((red + green + blue)/3); imageData.data[index] = average; imageData.data[index + 1] = average; imageData.data[index + 2] = average; imageData.data[index + 3] = alpha; } } ctx.putImageData(imageData, imageData.width + 5, 0, 0, 0, imageData.width, imageData.height); }
private string sample5(ICanvasRenderingContext2D ctx) { var img = new ImageData(); img.src = @"backdrop.png"; ctx.drawImage(img, 0, 0, 0, 0); ctx.beginPath(); ctx.moveTo(30, 96); ctx.lineTo(70, 66); ctx.lineTo(103, 76); ctx.lineTo(170, 15); ctx.stroke(); return @"Originals\Images\sample5.png"; }
private string sample7(ICanvasRenderingContext2D ctx) { var img = new ImageData(); img.src = @"rhino.jpg"; var imgFrame = new ImageData(); imgFrame.src = @"picture_frame.png"; ctx.drawImage(img, 33, 71, 104, 124, 21, 20, 87, 104); //ctx.commit(); ctx.drawImage(imgFrame, 0, 0, 0, 0); //ctx.commit(); return @"Originals\Images\sample7.png"; }
private string sample6(ICanvasRenderingContext2D ctx) { var img = new ImageData(); img.src = @"rhino.jpg"; for (int i = 0; i < 4; i++) { for (int j = 0; j < 3; j++) { ctx.drawImage(img, j*50, i*38, 50, 38); } } return @"Originals\Images\sample6.png"; }