当前位置: 首页>>代码示例>>C++>>正文


C++ BMP::SetPixel方法代码示例

本文整理汇总了C++中BMP::SetPixel方法的典型用法代码示例。如果您正苦于以下问题:C++ BMP::SetPixel方法的具体用法?C++ BMP::SetPixel怎么用?C++ BMP::SetPixel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BMP的用法示例。


在下文中一共展示了BMP::SetPixel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: array2bmp

//数组转图像
void array2bmp()
{
    int i,j;
    BMP bmp;
    RGBApixel pix_black={0};//R=0 G=0 B=0为黑色
    RGBApixel pix_white={255,255,255,0};//白色

    bmp.SetSize(3,3);
    bmp.SetBitDepth(1);
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            if(array[i][j]==1)
            {
                bmp.SetPixel( i,  j,pix_black);
            }
            else
            {
                bmp.SetPixel( i,  j,pix_white);
            }
        }
    }

    bmp.WriteToFile("examp_array2bmp.bmp");
    printf("array2bmp suc...\n");
}
开发者ID:bbky,项目名称:CodeBase,代码行数:28,代码来源:main.cpp

示例2: encode

void encode(string infile, string outfile, string payload)
{
	BMP input;
	if(!input.ReadFromFile(infile.c_str()))
	{
		cout << "The Bitmap doesn\'t exist!" << endl;
		return;
	}
	int msglength = payload.length() * 2;
	if(msglength > input.TellWidth() * input.TellHeight())
	{
		cout << "That message is too large for that image! (" << msglength << " as opposed to " << input.TellWidth() * input.TellHeight() << "; " << input.TellWidth() << " * " << input.TellHeight() << ")"<<endl;
		return;
	}
	stringstream msglength_ss;
	msglength_ss << setfill('0') << setw(8) << hex << msglength;
	string msglength_str = msglength_ss.str();

	uchar msgLength_split[8];
	for(uint i = 0; i < msglength_str.length(); i++)
	{
		msgLength_split[i] = (uchar)single_char_to_int(msglength_str[i]);
	}

	char* payload_split = new char[payload.length() * 2];
	for(uint i = 0; i < payload.length() * 2 - 1; i+=2)
	{
		payload_split[i] = payload[i / 2] >> 4;
		payload_split[i + 1] = payload[i/ 2] & 0x0F;
	}
	RGBApixel pix;
	for(int x = 0; x < 8; x++)
	{
		pix = input.GetPixel(x, 0);
		pix.Blue &= 0xF0;
		pix.Blue += msgLength_split[x];
		input.SetPixel(x, 0, pix);
	}

	for(int y = 0; y < input.TellHeight(); y++)
	{
		for(int x = 0; x < input.TellWidth(); x++)
		{
			if(y == 0 && x < 8)
				continue;
			pix = input.GetPixel(x, y);
			if(payload.length() * 2 > (uint)input.TellWidth() * y + x - 8)
			{
				pix.Blue &= 0xF0;
				pix.Blue += payload_split[input.TellWidth() * y + x - 8];
			}
			input.SetPixel(x, y, pix);
		}
	}
	fclose(fopen(outfile.c_str(),"w"));
	input.WriteToFile(outfile.c_str());
	delete[] payload_split;
}
开发者ID:techzoneat,项目名称:image-stegano,代码行数:58,代码来源:main.cpp

示例3: tile

