M
M
Muriam2019-01-26 21:33:01
css
Muriam, 2019-01-26 21:33:01

C++ builder. Work with graphics. How to fix errors in the code?

The program converts a BMP file by creating a frame around it of randomly colored pixels. Frame width - 15 pixels.
Attached is a photo with errors. Help fix them.
5c4ca74def750286553927.pngUnit1.cpp file

//---------------------------------------------------------------------------
#include <vcl.h>
#include "bmp.h"
#define MAXCOLORTC
//#include "wingraph.h"
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

  Bmp New;
  FileHeader *fh;
  MAPINFO *mi;
  RGBquad *rgb;
  //New.Open("CAT16.BMP");

  fh=New.GetFH();
  mi=New.GetMapInfo();
  BYTE *b=(BYTE*)(fh->bfOffbits+(long)fh);
  DWORD w,h;
  w=mi->Width;
  h=mi->Height;


  for (int i=0;i<h;i++)
      for (int j=0;j<w;j++)
        {
            if ((i<15)||(i>(h-1-15)))
                b[i*(w/2+1)+j]=(int)((float)rand()/RAND_MAX*256);

            if ((j<15-8)||(j>w+7-15))
                b[(i*(w/2)+j)]=(int)((float)rand()/RAND_MAX*256);
        }

//New.Save("gvozdika_frame.bmp");
//Image1->Picture->LoadFromFile("CAT16_frame.BMP");

}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
        Close();
}
//---------------------------------------------------------------------------

file "bmp.h"
#include <io.h>
#include <stdio.h>
#pragma pack(1) 

struct FileHeader 
{
  WORD bfType; 		//тип файла
  DWORD bfSize;		//размер файла в dword
  WORD bfReserved1;        //не используется
  WORD bfReserved2;        //не используется
  DWORD bfOffbits;  	       //смещение данных битового образа от заголовка в байтах
};
struct MAPINFO 
{
  DWORD Size;             //число байт, занимаемых структурой InfoHeader
  DWORD Width;          //ширина битового образа в пикселях
  DWORD Height;        //высота битового образа в пикселях
  WORD Planes;           //число битовых плоскостей устройства
  WORD BitCount;        //число битов на пиксель
  DWORD Compression;  //тип сжатия
  DWORD SizeImage;    //размер картинки в байтах
  long XPelsPerMeter;   //горизонтальное разрешение устройства, пиксель/м
  long YPelPerMeter;     //вертикальное разрешение устройства, пиксель/м
  DWORD ClrUsed;         //число используемых цветов
  DWORD ClrImportant; //число "важных" цветов
};

struct RGBquad 
{
    byte rgbRed;            //интенсивность красного
    byte rgbGreen;         //интенсивность зеленого
    byte rgbBlue;           //интенсивность голубого    
    byte rgbReserved;    //не используется
};

class Bmp
{
private:
  void *pBmp;
  long SizeFile;
public:
  Bmp();
  ~Bmp();
  void Open(char* fn);
  void Save(char* fn);
  FileHeader *GetFH();
  MAPINFO *GetMapInfo();
  RGBquad *GetMap();
};

void Bmp::Save(char* fn)
{
        FILE* File;
        File=fopen(fn,"wb");
        fwrite(pBmp,1,SizeFile,File);
        fclose(File);
}

RGBquad *Bmp::GetMap()
{
  RGBquad *rgb;
  rgb=(RGBquad *)((long)pBmp+sizeof(FileHeader)+sizeof(MAPINFO));
  return rgb;
}

MAPINFO *Bmp::GetMapInfo()
{
  MAPINFO *mi;
  mi=(MAPINFO*)((long)pBmp+sizeof(FileHeader));
  return mi;
}

FileHeader *Bmp::GetFH()
{
  FileHeader *fh;
  fh=(FileHeader *)pBmp;
  return  fh;
}

Bmp::Bmp()
{
  pBmp=0;
  SizeFile=0;
}

Bmp::~Bmp()
{
  delete []pBmp;
}

void Bmp::Open(char* fn)
{
  FILE* File;
        int hFile;
        File=fopen(fn,"rb");
        hFile=_fileno(File);
        SizeFile=filelength(hFile);
        pBmp=(BYTE*)malloc(SizeFile);
        fread(pBmp,1,SizeFile,File);
        fclose(File);
}

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexey, 2016-06-03
@lemme

As the most extreme option - div in div, the outer div has a background of repeating slanted stripes (gradient or picture.
But this is already the most extreme option :)
Like this codepen.io/anon/pen/qNdjoB

H
HamSter, 2016-06-03
@HamSter007

won't the border-image generator work?

L
lfoma, 2016-06-04
@lfoma

Is the block fixed or not? If fixed, then make background a picture, if dynamic, then through border-image. Variants without pictures in this case are impossible because of the complex rhythm.

V
Vapaamies, 2019-01-27
@vapaamies

__fastcall TForm1::TForm1(TComponent* Owner)

After this line, you have TForm(Owner) in the air, then an empty block of code, then the Bmp New declaration and the following code are also up in the air. Copying code from the Internet should be more careful.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question