Solved

scanline creates bitmap with incorrect values

Posted on 2004-08-18
4
694 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
ID: 11832035
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
ID: 11834237
Shouldn't you be working with a TImage instead?
0
 
LVL 19

Accepted Solution

by:
Gary Benade earned 125 total points
ID: 11838731
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
ID: 11839316
Thank you very much you have solved my problem.
with kind regards
Mattias
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Eclipse insufficient memory error 3 119
C#  WebForms or MVC 4 134
how do you get these � Marks in your text? 9 102
GET error with Font Awesome 3 32
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: …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

730 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