void tile(BMP& Input, BMP& Output) {
    if (Input.TellHeight() == 1) {
        Output.SetPixel(Output.TellWidth() - 1, 0, Input.GetPixel(0, 0));
    }
    else {
        BMP* ScaledInput = new BMP(Input);
        Rescale(*ScaledInput, 'p', 50);

        // SW quadrant
        RangedPixelToPixelCopy(*ScaledInput, 0, ScaledInput -> TellWidth(), 0, ScaledInput -> TellHeight(), 
                Output, Output.TellWidth() - 2 * ScaledInput -> TellWidth(), ScaledInput -> TellHeight());

        // NE quadrant
        tile(*ScaledInput, Output);

        // NW quadrant
        RangedPixelToPixelCopy(Output, Output.TellWidth() - ScaledInput -> TellWidth(), Output.TellWidth() - ScaledInput -> TellWidth() / 2 - 1,
                0, ScaledInput -> TellHeight() - 1, Output, Output.TellWidth() - 2 * ScaledInput -> TellWidth(), 0);

        RangedPixelToPixelCopy(Output, Output.TellWidth() - ScaledInput -> TellWidth(), Output.TellWidth() - ScaledInput -> TellWidth() / 2 - 1,
                0, ScaledInput -> TellHeight() - 1, Output, Output.TellWidth() - 3 * ScaledInput -> TellWidth() / 2, 0);

        // SE quadrant
        RangedPixelToPixelCopy(Output, Output.TellWidth() - ScaledInput -> TellWidth(), Output.TellWidth() - 1, ScaledInput -> TellHeight() / 2,
                ScaledInput -> TellHeight()  - 1, Output, Output.TellWidth() - ScaledInput -> TellWidth(), ScaledInput -> TellHeight());

        RangedPixelToPixelCopy(Output, Output.TellWidth() - ScaledInput -> TellWidth(), Output.TellWidth() - 1, ScaledInput -> TellHeight() / 2,
                ScaledInput -> TellHeight() - 1, Output, Output.TellWidth() - ScaledInput -> TellWidth(), 3 * ScaledInput -> TellHeight() / 2);
    }

}
开发者ID:zgthompson,项目名称:fa13,代码行数:31,代码来源:lab6.cpp

示例4: writeToBMPFile

bool Image::writeToBMPFile(const std::string & outputFileName)
{
  bool success = true;

  if( m_pixels != NULL )
    {
    // create bitmap image
    BMP outputImage;
    outputImage.SetSize(m_numCols, m_numRows);
    outputImage.SetBitDepth( 24 );

    double maxVal = m_pixels[0];
    double minVal = m_pixels[0];
    // Maximum and minimum values
    for( int i = 1; i < m_numRows * m_numCols; ++i )
      {
      if( m_pixels[i] > maxVal )
        {
        maxVal = m_pixels[i];
        }
      if( m_pixels[i] <= minVal )
        {
        minVal = m_pixels[i];
        }
      }
    for( int r = 0; r < m_numRows; ++r )
      {
      for( int c = 0; c < m_numCols; ++c )
        {
        // get pixel value and clamp between 0 and 255
        double val = 255.0 * (m_pixels[r * m_numCols + c] - minVal) / (maxVal - minVal);

        if( val < 0 )
          {
          val = 0;
          }
        if( val > 255 )
          {
          val = 255;
          }
        // set output color based on mapping
        RGBApixel pixelVal;
        pixelVal.Blue = (int)val; pixelVal.Green = (int)val; pixelVal.Red = (int)val;
        outputImage.SetPixel(c, r, pixelVal);
        }
      }

    // write to file
    success = outputImage.WriteToFile( outputFileName.c_str() );

    }
  else
    {
    success = false;
    }

  return success;
}
开发者ID:zachary-williamson,项目名称:robotics-bosscode,代码行数:58,代码来源:Image.cpp

示例5: drawBox

void drawBox(BMP &image, int lowx, int lowy, int highx, int highy) {

    RGBApixel redPixel;
    // make pixel red
    redPixel.Red = 255;
    redPixel.Blue = 0;
    redPixel.Green = 0;

    // color upper and bottom bounds
    for (int i = lowx; i <= highx; ++i) {
        image.SetPixel(i, lowy, redPixel);
        image.SetPixel(i, highy, redPixel);
    }
    
    // color left and right bounds
    for (int j = lowy; j <= highy; ++j) {
        image.SetPixel(lowx, j, redPixel);
        image.SetPixel(highx, j, redPixel);
    }
}
开发者ID:zgthompson,项目名称:fa13,代码行数:20,代码来源:lab7.cpp

