Solved

scanline creates bitmap with incorrect values

Posted on 2004-08-18
4
692 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Multi Line / Multi file editor 6 70
Visual Studio - Accept Button gets border 3 77
Good resource for accessibility implementation 1 73
Unable to start eclipse ? 17 141
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
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: …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

770 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