Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QImage->setPixel is going beyond the range.

    General and Desktop
    1
    1
    929
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      KBoya last edited by

      I am dividing the screen based on the height. Calculating the midpoint. If the y value is less than midpoint I am setting the pixcel to one color and if it is greater setting it to a different color. But the few pixels beyond the half point are set with first color. Please suggest.

      @int setImagePixcels(float &pX1,float &pY1,float &pX2,float &pY2)
      {

      int lValue = 0 ,pixelValY2=0, pixelValY1=0, pixelValX1=0, pixelValX2=0 ;
      int width= 0, height=0 , maxY=0,maxX=0,startx=0,starty=0;
      FILE *myFile=NULL;
      QRgb rgblo;

      pixelValX1= vPlotXY->getPixelXFromValueX(pX1); //px1 is x1
      pixelValX2= vPlotXY->getPixelXFromValueX(pX2); // px2 is x2

      startx = vPlotXY->vAxisPositionInPixels[LEFT]; //Starting point of x
      starty = vPlotXY->vAxisPositionInPixels[TOP]; //starting point of y

      pixelValY1= vPlotXY->getPixelYFromValueY(pY1); //py1 is y1
      pixelValY2= vPlotXY->getPixelYFromValueY(pY2); //py2 is y2

      width = (vPlotXY->vAxisPositionInPixels[RIGHT]-vPlotXY->vAxisPositionInPixels[LEFT]); //width of the screen
      height =(vPlotXY->vAxisPositionInPixels[BOTTOM]-vPlotXY->vAxisPositionInPixels[TOP]); //height of the screen

      float slope =(float) (pixelValY2-pixelValY1)/(pixelValX2-pixelValX1);

      myFile = fopen("C:\MyLearning\myData.txt","w+");
      if(!myFile)
      {
      // cout<<"error"; failure.
      }

      //int dy = (pixelValY2-pixelValY1); // This the delta for y
      //int dx = (pixelValX2-pixelValX1); // This the delta for x
      maxY = vPlotXY->vAxisPositionInPixels[BOTTOM];
      maxX = vPlotXY->vAxisPositionInPixels[RIGHT];

      for(int y= starty;y<maxY;y++)
      {
      for(int x= startx;x<maxX;x++)
      {
      int midHeight = vPlotXY->getPixelYFromValueY(1500);
      //float lineVal = (dyx)-(dxy)+(dx);
      //if((lineVal< 0)&& (axisVal[x-startx][y-starty]==0))
      if(y<midHeight)
      {
      vColor = 1;
      }
      else
      {

       vColor = 2;
      

      }

      // axisVal[x-startx][y-starty]=vColor;

      switch(vColor)
      {
       case GridColor::CYAN:
       rgblo= qRgb(0,255,255);
      
       break;
       case GridColor::SPRINGGREEN:
       rgblo= qRgb(0 ,250, 154);
       break;
       case GridColor::GREEN:
        rgblo= qRgb(0 ,205, 102);
       break; 
      
       case GridColor::DODERBLUE:
        rgblo= qRgb(30 ,144 ,255);
       break;
       case GridColor::SGI_SALMON:
        rgblo= qRgb(198, 113, 113);
       break;
       case GridColor::SGI_OLIVERDRAB:
        rgblo= qRgb(142 ,142 ,56);
       break;
       case GridColor::SGI_LIGHTBLUE:
       break;
       case GridColor::MEDIUMORCHID:
        rgblo= qRgb(186,85,211);
       break;
       case GridColor::YELLOW:
        rgblo= qRgb(255,255,0);
       break;
       case GridColor::MEDIUMPURPLE:
        rgblo= qRgb(147, 112, 219);
       break;
       default:
        rgblo= qRgb(255 ,255,255);
        break;
      
      }
       vImage->setPixel(x-startx,y-starty,rgblo); //Image starts from 0,0 and my co-ordinates starts from startx and start y so doing the adujustment.
      

      //fprintf(myFile, "(x=%d, y=%d)=(%d)", x,y,axisVal[x][y]);
      //}
      }
      fprintf(myFile, "\n");
      }
      fclose(myFile);

      return lValue;

      }@

      1 Reply Last reply Reply Quote 0
      • First post
        Last post