Solved

scanline creates bitmap with incorrect values

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

691 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