I want to create a program that can write my TImage pixels RGB color in a memo, the program does not know the resolution.
How do I retrieve every pixel color in String Variable (R, G, B)?
Code
var Image_width, Image_height, X, Y, I, i2: integer; Color: TColor; Start Image_width: = Image1.Width; IMAGE_HEIGHT: = Image1.Height; Memo1.text: = '$ image_width = *' + IntToStr (Image_Width) + '$$ image_height =' + IntToStr (image_hett) + '* $'; X: = 1; Y: = 1; I: For = 1 image_method starting for i2: = 1 start image_highlight color: = image 1. Canvas. Pixel [x, y]; Memo1.Text: = memo1.Text + ColorToString (Color); Y: = y + 1; End; X: = x + 1 end; End | Edited |
Process TForm1.Button2Click (Sender: Tubbed); Var image_width, image_height, x, y: integer; Color: TColor; S: string; Start Image_width: = Image1.Width; IMAGE_HEIGHT: = Image1.Height; Memo1.text: = '$ image_width = *' + IntToStr (Image_Width) + '* $ $ image_height = *' + IntToStr (image_hett) + '* $'; X: = 0; Y: = 0; Memo1.Lines.BeginUpdate; Start from X: = 0 to Image_width y: Let's start Image_height from = 0; Color: = Image1.Canvas.Pixels [x, y]; Memo1.Text: = Memo1.Text + ColorToString (Color); End; Memo1.Lines.EndUpdate; End; End; It is very slow, I think a 640x480 picture with the 1940s. And after the program was ready, and it was placed on memo 1, I'm seeing something in memo 1, but the program "is not responding again" ..
I have tried Try those variables, and the program does the same.
First Correction , Pixel 0 starts with 0. no , 1 as you have Change the initial value to Actually, there is no need to assign Second Correction , look for the internal Suggestions for improvement It is not clear if If you mean Color Depth or Bit Per Pixel, then it may be that the approach using your Repeatedly adding color string to the and then by adding the text to the text property If you intend to add each pixel color string as a new line in the memo, you can change the Finally, you can just do the right thing, either use for loops as the following:
x: = 0; // no 1; Y: = 0; // no 1; y to this point as we will see soon. to loop 1 from the image_hete i2 step and y are incremented in each round of loop, which is fine is. Then a trip to the external loop pay scale x and we come back to the inner loop. What happens to y? It was previously stopped, where it was previously reset to 0. The treatment is to add a line as follows. This is also the reason why the above assignment is redundant.
i: i = 1 to start Image_width y: = 0; // Add this line to I2: Starting image_height from = 1 pixels is more straight forward: resolution is unknown. . Otherwise, as suggested in the comments, you may consider using Scanline instead of pixels for quick access to actual bitmap data. For an excellent article, see: text property is very slow. In fact it was so slow with the 64 x 64 pixel image that I Could not wait to walk till the end. To speed it up, you can use a different string variable, in which you add color string
color: = Image1.Canvas.Pixels [x , Y]; S: = s + ColorToString (color);
memo1.Text: = memo1.Text + s; Add method
Color: = Picture 1. Canvas. Pixel [x, y]; Memo1.Lines.Add (ColorToString (Color)); for with loops memo1.Lines.BegginUpdate; and memo1.Lines.EndUpdate; Further speed improves. x and y such as loop control variables or i As a pixel indexed I will have to switched and i and i2 and both the code controls and the pixel index as both < Code> x y . But I leave it for you to decide.
No comments:
Post a Comment