怎样改变原有的尺寸320 X 240 ,达到1寸照片的效果,我用代码调整尺寸,但照片变形,请帮我看看程序或用其他的方法来实现,感谢!
unit GetPhotoUnit;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls,jpeg,AviCap, OleCtrls;type
  TGetPhotoForm = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    Shape2: TShape;
    Image1: TImage;
    Shape1: TShape;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
  private
    { Private declarations }
  procedure BmpToJpg;
  Procedure ChangePicSiz(SourceFileName,DescFileName:string);
  public
    { Public declarations }
  end;
const WM_CAP_START = WM_USER;
const WM_CAP_STOP = WM_CAP_START + 68;
const WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10;
const WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11;
const WM_CAP_SAVEDIB = WM_CAP_START + 25;
const WM_CAP_GRAB_FRAME = WM_CAP_START + 60;
const WM_CAP_SEQUENCE = WM_CAP_START + 62;
const WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20;
const WM_CAP_SEQUENCE_NOFILE =WM_CAP_START+ 63;
const WM_CAP_SET_OVERLAY =WM_CAP_START+ 51;
const WM_CAP_SET_PREVIEW =WM_CAP_START+ 50;
const WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START +6;
const WM_CAP_SET_CALLBACK_ERROR=WM_CAP_START +2;
const WM_CAP_SET_CALLBACK_STATUSA= WM_CAP_START +3;
const WM_CAP_SET_CALLBACK_FRAME= WM_CAP_START +5;
const WM_CAP_SET_SCALE=WM_CAP_START+ 53;
const WM_CAP_SET_PREVIEWRATE=WM_CAP_START+ 52;function capCreateCaptureWindowA(lpszWindowName : PCHAR; dwStyle : longint; x : integer;
y : integer;nWidth : integer;nHeight : integer;ParentWin : HWND;
nId : integer): HWND;STDCALL EXTERNAL 'dll\AVICAP32.DLL';
var
  GetPhotoForm: TGetPhotoForm;
  hWndC : THandle;
implementation{$R *.dfm}
 uses ProMainUnit;
procedure TGetPhotoForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
if hWndC <> 0 then begin
 SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0);
 hWndC := 0;
end;
  Action:=cafree;
end;procedure TGetPhotoForm.BitBtn1Click(Sender: TObject);
begin
if hWndC <> 0 then begin
 SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0);
 hWndC := 0;
end;
//
hWndC := capCreateCaptureWindowA('GetPhotoForm',WS_CHILD or WS_VISIBLE ,Panel1.Left,Panel1.Top,100,126,GetPhotoForm.Handle,0);
hWndC := capCreateCaptureWindowA('GetPhotoForm',WS_CHILD or WS_VISIBLE ,Panel1.Left,Panel1.Top,100,126,GetPhotoForm.Handle,0);
if hWndC <> 0 then
begin
 // SendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0);
 SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0);
 SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0);
 SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0);
 SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0);
 SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0);
 SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0);
 SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0);
end;
end;procedure TGetPhotoForm.BitBtn2Click(Sender: TObject);
var Dc: HDC;
 MyCanvas: TCanvas;
 MyRect: TRect;
begin
 Dc := GetWindowDC(0);
 MyCanvas := TCanvas.Create;
 SendMessage(hWndC,WM_CAP_SAVEDIB,0,longint(pchar(ExtractFilePath(Application.ExeName)+'Tmp\TmpPhoto.bmp')));
 try
   MyCanvas.Handle := Dc;
   MyRect:=Rect(0, 0,Image1.Width, Image1.Height);
   Image1.Canvas.CopyRect(MyRect, MyCanvas, MyRect);
 finally
  MyCanvas.Handle := 0;
  MyCanvas.Free;
  ReleaseDC(0, Dc);
 end;
BmpToJpg;
Image1.Picture.LoadFromFile(ExtractFilePath(Application.ExeName)+'Tmp\TmpPhoto.jpg');
showmessage('照相成功!');
 ProMainForm.Image1.Picture.LoadFromFile(ExtractFilePath(Application.ExeName)+'Tmp\TmpPhoto.jpg'); close;
