Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > C/C++ программирование > C++ Builder
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 24.11.2010, 21:47   #1
KingBelt
 
Регистрация: 19.11.2010
Сообщений: 9
По умолчанию Синтаксис Delphi Builder --> C++ Builder

Не шарю всех тонкостей синтаксиса с++)) Подскажите, что исправить надо
Код:
program bwcoding;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
Код:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, ExtDlgs, StdCtrls, Buttons;

type
  TForm1 = class(TForm)
    Bevel1: TBevel;
    Image1: TImage;
    Bevel2: TBevel;
    Image2: TImage;
    BitBtn1: TBitBtn;
    OpenPictureDialog1: TOpenPictureDialog;
    Label1: TLabel;
    BitBtn2: TBitBtn;
    Button1: TButton;
    Label2: TLabel;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    Label3: TLabel;
    procedure BitBtn1Click(Sender: TObject);
    procedure Image1Click(Sender: TObject);
    function BinToDec(s:string):integer;
    procedure Encode(FileName:string);
    procedure Decode(FileName:string);
    function cl(x:integer):byte;
    function GetXY(n:integer):TPoint;
    procedure BitBtn2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

var
  OldFileSize, NewFileSize: real;
  mas: array [1..352*352] of byte;
  f:File of Byte;

function TForm1.GetXY(n:integer):TPoint;
begin
  Result.Y := n div 352;
  Result.X := n - (Result.Y * 352);
end;

function TForm1.cl(x:integer):byte;
begin
  if x=clWhite then result:=0 else result:=1;
end;


procedure TForm1.Encode(FileName:string);
var
  count,i,j:integer;
  c: byte;
  cc,p:byte;

begin
  p:=0;
  with image1.Canvas do
  for j:=0 to 351 do
  for i:=0 to 351 do
  if pixels[i,j]=clBlack then mas[j*352+i]:=1 else
  mas[j*352+i]:=0;

  AssignFile(f, FileName);
  Rewrite(f);

  i:=1;
  p:=mas[1];
  count:=1;
  cc:=255;

  while i<352*352 do
  begin
    if mas[i]=p then inc(count) else
    begin
      if count>255 then
      begin
        for j:=1 to count div 255 do write(f,p,cc);
        c:=count mod 255;
        write(f,p,c);
      end else write(f,p,count);
        p:=mas[i];
        count:=1;
    end;
    inc(i);
  end;
  for j:=1 to count div 255 do write(f,p,cc);
  c:=count-(count div 255)*255;
  write(f,p,c);

  CloseFile(f);
end;

function TForm1.BinToDec(s:string):integer;
var
  i,n,sm: integer;
begin
  n:=1;
  sm:=0;
  for i:=length(s) downto 1 do
  begin
    if s[i]='1' then sm:=sm+n;
    n:=n*2;
  end;
  result := sm;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  Label1.Caption := 'Размер исходного файла:';
  Label2.Caption := 'Размер сжатого файла:';
  Label3.Caption := 'Коэффициент сжатия:-';
  with openpicturedialog1 do if execute then
  begin
    Image1.Picture.LoadFromFile(FileName);
    AssignFile(f, FileName);
    Reset(f);
    Label1.Caption:=Label1.Caption+' '+IntTostr(FileSize(F))+' байт';
    OldFileSize:=FileSize(f);
    CloseFile(f);
  end;
end;

procedure TForm1.Image1Click(Sender: TObject);
begin
Image1.Stretch:= not Image1.Stretch;
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
begin
  with savedialog1 do if execute then
  begin
    Encode(FileName);
    AssignFile(f, FileName);
    Reset(f);
    Label2.Caption:=Label2.Caption+' '+IntTostr(FileSize(f))+' байт';
    NewFileSize:=FileSize(f);
    Label3.Caption:=Label3.Caption+' 1:'+floattostr(trunc(OldFileSize / NewFileSize*10)/10);
    CloseFile(F);
  end;
end;

procedure TForm1.Decode(FileName:string);
var
  p,cur: byte;
  k,i,j,l,prev:integer;
