|
-
May 25th, 2004, 09:31 AM
#1
::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
-
May 26th, 2004, 02:27 PM
#2
Use the debugger to step through your code and check the values of strTwoChars and strRGBColor in the debugger.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|