Solved

scanline creates bitmap with incorrect values

Posted on 2004-08-18
4
687 Views
Last Modified: 2013-12-03
Does anybody know why scanline (see code below) creates with i=0 a black bitmap (values are 0) but generates for example with i=1 a bitmap with values 43?

   for(int i = 0 ; i < 256 ; i++) {
      Graphics::TBitmap *smallImg = new Graphics::TBitmap();
      smallImg->Width = 10; smallImg->Height = 14;
      smallImg->PixelFormat = pf8bit;

      unsigned char *ptr;
      int x=0, y=0;
      ptr = static_cast<BYTE*>(smallImg->ScanLine[y]);
      for(int j=0; j < (smallImg->Height * smallImg->Width); j++) {
         if(x == smallImg->Width) {
            y++;
            x = 0;
            ptr = static_cast<BYTE*>(smallImg->ScanLine[y]);
         }
         ptr[x]= (BYTE) colorValue;
         x++;
      }
      colorValue++;
      smallImg->Palette = grayPal;
      smallImg->SaveToFile("clusterColor_" + IntToStr(i) + ".bmp");
      images->Insert(i, smallImg, NULL);
   }
0
Comment
Question by:mad1159
4 Comments
 
LVL 11

Expert Comment

by:Jase-Coder
Comment Utility
This is a guess.
Maybe element 0 of the pixel array is used to determine the type of image ie black and white
0
 
LVL 9

Expert Comment

by:Cayce
Comment Utility
Shouldn't you be working with a TImage instead?
0
 
LVL 19

Accepted Solution

by:
Gary Benade earned 125 total points
Comment Utility
try this. You may have been setting your pallette at the wrong point, or there is something wrong with your loop logic.

   for(int i = 0 ; i < 256 ; i++)
   {
      Graphics::TBitmap *smallImg = new Graphics::TBitmap();
      smallImg->Width = 10; smallImg->Height = 14;
      smallImg->PixelFormat = pf8bit;
      smallImg->Palette = grayPal;

      for (int y = 0; y < smallImg->Height; y++)
      {
        ptr = (Byte *)smallImg->ScanLine[y];
        for (int x = 0; x < smallImg->Width; x++)
          ptr[x] = (Byte)colorValue;
      }

      colorValue++;
      smallImg->SaveToFile("clusterColor_" + IntToStr(i) + ".bmp");
      images->Insert(i, smallImg, NULL);
   }

Regards
Gary
0
 

Author Comment

by:mad1159
Comment Utility
Thank you very much you have solved my problem.
with kind regards
Mattias
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now