9 Replies Latest reply on Jan 24, 2010 10:54 AM by PitWiener

    how to draw a simple point?

    PitWiener Level 1

      I studied the scripting manual and many scripts but couldn't find how to draw a simple point (brush with size 1 pixel) at coordinates X/Y and with a specific RGB color. Please help me with the corresponding VBA codelines.

       

      Pit

        • 1. Re: how to draw a simple point?
          Paul Riggott Level 6

          You can't script using a brush, but you can select an area and fill it with whatever colour you like.

          • 2. Re: how to draw a simple point?
            Muppet Mark Level 5

            Or make path @ XnY & stroke path…

            • 3. Re: how to draw a simple point?
              PitWiener Level 1

              > You can't script using a brush, but you can select an area and fill it with whatever colour you like.

               

              Hm, that's bad because to select and fill an area is veeeeery slow. (1 h for a 500x500 image !!!)

              • 4. Re: how to draw a simple point?
                Muppet Mark Level 5

                1 h for a 500x500 image !!! How RU doing this one pixel @ a time? filling an area with colour should be fraction of second…

                • 5. Re: how to draw a simple point?
                  PitWiener Level 1

                  > 1 h for a 500x500 image !!! How RU doing this one pixel @ a time?

                  > filling an area with colour should be fraction of second…

                   

                  I want to fill each pixel with a specific color !

                  • 6. Re: how to draw a simple point?
                    Michael L Hale Level 5

                    Instead of writing the document in memory by filling each pixel, it would be faster to create the image in a file then open the image. The code below makes a simple greyscale ramp

                     

                    // to keep demo simple vars are used for RGB
                    // but could use array of solidColors or array of RGB values
                    var r=0;
                    var g=0;
                    var b=0;
                    var numberOfPixels = 65536;
                    var imageFile = new File('~/Desktop/myImage.ppm');
                    imageFile.open('w');
                    imageFile.writeln('P3');
                    imageFile.writeln('256 256');
                    imageFile.writeln('255');
                    var str = new String();
                    for( p = 0; p < numberOfPixels; p++ ){
                         str += r+' '+g+' '+b+' ';
                         r++;
                         g++;
                         b++;
                         if( str.length > 57 ){// lines can't be over 70 chars
                              imageFile.writeln(str);
                              str = "";
                         }
                         // the test is needed here to keep image 8 bit greyascale
                         // would not be need with array of valid 8 bit colors
                         if( r > 255 ){
                              r=0;
                              g=0;
                              b=0;
                         }
                    }
                    if( str.length < 0 ) imageFile.writeln(str);// last line
                    imageFile.close();
                    app.open( imageFile );
                    
                    • 7. Re: how to draw a simple point?
                      PitWiener Level 1

                      > Instead of writing the document in memory by filling each pixel,

                      > it would be faster to create the image in a file then open the image.

                      > The code below makes a simple greyscale ramp

                      >...

                       

                      Wow, that's great. I didn't know the really simple file format of ppm.

                       

                      > imageFile.writeln('256 256');

                      > imageFile.writeln('255');

                      The first line is file size in pixels, isn't it?

                      But what's the second line?

                      • 8. Re: how to draw a simple point?
                        Michael L Hale Level 5

                        The format is

                         

                        The string 'P6' followed by newline

                        width in pixels as string whitespace heigth in pixels as string followed by newline

                        bit depth in decimal as string followed by newline i.e. 8bit is 256

                        color triplets as strings seperated by whitespace. each line must be less than 70 chars.

                         

                        So that line means no color value will be above 255( one byte)

                         

                        8bit or lower is eaiser to write as each color is one byte.

                        • 9. Re: how to draw a simple point?
                          PitWiener Level 1

                          Great, thank you Michael. I think I'll do it that way.