begin
  AssignFile(f,FileName);
  Reset(f);
  i:=1;
  j:=0;
  while not eof(f) do
  begin
    read(f,p);
    read(f,cur);
    for l:=1 to cur do
    begin
      inc(i);
      if i>352 then
      begin
        i:=1;
        inc(j);
      end;
      if p=0 then image2.Canvas.Pixels[i,j]:=clWhite else
      if p=1 then image2.Canvas.Pixels[i,j]:=clBlack;
    end;
  end;
  CloseFile(F);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  with opendialog1 do if execute then decode(FileName);
end;

end.

  i:=1;
  p:=mas[1];
  count:=1;
  cc:=255;

  while i<352*352 do
  begin
    if mas[i]=p then inc(count) else
    begin
      if count>255 then
      begin
        for j:=1 to count div 255 do write(f,p,cc);
        c:=count mod 255;
        write(f,p,c)
      end else
      write(f,p,count);
      count:=1;
      p:=mas[i];
    end;
    inc(i);
  end;
KingBelt вне форума Ответить с цитированием
Старый 27.11.2010, 13:55   #2
KingBelt
 
Регистрация: 19.11.2010
Сообщений: 9
По умолчанию

up
KingBelt вне форума Ответить с цитированием
Старый 28.11.2010, 16:25   #3
KingBelt
 
Регистрация: 19.11.2010
Сообщений: 9
По умолчанию

Проблема актуальна, удалось переделать небольшую часть:
Код:
//---------------------------------------------------------------------------

#include <vcl.h>
#include <stdio.h>
#include <iostream.h>
#include <fstream.h>
#include <malloc.h>
#include <string.h>
#pragma hdrstop

#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
double OldFileSize, NewFileSize;
unsigned char mas[352][352];

//TPoint TForm1::Get(int n)
//{
//    tPoint Result;
//    Result.Y=n/352;
//    Result.X=n-(t.Y*352);
//    return Result;
//}
//---------------------------------------------------------------------------

__int64 FileSizeByName (AnsiString AFileName) 
{
__int64 Result = 0;
WIN32_FIND_DATA LRec;
HANDLE LHandle = FindFirstFile(AFileName.c_str(), &LRec);
if (LHandle != INVALID_HANDLE_VALUE)
  {
  FindClose(LHandle);
  Result = ((__int64) LRec.nFileSizeHigh << 32) + LRec.nFileSizeLow;
  }
return Result;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::N2Click(TObject *Sender)
{
 Label1->Caption="Размер исходного файла:";
 Label2->Caption="Размер сжатого файла:";
 Label3->Caption="Коэффициент сжатия:-";
 if (OpenPictureDialog1->Execute()){
  Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName);
  __int64 Size = FileSizeByName(OpenPictureDialog1->FileName);
  Label1->Caption = Label1->Caption + " " + IntToStr(Size) + " байт";
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N3Click(TObject *Sender)
{
 if (SaveDialog1->Execute()){
  Image1->Picture->SaveToFile(SaveDialog1->FileName);
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N4Click(TObject *Sender)
{
 Close();        
}
//---------------------------------------------------------------------------

void __fastcall TForm1::N6Click(TObject *Sender)
{
 Form2->ShowModal();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Image1Click(TObject *Sender)
{
 Image1->Stretch=false;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::N7Click(TObject *Sender)
{
 Image1->Picture='\0';
}
//---------------------------------------------------------------------------
KingBelt вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Rad Studio 2011 XE: новое в Delphi, C++ Builder, RadPHP и Delphi Prism savva-paladin Софт 18 02.10.2010 20:24
С Delphi 7 на C++ Builder 6 Kazik Помощь студентам 0 06.06.2010 13:25
Builder -> Delphi Avtograf Общие вопросы Delphi 0 02.06.2010 20:02
Перенести код из C++ Builder 5 в C++ Builder 2009 Kreadlling C++ Builder 2 13.09.2009 14:00
Из Delphi в Builder koljsch C++ Builder 2 03.09.2009 20:12