Bonjour à toutes et à tous,
J'aimerai réaliser une application qui scannerai un document afin de le sauver en image bmp, jpg, png.
Seulement, j'aimerai pouvoir appliquer un resize (800 x 600) avant la sauvegarde.
Voici mon code au cas ou quelqu'un aurait une idée :
Merci d'avance,
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91 procedure TFormScan.BacquerirClick(Sender: TObject); Var ImgTmp:TImage; n:Integer; TestDib:HBitmap; begin ImgTmp:=TImage.Create(Self); TWAIN_SelectImageSource(0); TWAIN_AcquireNative(0,0); n:=TWAIN_GetNumDibs; if n>=1 then begin TestDib:=TWAIN_GetDib(0); //Handle de la source CopyDibIntoImage(TestDib,ImgTmp); //Tansforme l'image DIB en Bitmap TWAIN_FreeNative(TestDib); //Libère la mémoire //Affiche dans "Image1" l'image "ImgTmp" Image1.Picture.Bitmap.Width:=ImgTmp.Width; Image1.Picture.Bitmap.Height:=ImgTmp.Height; Image1.Picture:=ImgTmp.Picture; end; end; procedure TFormScan.BenregistrerClick(Sender: TObject); begin SPD1.DefaultExt := GraphicExtension(TBitmap); with SPD1 {or SaveDialog1}do begin Filter := 'Bitmap|*.bmp|Jpeg|*.jpg'{$IFDEF SAVEPNG}+'|Png|*.png'{$ENDIF}; DefaultExt := '.bmp'; if execute then case FilterIndex of 1 : with TBitmap.Create do try Assign(image1.picture.Graphic); PixelFormat := pf24bit; SaveToFile(ChangeFileExt(FileName,'.bmp')); finally Free; end; 2 : with TJPEGImage.Create do try CompressionQuality := 80; {75..85 : best ratio Size/Quality} ProgressiveEncoding := True; {True : good for web or slow computer} Assign(image1.picture.bitmap); SaveToFile(ChangeFileExt(FileName,'.jpg')); finally Free; end; {$IFDEF SAVEPNG} {$IFDEF PNGLIB1}{use PNGImage lib} 3 : with TPNGObject.Create do try Assign(image1.picture.bitmap); CompressionLevel := 9; {9 : best quality but slow at hell} InterlaceMethod := imNone; Filters := [pfAverage]; Transparent := false; RemoveTransparency; SaveToFile(ChangeFileExt(FileName,'.png')); finally Free; end; {$ELSE} {$IFDEF PNGLIB2}{use zPNG lib} 3 : with TPNGImage.Create do try Assign(image1.picture.bitmap); CompressionLevel := clBest; PixelFormat := pf24bit; SaveToFile(ChangeFileExt(FileName,'.png')); finally Free; end; {$ELSE}{use Unknow/Custom PNG lib} 3 : with {INSERT NAME OF YOUR CUSTOM PNG CLASS HERE}.Create do try {INSERT PROPERTIES/PARAMETERS OF YOUR CUSTOM PNG CLASS HERE} SaveToFile(ChangeFileExt(FileName,'.png')); finally Free; end; {$ENDIF} {$ENDIF} {$ENDIF} end; {case} end; {with} end;
@+,
Cincap
Partager