示例6: copy

void copy(BMP & InImg, BMP & OutImg, int xPos, int yPos) {
  // copy image to larger final picture so that the InImg is placed in row i, column j of OutImg
    int width = InImg.TellWidth();
    RGBApixel curPixel;

    for (int i = 0; i < width; i++) {
        for (int j = 0; j < width; j++) {
            curPixel = InImg.GetPixel(i, j);
            OutImg.SetPixel(xPos * width + i, yPos * width + j, curPixel);
        }
    }
}
开发者ID:zgthompson,项目名称:fa13,代码行数:12,代码来源:image_stitch.cpp

示例7: w2f

void w2f(GlobalMap &globalMap, int i, int j, int size=1025)
{
	char fileName[6] = {'0','0','.','b','m','p'};
	fileName[0]=i+48;
	fileName[1]=j+48;
		
	short z;
		
	RGBApixel color;
	BMP image;
	image.SetSize(size,size);
	image.SetBitDepth(16);

	for(int y=0; y<size; y++)
	{
		for(int x=0; x<size; x++)
		{
			z= globalMap.getLocalMap(i,j)->getHeight(x,y);
			if(z<0)
			{
				color.Red=0;
				color.Green=0;
				color.Blue=(z+32768)/129;
				color.Alpha=0;
			}
			if(z>=0 && z<20000)
			{	
				color.Red=0;
				color.Green=z/134+100;
				color.Blue=0;
				color.Alpha=0;
			}
			if(z>=20000 && z<25000)
			{
				color.Red=(z-20000)/500+200;
				color.Green=(z-20000)/500+200;
				color.Blue=(z-20000)/500+200;
				color.Alpha=0;
			}
			if(z>=25000)
			{
				color.Red=255;
				color.Green=255;
				color.Blue=255;
				color.Alpha=0;
			}
			
			image.SetPixel(x,y, color);
		}
	}

	image.WriteToFile(fileName);
}
开发者ID:Psycojoker,项目名称:topomap,代码行数:53,代码来源:main.cpp

示例8: pixelsToBitmap

void BitmapRawConverter::pixelsToBitmap(char *outFilename) {
    BMP out;
    out.SetSize(width, height);
    out.SetBitDepth(24);

    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            out.SetPixel(i, j, getPixel(i,j));
        }
    }
    out.WriteToFile(outFilename);
}
开发者ID:ljmocic,项目名称:SPPuRV,代码行数:12,代码来源:BitmapRawConverter.cpp

示例9:

static cell AMX_NATIVE_CALL n_FSetPixelRGBA( AMX* amx, cell* params ){
	posx = params[1];
	posy = params[2];
	RGBApixel value;
	
	value.Red = (ebmpBYTE)params[4];
	value.Green = (ebmpBYTE)params[5];
	value.Blue = (ebmpBYTE)params[6];
	value.Alpha = (ebmpBYTE)params[7];
	
	GlobalImage.SetBitDepth(24);
	GlobalImage.GetPixel(posx,posy);
	GlobalImage.SetPixel(posx,posy,value);
	return 1;
}
开发者ID:berke123123,项目名称:GPB,代码行数:15,代码来源:pwncurl.cpp

