Skip to main content

How to Make an Inverse Effect of the Image using Embarcadero C++ Builder XE5?

How To Make An Inverse Effect Of The Image Using Embarcadero C++ Builder XE5?

How to make an inverse effect of the image using Embarcadero C++ Builder XE5?

Introduction

If you want to make an inverse effect of the image, you can try this algorithm. To make a similar a negative (of a photo). That would be fun.

Equipment

Operation System: Microsoft Windows 7 (64 bit)
Development Utility: Embarcadero C++ Builder XE5

Usage

image.png

image.png


//---------------------------------------------------------------------------

#include 
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
// Create three points of TBitmap object
Graphics::TBitmap *TheBitmap, *TempBitmap, *OriginBitmap;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Exit1Click(TObject *Sender)
{
    // Exit the program
    Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OpenFile1Click(TObject *Sender)
{
    // If you got a file of the picture, you are able to load it.
    if ( OpenPictureDialog1->Execute() )
    {
        // Disable automatic resize.
        Image1->AutoSize=false;
        // Enable an automatic stretch.
        Image1->Stretch=true;
        // Loads a picture file.
        Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName);
        // Set a point to the picture of loading.
        TheBitmap=Image1->Picture->Bitmap;
        // Create a new TBitmap object to keep original picture.
        OriginBitmap = new Graphics::TBitmap();
        // To keep original picture.
        OriginBitmap->Assign(TheBitmap);
        // Set up TImage object to keep original picture.
        Image1->Picture->Bitmap->Assign(TheBitmap);
        // If you open picture file successful and then set a flag.
        // The means that you have been opened a file.
        OpenFile = 1;
    }
    // If you have not opened a file, the flag will be zero, and then returns.
    if (OpenFile == 0) {
        return;
    }
    Byte *ptr, *tptr;
    // Set up the TImage restore to the original picture.
    Image1->Picture->Bitmap->Assign(OriginBitmap);
    // Create a new TBitmap.
    TempBitmap = new Graphics::TBitmap();
    // To get a current bitmap.
    TempBitmap->Assign(TheBitmap);
    // To do scan line of the whole picture.
    for (int y=0; y < TheBitmap->Height; y++) {
        // Set Y position of the image point.
        ptr = (Byte*) TheBitmap->ScanLine[y];
        // Set Y position of the image point.
        tptr = (Byte*) TempBitmap->ScanLine[y];
        // To do scan X-axis of the line.
        for (int x=0; x < TheBitmap->Width; x++) {
            // Inverse the pixel.
            ptr[x] = (Byte) 255 - ptr[x];
        } // End x
    } // End y
    // Release the temporal bitmap.
    delete TempBitmap;
    // Refresh and draw the TImage object.
    Repaint();
    // Set result of inverse of the picture.
    Image1->Picture->Bitmap->Assign(TheBitmap);

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

Exception

If you encounter the error, don’t worry. You just step by step to solve it.

Reference

[1] Gary Bradski and Adrian Kaehler, “Learning OpenCV: Computer Vision with the OpenCV Library,” O’REILLY, September 2008, ISBN:978-0-596-51613-0

Acknowledge

Thank you (Embarcadero C++ Builder XE5, Lenna Sjööblom) very much for this great development utility and beautiful photo.

Popular posts from this blog

數位影像處理:最佳化處理策略之快速消除扭曲演算法

寫作:波蘭文學習之旅:1-1. 波蘭文字母與發音(注音版)

Python 日期與時間的處理

數位影像處理:最佳化處理策略之快速消除扭曲演算法

Image

寫作:波蘭文學習之旅:1-1. 波蘭文字母與發音(注音版)

Image

Python 日期與時間的處理

Image

Visual Basic 6.0 (VB6) 程式語言案例學習 (10. 條碼列印程式)

Image

Visual Basic .Net (VB.Net) 程式語言案例學習 (06. 題庫測驗系統)

Image

修復損毀的 SQLite DB 資料庫

Image

用10種程式語言做影像二值化(Image binarization)

解決 ValueError: If using all scalar values, you must pass an index

Image

Visual Basic 6.0 (VB6) 程式語言案例學習 (04. 人事考勤管理系統)

Image

Visual Basic 6.0 (VB6) 程式語言案例學習 (07. 收據列印程式)

Image