stop Refreshing of images drawn by setpixel() and saving it how to do? - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17

Thread: stop Refreshing of images drawn by setpixel() and saving it how to do?

  1. #16
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,981

    Re: stop Refreshing of images drawn by setpixel() and saving it how to do?

    hmm actually this may be harder than I thought... The headers are part of the platform SDK. but I'm not sure microsoft still distributes platform SDK's compatible with VC6.
    THe newer ones won't work for sure because VC6 isn't c++ standards compliant.

    You really should consider upgrading to a newer version of VC.
    In any case, even if you do find a platform SDK with GDI+ support that works for VC6. CImage (an MFC class) won't work on VC6. you can use the GDI+ primitives of course.

  2. #17
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,981

    Re: stop Refreshing of images drawn by setpixel() and saving it how to do?

    since all you need of gdi+ is the bitmap thing... this'll probably be easier to get to work using the CreateDIBSection() solution instead.

    Create a new project.
    Set the type to SDI.
    Set the view type to CScrollview

    Open the view header and add the following 2 members.
    Code:
    CBitmap m_Bmp;
    DWORD* m_pdwBits;
    In the OnDraw() you add this code
    Code:
    	CDC dcMem;
    	dcMem.CreateCompatibleDC(pDC);
    	CBitmap* pOldBmp = dcMem.SelectObject(&m_bmp);
    	BITMAP bmpInfo;
        m_bmp.GetBitmap(&bmpInfo);
    	pDC->BitBlt(0,0,bmpInfo.bmWidth,bmpInfo.bmHeight,&dcMem, 0,0, SRCCOPY);
    	dcMem.SelectObject(pOldBmp);

    In the OnInitialUpdate() set the sizeTotal variable to the desired size (600x600) and add following bit of code:
    Code:
    	BITMAPINFO bmi; 
    	memset(&bmi, 0, sizeof(BITMAPINFO)); 
    	bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 
    	bmi.bmiHeader.biWidth = sizeTotal.cx; 
    	bmi.bmiHeader.biHeight = -sizeTotal.cy; // top-down
    	bmi.bmiHeader.biPlanes = 1; 
    	bmi.bmiHeader.biBitCount = 32; 
    	bmi.bmiHeader.biCompression = BI_RGB; 
    	m_bmp.Attach( CreateDIBSection( *GetDC(), &bmi, DIB_RGB_COLORS, (void**)&m_pdwBits, NULL, NULL) );
    	ZeroMemory(m_pdwBits, sizeof(sizeTotal.cx*sizeTotal.cy*sizeof(DWORD)));

    You can then use the m_pdwBits variable as a simple bitmap. each "pixel" is a 32bit RGB pixel in ARGB format.
    to set a pixel at 100x50 to purple.
    m_pdwBits[ 100*600 + 50 ] = 0x00FF00FF; // set red and blue to 255.

    be careful not to write outside of your given size.
    With the above code, 0,0 of the bitmap will be located at the top left of the window, with increasing Y pointing downward
    If you'd like it at the bottom left with increasing Y going upward. set biHeight to the poxitive value rather than the negative one.

    When you have made changes to the bitmap and want to see them. Invalidate the window with Invalidate();

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center