示例10: ExportBMP

        bool ExportBMP( const _TImg_t     & in_indexed,
                        const std::string & filepath )
    {
        //shorten this static constant
        typedef utils::do_exponent_of_2_<_TImg_t::pixel_t::mypixeltrait_t::BITS_PER_PIXEL> NbColorsPP_t;
        BMP output;
        output.SetBitDepth(_TImg_t::pixel_t::GetBitsPerPixel());

        if( in_indexed.getNbColors() != NbColorsPP_t::value )
        {
#ifdef _DEBUG
            assert(false);
#endif
            throw std::runtime_error( "ERROR: The tiled image to write to a bitmap image file has an invalid amount of color in its palette!" );
        }
        //copy palette
        for( int i = 0; i < NbColorsPP_t::value; ++i )
            output.SetColor( i, colorRGB24ToRGBApixel( in_indexed.getPalette()[i] ) );

        //Copy image
        output.SetSize( in_indexed.getNbPixelWidth(), in_indexed.getNbPixelHeight() );

        for( int i = 0; i < output.TellWidth(); ++i )
        {
            for( int j = 0; j < output.TellHeight(); ++j )
            {
                auto &  refpixel = in_indexed.getPixel( i, j );
                uint8_t temp     = static_cast<uint8_t>( refpixel.getWholePixelData() );
                output.SetPixel( i,j, colorRGB24ToRGBApixel( in_indexed.getPalette()[temp] ) ); //We need to input the color directly thnaks to EasyBMP
            }
        }

        bool bsuccess = false;
        try
        {
            bsuccess = output.WriteToFile( filepath.c_str() );
        }
        catch( std::exception e )
        {
            cerr << "<!>- Error outputing image : " << filepath <<"\n"
                 << "     Exception details : \n"     
                 << "        " <<e.what()  <<"\n";

            assert(false);
            bsuccess = false;
        }
        return bsuccess;
    }
开发者ID:PsyCommando,项目名称:ppmdu,代码行数:48,代码来源:bmp_io.cpp

示例11: graydata2BMP

void graydata2BMP(unsigned char* data, BMP& bmp ){
	int k=0;
	int width =bmp.TellWidth();
	int height=bmp.TellHeight();

	for (int i=0; i<height; i++){
		for (int j=0; j<width; j++){
			RGBApixel pix;
			pix.Blue =data[k];
			pix.Red  =data[k];
			pix.Green=data[k];
			bmp.SetPixel(j,i,pix);
			k++;
		}
	}
}
开发者ID:RC-MODULE,项目名称:sobel-steps,代码行数:16,代码来源:main.cpp

示例12: debugRender

void Camera::debugRender(unsigned int width, unsigned int height, std::string& outputFile)
{
	BMP file;
	file.SetSize(width,height);
	file.SetBitDepth(24);

	
	double d = m_direction.length();              //Distance from Eye to Middle point of the image

	Vector myVectorEyetoMiddle(m_direction);
	myVectorEyetoMiddle *= d;    //C in full length

	double tanfovx = tan(m_fovRad)*double(width)/height ;  
    Vector myEyeVectorX = myVectorEyetoMiddle.crossProduct(m_up) ;      //A
	Vector myEyeVectorY = myEyeVectorX.crossProduct(myVectorEyetoMiddle) ;      //B

	Vector myMiddlePoint =  myVectorEyetoMiddle + m_position;

	Vector myImageVectorX = myEyeVectorX *  ( myVectorEyetoMiddle.normalize().length() * tanfovx / myEyeVectorX.length() );    //H
	Vector myImageVectorY = myEyeVectorY *  ( myVectorEyetoMiddle.normalize().length() * tan(m_fovRad) / myEyeVectorY.length() );    //V

	for(unsigned int i=0;i<width;i++){
		for(unsigned int j=0;j<height;j++){
			
		    double sx,sy;
			sx = double(i)/width;
			sy = double(j)/height;

			Vector P =  myImageVectorX*(2*sx-1) + myImageVectorY*(2*sy-1) + myMiddlePoint ;
			Vector myRayCasting = (P - m_position)*(1.0 / (P - m_position).normalize().length()); //RayDirection = (P - E)/normalize(P - E);
		
			Vector normalizedRay = myRayCasting.normalize();

			RGBApixel NewColor;
			NewColor.Red = (ebmpBYTE) abs(normalizedRay[0])*255;
			NewColor.Green = (ebmpBYTE) abs(normalizedRay[1])*255;
			NewColor.Blue = (ebmpBYTE) abs(normalizedRay[2])*255;
			NewColor.Alpha = 0;
			file.SetPixel(i, height-j-1, NewColor);
		}
	}

	file.WriteToFile(outputFile.c_str());
}
开发者ID:katzeforest,项目名称:Computer-Graphics,代码行数:44,代码来源:Camera.cpp