end;procedure TGetPhotoForm.BmpToJpg;
 var
   Jpeg : TJPEGImage;
   Bmp : TBitmap;
begin
   Bmp := TBitmap.Create;
  try
   Bmp.LoadFromFile(ExtractFilePath(Application.ExeName)+'Tmp\TmpPhoto.bmp');
   Jpeg := TJPEGImage.Create;
try
   Jpeg.Assign(bmp);
   jpeg.CompressionQuality :=30;
   Jpeg.Compress;
//保存图片
   Jpeg.SaveToFile(ExtractFilePath(Application.ExeName)+'Tmp\TmpPhoto.jpg');
   ChangePicSiz(ExtractFilePath(Application.ExeName)+'Tmp\TmpPhoto.jpg',ExtractFilePath(Application.ExeName)+'Tmp\TmpPhoto.jpg')
finally
   Jpeg.Free;
end;
finally
   Bmp.Free;
end;end;procedure TGetPhotoForm.BitBtn3Click(Sender: TObject);
begin close;
end;procedure TGetPhotoForm.ChangePicSiz(SourceFileName, DescFileName: string);
var   
        jpg:TJPEGImage;
        bmp:TBitmap;
        SourceJpg:TJPEGImage;
        FWidth,FHeight:Integer;
begin
   FWidth   :=   100;
      FHeight   :=   126;
      bmp   :=   TBitmap.Create;
      SourceJpg   :=   TJPEGImage.Create;
      Jpg:=   TJPEGImage.Create;
      try
                      //读取源文件   
       SourceJpg.LoadFromFile(SourceFileName);
                      //缩小   
       bmp.Width   :=   FWidth;
       bmp.Height   :=   FHeight;
       bmp.PixelFormat   :=   pf24bit;
       bmp.Canvas.StretchDraw(Rect(0,   0,   FWidth,   FHeight),   SourceJpg);
                      //保存   
       jpg.Assign(bmp);
       jpg.SaveToFile(DescFileName);
       finally
        bmp.Free;
        jpg.Free;
        SourceJpg.Free;
       end;   end;end.

解决方案 »

  1.   

    1、代码绕来绕去,貌似走了许多弯路2、你的TmpPhoto.bmp、TmpPhoto.jpg是相同的尺寸,后来的TmpPhoto.jpg只是规定长宽之后进行了Stretch调整。倒底是想达到什么结果?根据固定的长宽压缩?或是从原始图象中裁取固定长宽的一部分?
      

  2.   

    主要是输出设备的dpi决定的吧,应该输出控制才对吧,改原始图像好像意义不大
      

  3.   

    你的原始尺寸stretch到1英寸的时候比例不一样,剪裁成1英寸比例后然后再stretchDraw
      

  4.   

    如果是将摄像头拍的照片压缩显示的话,很方便,用 TGpImage 和TGpGraphics 就可以做到,而且效果非常好,不会有损
      

  5.   

        try
          FGpBitmap := TGpBitmap.Create(FGpBitmapName);//FGpBitmapName = 文件名
          self.Color := clBlack;
          pg := TGPGraphics.Create(form.Canvas.Handle);
          rc := GpRect(3,3,103,70);
          pg.DrawImage(FGpBitmap,rc, 3, 3, FGpBitmap.Width, FGpBitmap.Height, utPixel);
        finally
          FGpBitmap.Free;
          pg.Free;
        end;
      

  6.   

    //原图//压缩图
    http://tg1a128.mail.163.com/netfolder/servlet/nfapp/GetFile?sid=sCfrQiGGJvuKBjmRdKGGQFbVRKhOvles&mid=1tbi7h90METM3Rl2uAAAs3
      

  7.   

    不知道楼主使用的是什么进行视频捕获了!如果用VFW的话,可以会有一个回调函数返回每一贞的信息,这个时候
    可以使用一个Image来把图片放到Image上,然后在在Image上调整就简单了,我以前就是这样取尺寸的。
      

  8.   

    看楼主貌似是用VFW处理的,我写了一个这样的视频控件!如果有需要我就放出来吧。
    不过VFW现在过时了!以前公司的视频用我这个的时候,有些摄相头的图象搞不出来
    所以,建议楼主使用DirectShow吧!