TImage question lazarus / 39-Graphics ---------------------------------------------------------------------- henrytj · 2007-09-01 02:27 I am manipulating an image in a TImage object using Canvas.Pixels. But when I do a SaveToFile I seem to bet getting the old image and not the new modified one. Is there something between the WorkBitmap.Canvas.Pixels changes and the WorkBitmap.SaveToFile that I need to be doing? Thanks, Henry ---------------------------------------------------------------------- theo · 2007-09-01 10:33 No problem here. The following works as expected for me (GTK):   Image1.Picture.Bitmap.LoadFromFile('/home/theo/logoop.bmp');   Image1.Picture.Bitmap.Canvas.Pen.Color:=clred;   Image1.Picture.Bitmap.Canvas.MoveTo(1,1);   Image1.Picture.Bitmap.Canvas.LineTo(50,50);   Image1.Picture.Bitmap.Canvas.Pixels[2,2]:=clwhite;   Image1.Picture.Bitmap.SaveToFile('/home/theo/logoopn.bmp'); ---------------------------------------------------------------------- henrytj · 2007-09-01 13:29 Could there be a difference between the Image form control and the TBitmap object? I am doing roughly what you did in your test but doing it "behind the scenes" with a TBitmap object. Or there is a flaw in my logic that I can't seem to see. Here is the code in case someone can see what I am doing wrong. Code: [Select] Procedure SaveFinalImage (ImageFileName : String); Var    x, y : Integer;    PixelCalc : TThisPixel; Begin For y := 0 To ArrayMax_y Do     Begin     For x := 0 To ArrayMax_x Do         Begin         With WorkBitmap.Canvas, PixelWorkArray[x, y] Do              Begin              If ImageCount > 0 Then                 Begin                 //PixelCalc.RedVal   := Round (PixelWorkArray[x, y].RedVal   / ImageCount);                 //PixelCalc.GreenVal := Round (PixelWorkArray[x, y].GreenVal / ImageCount);                 //PixelCalc.BlueVal  := Round (PixelWorkArray[x, y].BlueVal  / ImageCount);                 PixelCalc.RedVal   := Round (RedVal   / ImageCount);                 PixelCalc.GreenVal := Round (GreenVal / ImageCount);                 PixelCalc.BlueVal  := Round (BlueVal  / ImageCount);                 Pixels[x, y] := RGBToColor (PixelCalc.RedVal,                                             PixelCalc.GreenVal,                                             PixelCalc.BlueVal);                 //Pixels[x, y] := ClRed;                 End              Else                  Begin                  Pixels[x, y] := clBlack;                  End;//If-Else              End;//With         End;//For     End;//For WorkBitmap.SaveToFile(ImageFileName); End; ---------------------------------------------------------------------- theo · 2007-09-01 13:57 This is not enough information for me to see the problem. Avoid "with" statements while debugging. They are error prone and hard to read for others. What is done with WorkBitmap before calling this? Is it a global variable? What's ImageCount? And most important: How does the result look after calling this procedure? ---------------------------------------------------------------------- henrytj · 2007-09-01 15:17 I never used to use With statements before, but due to the very long lines of code I thought it would help. What I am doing is loading a series of images one at a time into the program and summing up their pixel RGB values  into the PixelWorkArray declared at the Unit level, so I guess it is global is scoping to the Unit. With some test code (not shown) I am satisfied that the pixel RGB values are being summed correctly. The ImageCount is a count of the images that have been summed so that I can calculate the average pixel values across many images. Basically I am averaging many images together to see what special effect I can get out of it. The program is 90%} done. The last part that doesn't seem to be working is going from calculated average going back into the WorkBitmap and it saving to disk. What I am getting as a result of the SaveToFile is the last image that I loaded (LoadFromFile) that I Put into the WorkBitmap (also defined at the Unit level.) Blending images together like this is difficult to do in PS and why this is my first Pascal project to automate this. I worked with Delphi i little about 10 years ago, but used Pascal extensively back in college about 25 years ago. But that was pre GUI and OOP, of course. I was hoping to finish this by the weekend as I need to travel. I spent about 6 hours on it yesterday searching the forums and FP PDF docs. At one time I could have slapped something like this together in a couple hours rather than the days it is taking me. But again, I have not programmed in 5+ years. Sadly I dont have time to work on it anymore today. Frustrating in that it is all but done, save for this last snag. ---------------------------------------------------------------------- theo · 2007-09-01 16:09 I guess it's something in the logic of you code that has not directly to do with the code you showed us above. Another hint: When doing a lot of pixel operations, your approach may be slow. Try using a TLazIntfImage as shown here http://wiki.lazarus.freepascal.org/Developing_with_Graphics#A_fading_e xample Read the part about Lazarus, not Delphi! ---------------------------------------------------------------------- henrytj · 2007-09-03 02:39 After a couple more hours of experimenting I found that if I add the following 3 commands Code: [Select] WorkBitmap.FreeImage; WorkBitmap.Width  := 320; WorkBitmap.Height := 240; Then things work. Apparently I have to "free" the image and then set the size values again. Henry