示例13: save_image

void save_image(const Matrix<std::tuple<T, T, T>> &im, const char *path)
{
    BMP out;
    out.SetSize(im.n_cols, im.n_rows);

    T r, g, b;
    RGBApixel p;
    p.Alpha = 255;
    for (uint i = 0; i < im.n_rows; ++i) {
        for (uint j = 0; j < im.n_cols; ++j) {
            tie(r, g, b) = im(i, j);
            p.Red = clip(r); p.Green = clip(g); p.Blue = clip(b);
            out.SetPixel(j, i, p);
        }
    }

    if (!out.WriteToFile(path))
        throw string("Error writing file ") + string(path);
}
开发者ID:SenderOK,项目名称:Prokudin-Gorsky,代码行数:19,代码来源:io.hpp

示例14: save_image

void save_image(const Image &im, const char *path)
{
    BMP out;
    out.SetSize(im.n_cols, im.n_rows);

    int r, g, b;
    RGBApixel p;
    p.Alpha = 255;
    for (int i = 0; i < im.n_rows; ++i) {
        for (int j = 0; j < im.n_cols; ++j) {
            tie(r, g, b) = im(i, j);
            p.Red = r; p.Green = g; p.Blue = b;
            out.SetPixel(j, i, p);
        }
    }

    if (!out.WriteToFile(path))
        throw string("Error writing file ") + string(path);
}
开发者ID:allocator64,项目名称:graphics1,代码行数:19,代码来源:io.cpp

示例15: hpx_main

int hpx_main()
{
    BMP SetImage;
    SetImage.SetBitDepth(24);
    SetImage.SetSize(sizeX * 2,sizeY);
    hpx::util::high_resolution_timer t;

    {
        using namespace std;

        using hpx::future;
        using hpx::async;
        using hpx::wait_all;

        int const max_iteration = 255;

        vector<future<int> > iteration;
        iteration.reserve(sizeX*sizeY);

        hpx::cout << "Initial setup completed in " 
                  << t.elapsed() 
                  << "s. Initializing and running futures...\n";
        t.restart();

        hpx::id_type const here = hpx::find_here();
        fractals_action fractal_pixel;

        for (int i = 0; i < sizeX; i++)
        {
            for (int j = 0; j < sizeY; j++)
            {
                float x0 = (float)i * 3.5f / (float)sizeX - 2.5f;
                float y0 = (float)j * 2.0f / (float)sizeY - 1.0f;

                iteration.push_back(async(fractal_pixel, here, x0, y0, max_iteration));
            }
        }
        wait_all(iteration);

        hpx::cout << sizeX*sizeY << " calculations run in " 
                  << t.elapsed() 
                  << "s. Transferring from futures to general memory...\n";
        t.restart();

        for (int i = 0; i < sizeX; ++i)
        {
            for (int j = 0; j < sizeY; ++j)
            {
                int it = iteration[i*sizeX + j].get();
                for (int k = 0; k < 2; ++k)
                {
                    int p = (it * 255) / max_iteration;
                    SetImage.SetPixel(i * 2 + k, j, RGBApixel(p, p, p));
                }
            }
        }
    }

    hpx::cout << "Transfer process completed in " 
              << t.elapsed() << "s. Writing to hard disk...\n";
    t.restart();

    SetImage.WriteToFile("out.bmp");
    
    hpx::cout << "Fractal image written to file \"out.bmp\" from memory in " 
              << t.elapsed() << "s.\nInitializing shutdown process.\n";

    return hpx::finalize(); // Handles HPX shutdown
}
开发者ID:AntonBikineev,项目名称:hpx,代码行数:69,代码来源:fractals.cpp


注:本文中的BMP::SetPixel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。