Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (0)


optimise a dbimage fields and free space on the diskFormat this article printer-friendly!Bookmark function is only available for registered users!
reduce the size of dbimage
Product:
Delphi 4.x (or higher)
Category:
DB-General
Skill Level:
Scoring:
Last Update:
07/07/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet graphic dbimage jpeg bmp reduire reduce zeriouh image picture dataset blob convert to
Times Scored:
3
Visits:
4241
Uploader: ZERIOUH ABDELHAFID
Company:
Reference: N/A
 
Question/Problem/Abstract:
how to reduce the size of dbimage and optimise the dbimage fields
or graphic field.
Answer:



we know that after scanning a photo and save it in a dataset the place assigned
on the disk depend of the size of the image and  on the parametres of scanning way, so if we have to scan n photos we have  to optimise and reduce the size of photos stored in the dataset.

this a unit of my project

{ this project  is for optimise the blob fields as photos
  after execute this project you will pack the table}
//***************************************************
// before  you have to create a form
// dbnavigator1
// dbimage1 with the specified field to optimise
// image1
// datamodule2 unit
// gauge1
// SpeedButton1
//***************************************************

unit optimise;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls, Buttons, Mask,ComCtrls,DBCtrls,jpeg, Gauges;

type
  TFoptimise = class(TForm)
    SpeedButton1: TSpeedButton;
    Gauge1: TGauge;
    Image2: TImage;
    DBImage1: TDBImage;
    DBNavigator1: TDBNavigator;
    procedure FormShow(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Foptimise: TFoptimise;

implementation

uses Unit2;

//unit2 is datamodule2 unit

{$R *.DFM}

function resizeImage(sInImage, sOutImage: string; iHeight, iWidth: integer): boolean;
    var
    JpgImg : TJpegImage;
    BmpImg : TBitmap;
    Rectangle: TRect;
    begin
    try
     JpgImg := TJpegImage.Create;
     BmpImg := TBitmap.Create;

     JpgImg.LoadFromFile(sInImage);
     Rectangle := Rect(0, 0, iWidth, iHeight);
     with BmpImg do
     begin
     Width := iWidth;
     Height := iHeight;
     Canvas.StretchDraw(Rectangle, JpgImg);
     end;
     finally
     JpgImg.Assign(BmpImg);
     JpgImg.SaveToFile(sOutImage);
     JpgImg.Free;
     BmpImg.Free;
     end;
    Result := True;
    end;

Function ConvertJpegToBmp(imgJpeg : TJPEGImage; Var imgBmp : TBitMap) : Boolean;
// Converti une image Jpeg en BMP
begin
  Result:=True;
  try
   ImgBMP.Width := ImgJPEG.Width;  // dÉtermination de la taille de ImgBmp
   ImgBMP.Height := ImgJPEG.Height;
   ImgBMP.Canvas.Draw(0,0,ImgJPEG); // On dessine de ImgJPEG dans ImgBmp
  Except
    On E:Exception do Result:=False;
  end;
end;

Function FileConvertJpegToBmp(JpegFile,BmpFile : String) : Boolean;
// Converti un fichier Jpeg en fichier BMP
var
  ImgJPEG : TJPEGImage;
  ImgBmp  : TBitmap;
begin
  Result:=False;
  try
    try
     ImgJPEG := TJPEGImage.Create;
     ImgBmp := TBitmap.Create;
     ImgJPEG.LoadFromFile(JpegFile); // chargement du JPEG À partir d'un fichier
     if ConvertJpegToBmp(ImgJPEG,ImgBmp) then
     begin
       ImgBmp.SaveToFile(BmpFile);  // Sauvegarde de ImgBmp sous fichier
       Result:=True;
     end;
    Except
      On E:Exception do ;
    end;
  finally
    ImgJPEG.Free;
    ImgBmp.Free;
  end;
end;




procedure TFoptimise.FormShow(Sender: TObject);
begin
   datamodule2.Table1.open;
end;


procedure TFoptimise.SpeedButton1Click(Sender: TObject);
var
  Imgbmp:TBitMap;
  jpgImg2: TJPEGImage;
  MyFormat:word;
  Bitmap : TBitMap;
  AData,APalette : THandle;
  photo1,photo2,photo3,photo4:string;
begin
image2.Visible:=True;
gauge1.Visible:=True;
gauge1.MaxValue:=DataModule2.table1.RecordCount;
gauge1.Progress:=0;
DataModule2.table1.First;
photo1:=datamodule2.Session1.NetFileDir+'\constphoto.bmp';
photo2:=datamodule2.Session1.NetFileDir+'\constphoto.jpg';
photo3:=datamodule2.Session1.NetFileDir+'\constphoto3.jpg';
photo4:=datamodule2.Session1.NetFileDir+'\constphoto5.jpg';
while not (datamodule2.Table1.eof) do
begin
gauge1.Progress:=gauge1.Progress+1;
if not((Datamodule2.Table1photo.BlobSize=0) or (Datamodule2.Table1photo.isnull)) then
begin
  dbimage1.Picture.SaveToFile(photo1);
  image2.picture.LoadFromFile(photo1);
  Image2.Refresh;
//conversion BMP -JPG
  jpgImg2 := TJPEGImage.Create;
  jpgImg2.Assign(Image2.Picture.Bitmap);
  jpgImg2.SaveToFile(photo2);
//RESIZE
  resizeImage(photo2,photo3,128,128);
  image2.picture.LoadFromFile(photo3);
  datamodule2.Table1.edit;
  FileConvertJpegToBmp(photo3,photo4);
  dbimage1.picture.Bitmap.LoadFromFile(photo4);
  datamodule2.Table1.post;
  deletefile(photo4);
end;
Datamodule2.table1.next;
end;
gauge1.Visible:=false;
image2.Visible:=False;
end;

procedure TFoptimise.FormClose(Sender: TObject; var Action: TCloseAction);
begin
datamodule2.Table1.close;
end;

end.

// after try to pack the dataset table.










Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment













 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
I. Siticov
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)