Raw image pixel access lazarus / 39-Graphics ---------------------------------------------------------------------- user5 · 2019-12-03 22:26 Raw image pixel access is similar to BGRABitmap and in all the examples of it that I have seen it is used in an xy loop as shown in the first code example shown below. My question is: Can it be used outside of an xy loop and if so, how? If possible I would like to use it in conjunction with some code that opens a text file which provides xy coordinates such as shown in the second code example. Is this possible? I've been using TLazIntfImage as shown in the third bit of code and it's fast but sometimes it occasionally fails and an error message appears which says "Invalid horizontal index..." or something like that.  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i while (county < image302.height) do begin  PixelPtr := PixelRowPtr;  while (countx < image302.width) do   begin    tempcolor := PixelPtr^;    tempcolor := SwapRedBlue(tempcolor);    Inc(PByte(PixelPtr), BytePerPixel);    countx := countx + 1;   end;  county := county + 1; end;   while not eof(readfile) do begin  readln(readfile,tempstr);  val(tempstr,x,code);  readln(readln,tempstr);  val(tempstr,y,code);   //other code here  end;   while not eof(readfile) do begin  readln(readfile,tempstr);  val(tempstr,x,code);  readln(readln,tempstr);  val(tempstr,y,code);   lazimage.colors[x,y] := lazcolor;  end; ---------------------------------------------------------------------- winni · 2019-12-03 23:53 Hi! I show you a solution with BGRAbitmap. I don't know if it exists with other bitmaps: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i varimg: TBGRABitmap;i,n : Integer;p.q: PBGRAPixel; beginp := img.data;    for i := 0 to  img.NbPixels -1 { img.Width * img.Height - 1 } do        begin         p^ := DoSomething;         inc(p);        end;       img.InvalidateBitmap; end;  But you can access every single pixel by n := y * Img.width + x; Then you do q := p + n; q^ := clRed; Winni ---------------------------------------------------------------------- user5 · 2019-12-04 05:25 Hmmmm... Your suggestion is interesting but I don't know much about TBGRABitmap or if it can be applied to this case. What I have is a long text file that has information about various pixels in a TImage which is assigned to a bitmap and then to a TLazIntfImage (or TBGRABitmap). The number of entries in the text file don't usually equal the number of pixels in the image.     Each entry in the text file represents a pixel in the image and each entry provides x and y. An example of an entry is shown below. The second line in the sample entry gives a particular color. Lines 5 and 6 respectively provide x and y of the image pixel to be changed. The 7th line provides another color. The program uses these colors to produce a third color. The code I'm currently using looks something like the code shown below following the sample file entry.     I could have some part of the program count the number of entries in the file and then use that count number instead of useing while not eof(readfile). Can you think of a way to apply TBGRABitmap to this case?     Thank you so much for helping me. The last few times that I have asked for help on this forum I received some solutions that were of critical importance to me. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  6clWhite3371489418clBlue while not eof(readfile) do //or for i := to 1 to numberofentries do begin  //the program reads each entry in the text file to get 2 colors along with x and y  //code which uses those 2 colors to produce a third color  lazcolor := TColorToFPColor(thirdcolor);  lazimage.colors[x,y] := lazcolor; //the line that sometimes fails but not always end; ---------------------------------------------------------------------- user5 · 2019-12-04 05:40 Another idea occurred to me. If I can't come up with a way to use TBGRABitmap in this case then I could put "lazimage.colors[x,y] := lazcolor" in a try statement and if it fails then have the program use "mybitmap.canvas.pixels[x,y] := thirdcolor" instead though this wouldn't be the best solution. ---------------------------------------------------------------------- user5 · 2019-12-04 06:35 I just realized that my last idea wouldn't work because the code is working on the TLazIntfImage, not the bitmap. The best that I could do if it failed would be to just pass up that attempt and then try again. Duh. ---------------------------------------------------------------------- circular · 2019-12-04 15:57 You can use TBGRABitmap.SetPixel(x,y,color) for that. ---------------------------------------------------------------------- user5 · 2019-12-04 17:59 So the code would be something like this?     I've had difficulty in installing bgrabitmappackage.lpk in the past but I'm going to try again.     Thanks.     Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var img: TBGRABitmap;    mybitmap:TBitmap;    x,y:integer;    tempcolor,thirdcolor:TColor;    readfile:TextFile; begin  mybitmap := TBitmap.create; mybitmap.width := image1.width; mybitmap.height := image1.height; mybitmap.assign(image1.picture.bitmap); //TImage img := TBGRABitmap.create(mybitmap.width,mybitmap.height); img.assign(mybitma p);  assignfile(readfile,'edges.txt'); reset(readfile);  while not eof(readfile) do //or for i := to 1 to numberofentries do  begin   //the program reads each entry in the text file to get 2 colors along with x and y   //code which uses those 2 colors to produce a third color   img.SetPixel(x,y,thirdcolor);  end;  img.free; mybitmap.free; closefile(readfile); end; ---------------------------------------------------------------------- Handoko · 2019-12-04 18:22 Quote from: user5 on December 04, 2019, 06:59:40 pm    I've had difficulty in installing bgrabitmappackage.lpk in the past but I'm going to try again. Do you know OPM (Online Package Manager)? It makes installing packages much easier. https://wiki.freepascal.org/Online_Package_Manager ---------------------------------------------------------------------- user5 · 2019-12-04 18:38 I'm once again having trouble installing bgrabitmappack.lpk     I downloaded the lpk zip file and unzipped it to a folder     I clicked on Package and then I clicked on Open Package File (.lpk)     I then clicked on bgrabitmappack.lpk     On the window that appeared I clicked on Use but the only highlighted item was Add to Project. Install was not highlighted.     I clicked on Compile but got an error message that said: C:\Users\Art McGinnis\Desktop\temp9\bgrabitmap- master\bgrabitmap\bgramultifiletype.pas(70,58) Error: Identifier not found "RawByteString"     I don't understand what's going on here. I'm not sure what to do now. Maybe I'll check out OPM. What a drag. ---------------------------------------------------------------------- user5 · 2019-12-04 19:06 On the OPM page the instructions said: In Lazarus "Install/Uninstall Packages" window select "OnlinePackageManager" from the available packages, click "Install selection" and then rebuild the IDE.     I did that but OnlinePackageManager was not listed as an available package. I did see an item titled: LazarusPackageManager 0.0.1 and I tried to install it but got an error message that said: Broken dependency - Ome or more required packages were not found.     If someone could provide me with step by step instructions then that might help.     Otherwise I guess that I can't use BGRABitmap. ---------------------------------------------------------------------- Handoko · 2019-12-04 19:13 Don't give up easily sir. What is the version of your Lazarus? OPM can be found in the directory: ($LazarusDir)/components/onlinepackagemanager But if you can't find it (because you're using older Lazarus version), you can download OPM 1.6 from here: https://drive.google.com/file/d/0B9Me_c5onmWobVZOdVlXSlZRRmc/view ---------------------------------------------------------------------- circular · 2019-12-04 22:29 You don't need to install BGRABitmap. Just open the package once and that's it. After that, you can add it to your project. https://wiki.freepascal.org/BGRABitmap_tutorial_1 ---------------------------------------------------------------------- user5 · 2019-12-04 22:30 Yes, you are correct; I had forgotten that I was using an older version of Lazarus because a project I was trying to use wouldn't compile with the newest version of Lazarus.     I uninstalled the old version and installed the new version of Lazarus. I installed the component for OPM and then used it to install BGRABitmap.     The code img.SetPixel(x,y,thirdcolor); compiled just fine so it looks like I'm in business.     Thank you all for your patience and understanding. Once again this forum came through for me. ---------------------------------------------------------------------- circular · 2019-12-04 22:33 You're welcome