uses JPEG, GDIPAPI, GDIPOBJ;
procedure TForm1.acAddJpgExecute(Sender: TObject);
var
idx: integer;
jpg: TjpegImage;
GPImage: TGPimage;
GPGraphics: TGPGraphics;
pPropItem: PPropertyItem;
BufferSize: Cardinal;
Orientation: Byte;
RotateType: TRotateFlipType;
Bitmap: TBitmap;
TempBitmap: TBitmap;
iHeight: integer;
begin
if OpenPictureDialog1.Execute then begin
for idx := 0 to OpenPictureDialog1.Files.Count - 1 do begin
ZQuery1.Append;
ZQuery1.FieldByName('ino').AsInteger := idx*10;
ZQuery1.FieldByName('idate').AsString := DateToStr(DatePicker1.Date);
GPImage := TGPimage.Create(OpenPictureDialog1.Files[idx]);
try
BufferSize := GPImage.GetPropertyItemSize(PropertyTagOrientation);
if BufferSize > 0 then begin
GetMem(pPropItem, BufferSize);
try
GPImage.GetPropertyItem(PropertyTagOrientation, BufferSize, pPropItem);
Orientation := PByte(pPropItem.value)^;
case Orientation of
1: RotateType := RotateNoneFlipNone; // Horizontal - No rotation required
2: RotateType := RotateNoneFlipX;
3: RotateType := Rotate180FlipNone;
4: RotateType := Rotate180FlipX;
5: RotateType := Rotate90FlipX;
6: RotateType := Rotate90FlipNone;
7: RotateType := Rotate270FlipX;
8: RotateType := Rotate270FlipNone;
else RotateType := RotateNoneFlipNone; // Unknown rotation?
end;
if RotateType <> RotateNoneFlipNone then GPImage.RotateFlip(RotateType);
Bitmap := TBitmap.Create;
TempBitmap := TBitmap.Create;
try
Bitmap.Width := GPImage.GetWidth;
Bitmap.Height := GPImage.GetHeight;
Bitmap.Canvas.Lock;
try
GPGraphics := TGPGraphics.Create(Bitmap.Canvas.Handle);
try
GPGraphics.DrawImage(GPImage, 0, 0, GPImage.GetWidth, GPImage.GetHeight);
if Bitmap.Width > 1280 then begin
iHeight := Ceil((Bitmap.Height * 1280) / Bitmap.Width);
TempBitmap.Width := 1280;
TempBitmap.Height := iHeight;
SetStretchBltMode(TempBitmap.Canvas.Handle, HALFTONE);
StretchBlt(TempBitmap.Canvas.Handle, 0, 0, TempBitmap.Width, TempBitmap.Height, Bitmap.Canvas.Handle, 0, 0, Bitmap.Width, Bitmap.Height, SRCCOPY);
DBImage1.Picture.Assign(TempBitmap);
end
else DBImage1.Picture.Assign(Bitmap);
ZQuery1.Post;
finally GPGraphics.Free;
end;
finally Bitmap.Canvas.Unlock;
end;
finally
Bitmap.Free;
TempBitmap.Free;
end;
finally FreeMem(pPropItem);
end;
end
else begin
Bitmap := TBitmap.Create;
TempBitmap := TBitmap.Create;
try
Bitmap.Width := GPImage.GetWidth;
Bitmap.Height := GPImage.GetHeight;
Bitmap.Canvas.Lock;
try
GPGraphics := TGPGraphics.Create(Bitmap.Canvas.Handle);
try
GPGraphics.DrawImage(GPImage, 0, 0, GPImage.GetWidth, GPImage.GetHeight);
if Bitmap.Width > 1280 then begin
iHeight := Ceil((Bitmap.Height * 1280) / Bitmap.Width);
TempBitmap.Width := 1280;
TempBitmap.Height := iHeight;
SetStretchBltMode(TempBitmap.Canvas.Handle, HALFTONE);
StretchBlt(TempBitmap.Canvas.Handle, 0, 0, TempBitmap.Width, TempBitmap.Height, Bitmap.Canvas.Handle, 0, 0, Bitmap.Width, Bitmap.Height, SRCCOPY);
DBImage1.Picture.Assign(TempBitmap);
end
else DBImage1.Picture.Assign(Bitmap);
ZQuery1.Post;
finally GPGraphics.Free;
end;
finally Bitmap.Canvas.Unlock;
end;
finally
Bitmap.Free;
TempBitmap.Free;
end;
end;
finally GPImage.Free
end;
end;
StatusBar1.SimpleText := '사진을 읽어왔습니다, 작업사항을 입력하십시요.'
end; // for
end;