The problem is that when I test it in IE 6 the image will request a new image from the server. Normally new browsers will load an image once and there are several ways to use that image again. If you execute my code by replacing those lines you probably realize that they both swap Red and green value but the pixel of a man on the image(drewgreen.png) will be different that means the first one didn't change the man color or fg but the second one has huge effect on the man color(pixels). I'm trying to clone an image in javascript, bud without loading a new one. \ if you want to confirm use DLTP environment then it gives (r:255,g:0,b:0 )Īnd also the second one have the same value (r:255,g:0,b:0 ) even though there is typeo difference. in my function case the red one gets value of green(255) before the G turn to 0. SO it will be two different colors: (0,0,255) and (0,255,0).īut your calculation somehow incorrect because in this case it gets blue value which is 0 and set as G. In you first case you have var G = pixel.getBlue() // when(r:0 ,g:255 ,b:0). Print (pix2) // for testing the before and after of the pixel swap` Var pix2 = img.getPixel(50,50) // this is for testing the before and after of the pixel swap Print (pix) //this is for testing the before and after of the pixel swap Var pix = img.getPixel(50,50) //this is for testing the before and after of the pixel swap It is probably overkill, but it appears to work. I have come up with a solution, which seems to work, but it is not in the form of a function as of now. So, for an image it would be r:0 g:255 b:0 before the code is run, and r:255 g:255 b:0 after the code is run. I think your code swaps the green value into red, then checks red's value (which is now the value from green), then inserts that value into green. Print (pix2) ` //print the pixel value for pixel at 1,1 Var pix2 = img.getPixel(1,1) // added this code to check the pixel value after processing The first pixel is orange and has rgb (255,153,51), and the second pixel is green and has rgb (51,153,51). You have two pixels to convert to grayscale, and you would like to determine visually whether your code is likely to be working, so you work an example by hand. Print (pix) //print the pixel value for pixel at 1,1 A script specifying where to find the JavaScript library for SimpleImage. Var pix = img.getPixel(1,1) // added this code to check the pixel values before processing `var img = new SimpleImage("eastereggs.jpg") I used an image with a green background for my test of your code, and it converts the green background to a yellow background, whereas I think it should be a red background. I added some code to check the before and after values for a pixel and it doesn't correctly swap pixels. Your code seems to fail at swapping the pixel values for red and green. ![]() Please forgive any mistakes I have made as I am very new to coding.
0 Comments
Leave a Reply. |