[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

scanline creates bitmap with incorrect values

Posted on 2004-08-18
4
Medium Priority
?
705 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 500 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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.
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
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 new code templates in NetBeans IDE 8.0 for Windows.

650 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