Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 23rd, 2004, 02:50 AM
ck ck is offline
Authorized User
Join Date: Dec 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to get bitmap pixel to store in the array

 i'm a beginner of visual C++, anybody know or can teach me how to get bitmap pixel, read it, write it, then save it, then load & display it on the static control in MFC??? & all tis codes is it write in header file(.h) or source file(.cpp)??? thanks

below is the codes..but dunnno right or wrong...& it got bugs also...

struct Image {
 int rows;
 int colds;
 unsigned char *Data;
 unsigned char Type;

#define BASIC 0

#include <stdlib.h>
#include <memory.h>

void ReadArray(Image *Img, const char *filename)
    FILE *fl;
    int x;

        fl = fopen(filename, "ra");

    for(x=0; x<Img->rows; ++x)
            fread(Img->Data + x*Img->cols, Img->cols,1,fl);

void WriteArray(Image *Img, const char *filename)
    FILE *fl;
    int y;

        fl = fopen(filename, "wa");

    for(y=0; y<Img->rows; ++y)
            fwrite(Img->Data + y*Img->cols, Img->cols,1,fl);

Reply With Quote
  #2 (permalink)  
Old January 20th, 2005, 05:02 PM
Registered User
Join Date: Jan 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

You're working too hard...try
the following from Ronen Magid on www.codeguru.com

1. Create your own CBitmap-derived class (say, CMyBitmap)
2. Add a "load from bitmap" method as listed below

BOOL CMyBitmap::LoadBitmap(LPCTSTR szFilename)

  HBITMAP hBitmap = NULL;
  hBitmap = (HBITMAP)LoadImage(NULL, szFilename, IMAGE_BITMAP, 0, 0,
  return Attach(hBitmap);

Then do a CStatic::SetBitmap ( hBitmap ).

I noticed that your example code is all done in C, not C++. The above code assumes using MFC and C++. The LoadImage () call is a WinAPI C-function call that returns an HBITMAP handle.
Reply With Quote

Similar Threads
Thread Thread Starter Forum Replies Last Post
read bitmap pixel ersantombalak VB How-To 2 February 13th, 2007 07:20 AM
Store time into Array derekl ASP.NET 1.0 and 1.1 Basics 3 December 18th, 2006 09:41 AM
Store Array of Form Values lbunnell Beginning PHP 1 June 21st, 2005 10:13 AM
How to get bitmap pixel to store in the array ck Visual C++ 0 December 23rd, 2004 02:52 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.