CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2000
    Location
    England
    Posts
    574

    ::SetPixelV help please

    Hi
    Why when i use this code is my bitmap the right size but im trying to set just one pixel a certain color
    but with this code the whole line gets turned into that colour
    always my y co ordinate ??

    Any ideas ?

    say the RGB values are 128,128,128 instead of just getting a color dot at position x,y
    i get a colored line at position x but all the way down line y ??

    Code:
    	CPen Pen1;
    	LOGPEN lp;
    	lp.lopnStyle = PS_SOLID;
    	lp.lopnWidth.x = 0;
    	lp.lopnColor = RGB(0,0,0);
    	Pen1.CreatePenIndirect(&lp);
    
    	// Create a brush
    	CBrush brush1;
    	brush1.CreateSolidBrush(RGB(0,0,0));
    
    	CBrush* pOldBrush = m_pDCNew->SelectObject(&brush1);
    	CPen* pOldPen = m_pDCNew->SelectObject(&Pen1);
    
    	// declare a AFPDibSection
    	AFPDibSection dib(nWidthInPixels, nHeightInPixels);
    
    	// call the Rectangle function and draw a rectangle for the size of the bitmap in the AFPDibSection
    	::Rectangle(dib.getDC(), 0, 0, nWidthInPixels, nHeightInPixels);
    
    	int x = 0, y = 0;
    
    	// The amount of bits allowed in the line is as long as the width of the bitmap
    	int bits_per_line = nWidthInPixels;
    
    
    //******************** End *************************************************//
    
    		for (int n = 0; n < strRawData.GetLength(); n += bits_per_line)	// loop through all the data
    		{
    			for (int j = 0; j <= bits_per_line; j++) // loop through and get values from array
    			{
    				CString strRDRed, strRDGreen, strRDBlue; 
    				int nrdRed, nrdGreen, nrdBlue;
    
    				// break up rawdata string into 2 chars
    				CString strTwoChars = strRawData.Mid(nStartingPosition,nTwoChars);
    				int nValue = HexToDec(strTwoChars);
    				CString strRGBColor = colorTable.GetAt(nValue);
    
    				// pull out colors
    				strRDRed   = strRGBColor.Mid(0,3);
    				strRDGreen = strRGBColor.Mid(3,3);
    				strRDBlue  = strRGBColor.Mid(6,3);
    
    				nrdRed   = _ttoi(strRDRed);
    				nrdGreen = _ttoi(strRDGreen);
    				nrdBlue  = _ttoi(strRDBlue);
    
    				COLORREF clr = RGB(nrdRed, nrdGreen, nrdBlue);
    
    				// need to set pixel color
    				::SetPixelV(dib.getDC(), x, y , clr);
    
    				nStartingPosition += nTwoChars;
    
    				x++;
    			}
    			nStartingPosition = 0;
    			x = 0;
    			y++;
    		}
    Thanks

    P

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150
    Use the debugger to step through your code and check the values of strTwoChars and strRGBColor in the debugger.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured