Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Create a bitmap and drawing in it?

    SDK Help
    0
    28
    15.6k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 29/04/2012 at 11:17, xxxxxxxx wrote:

      I have no idea Steve. This is not obvious stuff. At least not to me it isn't.
      There's these two separate classes(BaseBitmap&GeClipmap). And each one has it's own strengths and limitations.
      And to make things more confusing...There's no clear documentation in the docs showing how to make these two classes work together. To edit or create images with them.

      Here's my latest attempt at loading an image. Then editing it with GeClipMap. Then saving it:

          Filename fn = GeGetC4DPath(C4D_PATH_DESKTOP)+"myimage.jpg"; //Get the path to an image  
        
        //Because we have to init first..Then get the image's info. We'll create a dummy BaseBitmap instance first  
        //This BaseBitmap instance will be used just to gather inforamtion about the file we've imported  
        AutoAlloc<BaseBitmap> file;                //Create a new BaseBitmap instance  
        file->Init(fn);                            //intialize it using the file path we used as the target image  
        LONG width = file->GetBw();                //Get the image's width  
        LONG height = file->GetBh();               //Get the image's height  
        LONG bitDepth = file->GetBt();             //Get the image's bitdepth  
        GePrint("Width: " + LongToString(width) + ", Height: " + LongToString(height) + ", BitDepth:  " + LongToString(bitDepth));  
        
        
        //Now we'll create another BaseBitmap...Based on the info we gathered from the previous BaseBitmap instance  
        //This is the one we'll edit and make changes to  
        AutoAlloc<BaseBitmap> bmp;           //Create a new image based on the file's info  
        bmp->Init(width, height,bitDepth);  
        file->CopyTo(bmp);                   //Copies the image's info over to this BaseBitmap instance  
        //bmp->Clear(255,255,255);           //Set the entire image to the color white if desired  
        bmp->SetPen(255,255,255);  
        bmp->Line(0,0,100,200);  
        
        AutoAlloc<GeClipMap> gcm;  
        if(!gcm) return FALSE;  
        gcm->Init(bmp);                       //Initialise the clip map using the BaseBitmap above so we can save it later on  
        gcm->BeginDraw();  
        gcm->SetColor(255, 0, 0);             //Sets the color of the text to red  
        gcm->FillRect(0,0,100,100);  
        gcm->EndDraw();  
        
        Filename newfn = GeGetC4DPath(C4D_PATH_DESKTOP)+"myimagenew.jpg"; //Create a path to save our new image  
        bmp->Save(Filename(newfn),FILTER_JPG,NULL,SAVEBIT_0);             //Save the new image
      

      The result is a copy of the source image. With a rectangle drawn with some weird missing strips. And the wrong color(green)
      But at least I'm getting  something as a result.
      I'm slowly getting there...But I'm doing a lot of fumbling around in the dark. 😂

      -ScottA

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 30/04/2012 at 00:09, xxxxxxxx wrote:

        Originally posted by xxxxxxxx

        The result is a copy of the source image. With a rectangle drawn with some weird missing strips. And the wrong color(green)
        But at least I'm getting   something  as a result.
        I'm slowly getting there...But I'm doing a lot of fumbling around in the dark. !LOL[URL-REMOVED]

        Yes because after drawing to the clipmap you need to get the modified bitmap with GetBitmap() (as said Steve above). The source bitmap isn't updated automatically.

          
          AutoAlloc<GeClipMap> gcm;  
          if(!gcm) return FALSE;  
          gcm->Init(bmp);                       //Initialise the clip map using the BaseBitmap above so we can save it later on  
          gcm->BeginDraw();  
          gcm->SetColor(255, 0, 0);             //Sets the color of the text to red  
          gcm->FillRect(0,0,100,100);  
          gcm->EndDraw();
          
            **BaseBitmap *clipBmp** _ **  = gcm->GetBitmap()    //Get modified bitmap from clipmap**_  
          
          Filename newfn = GeGetC4DPath(C4D_PATH_DESKTOP)+"myimagenew.jpg"; //Create a path to save our new image  
             clipBmp->Save(Filename(newfn),FILTER_JPG,NULL,SAVEBIT_0);             //Save the new image
        

        EDIT: Fixed code.


        [URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 30/04/2012 at 08:26, xxxxxxxx wrote:

          It won't let me do this: bmp = gcm- >GetBitmap(); //error: cannot access private member  AutoAlloc()

          -ScottA

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 30/04/2012 at 08:40, xxxxxxxx wrote:

            Originally posted by xxxxxxxx

            It won't let me do this: bmp = gcm- >GetBitmap(); //error: cannot access private member  AutoAlloc()

            Sorry, this is because bmp was already allocated with AutoAlloc(). We have to declare a new BaseBitmap variable to hold the modified bitmap:

            BaseBitmap *clipBmp = gcm->GetBitmap();
            
            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

              On 30/04/2012 at 09:16, xxxxxxxx wrote:

              Sorry about that. I should have mentioned that I already tried assigning it to a new BaseBitmap variable like that.

              The code you posted still produces a rectangle full of lines. And not the correct color for the FillRect().
              An interesting thing to note is I got this same type of bad result when using SetPixelCnt() with the wrong buffer settings.

              -ScottA

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                On 30/04/2012 at 09:34, xxxxxxxx wrote:

                Here is the code that works for me:

                Filename fn = GeGetC4DPath(C4D_PATH_DESKTOP)+"myimage.jpg"; //Get the path to an image
                  
                AutoAlloc<GeClipMap> gcm;        //Create an instance of the GeClipMap class
                gcm->Init(fn,0,0);               //Initialise it using the image in our path
                  
                gcm->BeginDraw();
                    gcm->SetColor(255L,255L,255L);      //Set the color to white
                    gcm->FillRect(50L,50L,100L,100L);   //Create a filled rectangle area
                gcm->EndDraw();
                  
                ShowBitmap(gcm->GetBitmap());           //Show the drawn bitmap
                
                1 Reply Last reply Reply Quote 0
                • H
                  Helper
                  last edited by

                  THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                  On 30/04/2012 at 10:05, xxxxxxxx wrote:

                  Now you've got it. 👍

                  Here's my little addition to it that will also save the image as well as show it in the picture viewer:

                      Filename fn = GeGetC4DPath(C4D_PATH_DESKTOP)+"myimage.jpg"; //Get the path to an image  
                    AutoAlloc<GeClipMap> gcm;           //Create an instance of the GeClipMap class  
                    gcm->Init(fn,0,0);                  //Initialise it using the image in our path  
                    
                    gcm->BeginDraw();  
                    gcm->SetColor(255L,255L,255L);      //Set the color to white  
                    gcm->FillRect(50L,50L,100L,100L);   //Create a filled rectangle area  
                    gcm->EndDraw();  
                    
                    ShowBitmap(gcm->GetBitmap());       //Show the drawn bitmap in the picture viewer  
                    
                    BaseBitmap *clipBmp = gcm->GetBitmap();                         //Get the modified bitmap from GeClipMap  
                    Filename newfn = GeGetC4DPath(C4D_PATH_DESKTOP)+"newimage.jpg"; //Create a path to save our new image  
                    clipBmp->Save(Filename(newfn),FILTER_JPG,NULL,SAVEBIT_0);       //Save the new image
                  

                  Please don't kill me. 😉
                  But could you possibly show me how to write the PolyLine code?
                  It requires a GE_POINT2D struct pointer. And I can't figure out how to write that part.

                  -ScottA

                  1 Reply Last reply Reply Quote 0
                  • H
                    Helper
                    last edited by

                    THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                    On 30/04/2012 at 12:20, xxxxxxxx wrote:

                    I've tried a whole bunch of different things. But I just can't get the struct to work.

                    Example#1

                        GE_POINT2D *points;       //<--Error. Variable is not initialized!!  
                                                //Setting it to NULL doesn't work  
                      LONG x = points->x = 5;  
                      LONG y = points->y = 25;  
                      gcm->PolyLine(20, points);
                    

                    Example#2
                    Accessing the struct directly without pointers crashes C4D

                        GE_POINT2D points;   
                      LONG x = points.x = 5;  
                      LONG y = points.y = 25;  
                      gcm->PolyLine(20, &points);
                    

                    Can anyone tell me how to do this?
                    I've got all the parts and pieces. But I just can't make C4D happy.

                    -ScottA

                    1 Reply Last reply Reply Quote 0
                    • H
                      Helper
                      last edited by

                      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                      On 30/04/2012 at 15:04, xxxxxxxx wrote:

                      Hi,

                      You have to initialize an array of struct (GE_POINT2D in this case) :

                      GE_POINT2D points[] =       //Define an array of GE_POINT2D
                      {
                          {200L,200L},      //x = 200L, y = 200L
                          {250L,250L},      //etc.
                          {200L,300L}
                      };
                        
                      gcm->PolyLine(3, points);    //Draw the polyline with the given 3 points
                      

                      This is a bit tricky at the beginning 🙂.

                      1 Reply Last reply Reply Quote 0
                      • H
                        Helper
                        last edited by

                        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                        On 30/04/2012 at 15:34, xxxxxxxx wrote:

                        Wonderful.
                        I think I've got everything I need now.
                        If not... too bad. Because I've bothered you enough about this. 😂

                        Thanks a lot.
                        You've really helped me (and probably many others) out a great deal with this.🍺

                        -ScottA

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post