Kodbank İndir

! CODEBANK 2012 !

İNDİRMEK&DETAYLI BİLGİ ALMAK İÇİN BURAYI TIKLAYINIZ.

ÖNEMLİ AÇIKLAMA: MUTLAKA OKUYUNUZ!

Gönderen Konu: her zaman farklı isimle kaydetmek  (Okunma sayısı 374 defa)

0 Üye ve 1 Ziyaretçi konuyu incelemekte.

tdoktoru

  • Ziyaretçi
her zaman farklı isimle kaydetmek
« : 30 Haziran 2009 11:00:33 »
merhaba arkadaslar ben button1 e her tıkladıgımda c:\ dizinine otomatik deneme[1].jpg, deneme[2].jpg, deneme[3].jpg atmasını nasıl saglayabilirim.

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    save: TSavePictureDialog;
    procedure Button1Click(Sender: TObject);
 procedure BmpDenJpgye(bmpyolu:string;jpgyolu:string);   
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
procedure Tform1.BmpDenJpgye(bmpyolu:string;jpgyolu:string);
var
  JpegImg: TJpegImage;
  Bitmap: TBitmap;
begin
  Bitmap := TBitmap.Create;
  try
   Bitmap.LoadFromFile(bmpyolu) ;
   JpegImg := TJpegImage.Create;
   try
    JpegImg.Assign(Bitmap) ;
    JpegImg.SaveToFile(jpgyolu) ;
    finally
    JpegImg.Free
   end;
  finally
   Bitmap.Free
  end;
end;

// 1. Get the handle to the current mouse-cursor and its position
function GetCursorInfo2: TCursorInfo;
var
 hWindow: HWND;
 pt: TPoint;
 pIconInfo: TIconInfo;
 dwThreadID, dwCurrentThreadID: DWORD;
begin
 Result.hCursor := 0;
 ZeroMemory(@Result, SizeOf(Result));
 // Find out which window owns the cursor
 if GetCursorPos(pt) then
 begin
   Result.ptScreenPos := pt;
   hWindow := WindowFromPoint(pt);
   if IsWindow(hWindow) then
   begin
     // Get the thread ID for the cursor owner.
     dwThreadID := GetWindowThreadProcessId(hWindow, nil);

     // Get the thread ID for the current thread
     dwCurrentThreadID := GetCurrentThreadId;

     // If the cursor owner is not us then we must attach to
     // the other thread in so that we can use GetCursor() to
     // return the correct hCursor
     if (dwCurrentThreadID <> dwThreadID) then
     begin
       if AttachThreadInput(dwCurrentThreadID, dwThreadID, True) then
       begin
         // Get the handle to the cursor
         Result.hCursor := GetCursor;
         AttachThreadInput(dwCurrentThreadID, dwThreadID, False);
       end;
     end
     else
     begin
       Result.hCursor := GetCursor;
     end;
   end;
 end;
end;

// 2. Capture the screen
function CaptureScreen: TBitmap;
var
 DC: HDC;
 ABitmap: TBitmap;
 MyCursor: TIcon;
 CursorInfo: TCursorInfo;
 IconInfo: TIconInfo;
begin
 // Capture the Desktop screen
 DC := GetDC(GetDesktopWindow);
 ABitmap := TBitmap.Create;
 try
   ABitmap.Width  := GetDeviceCaps(DC, HORZRES);
   ABitmap.Height := GetDeviceCaps(DC, VERTRES);
   // BitBlt on our bitmap
   BitBlt(ABitmap.Canvas.Handle,
     0,
     0,
     ABitmap.Width,
     ABitmap.Height,
     DC,
     0,
     0,
     SRCCOPY);
   // Create temp. Icon
   MyCursor := TIcon.Create;
   try
     // Retrieve Cursor info
     CursorInfo := GetCursorInfo2;
     if CursorInfo.hCursor <> 0 then
     begin
       MyCursor.Handle := CursorInfo.hCursor;
       // Get Hotspot information
       GetIconInfo(CursorInfo.hCursor, IconInfo);
       // Draw the Cursor on our bitmap
       ABitmap.Canvas.Draw(CursorInfo.ptScreenPos.X - IconInfo.xHotspot,
                           CursorInfo.ptScreenPos.Y - IconInfo.yHotspot, MyCursor);
     end;
   finally
     // Clean up
     MyCursor.ReleaseHandle;
     MyCursor.Free;
   end;
 finally
   ReleaseDC(GetDesktopWindow, DC);
 end;
 Result := ABitmap;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
  Image1.Picture.Assign(CaptureScreen);
//  image1.Picture.SaveToFile('C:\deneme.bmp');
  BmpDenJpgye('C:\deneme.bmp','C:\deneme.jpg');//Bmden Jpye çeviriyorum
  // ben her tıkladıgımda otomatik deneme[1].jpg, deneme[2].jpg, deneme[3].jpg olarak
  // aktarmasını istiyorum
  end;
end.

Çevrimdışı barutali

  • Administrator
  • *****
  • İleti: 2.116
  • Rep: +51/-0
  • Cinsiyet: Bay
  • Falan filan ...
Ynt: her zaman farklı isimle kaydetmek
« Yanıtla #1 : 30 Haziran 2009 11:49:27 »
Kod: Delphi
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs,jpeg, StdCtrls, ExtCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Button1: TButton;
  12.     Image1: TImage;
  13.     procedure Button1Click(Sender: TObject);
  14.   private
  15.     { Private declarations }
  16.  
  17.    arttir : integer;  // eklendii
  18.  
  19.     procedure BmpDenJpgye(bmpyolu:string;jpgyolu:string);
  20.   public
  21.     { Public declarations }
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. {$R *.dfm}
  30.  
  31. procedure Tform1.BmpDenJpgye(bmpyolu:string;jpgyolu:string);
  32. var
  33.   JpegImg: TJpegImage;
  34.   Bitmap: TBitmap;
  35. begin
  36.   Bitmap := TBitmap.Create;
  37.   try
  38.    Bitmap.LoadFromFile(bmpyolu) ;
  39.    JpegImg := TJpegImage.Create;
  40.    try
  41.     JpegImg.Assign(Bitmap) ;
  42.     JpegImg.SaveToFile(jpgyolu) ;
  43.     finally
  44.     JpegImg.Free
  45.    end;
  46.   finally
  47.    Bitmap.Free
  48.   end;
  49. end;
  50.  
  51. function GetCursorInfo2: TCursorInfo;
  52. var
  53.  hWindow: HWND;
  54.  pt: TPoint;
  55.  pIconInfo: TIconInfo;
  56.  dwThreadID, dwCurrentThreadID: DWORD;
  57. begin
  58.  Result.hCursor := 0;
  59.  ZeroMemory(@Result, SizeOf(Result));
  60.  // Find out which window owns the cursor
  61.  if GetCursorPos(pt) then
  62.  begin
  63.    Result.ptScreenPos := pt;
  64.    hWindow := WindowFromPoint(pt);
  65.    if IsWindow(hWindow) then
  66.    begin
  67.      // Get the thread ID for the cursor owner.
  68.      dwThreadID := GetWindowThreadProcessId(hWindow, nil);
  69.  
  70.      // Get the thread ID for the current thread
  71.      dwCurrentThreadID := GetCurrentThreadId;
  72.  
  73.      // If the cursor owner is not us then we must attach to
  74.      // the other thread in so that we can use GetCursor() to
  75.      // return the correct hCursor
  76.      if (dwCurrentThreadID <> dwThreadID) then
  77.      begin
  78.        if AttachThreadInput(dwCurrentThreadID, dwThreadID, True) then
  79.        begin
  80.          // Get the handle to the cursor
  81.          Result.hCursor := GetCursor;
  82.          AttachThreadInput(dwCurrentThreadID, dwThreadID, False);
  83.        end;
  84.      end
  85.      else
  86.      begin
  87.        Result.hCursor := GetCursor;
  88.      end;
  89.    end;
  90.  end;
  91. end;
  92.  
  93. // 2. Capture the screen
  94. function CaptureScreen: TBitmap;
  95. var
  96.  DC: HDC;
  97.  ABitmap: TBitmap;
  98.  MyCursor: TIcon;
  99.  CursorInfo: TCursorInfo;
  100.  IconInfo: TIconInfo;
  101. begin
  102.  // Capture the Desktop screen
  103.  DC := GetDC(GetDesktopWindow);
  104.  ABitmap := TBitmap.Create;
  105.  try
  106.    ABitmap.Width  := GetDeviceCaps(DC, HORZRES);
  107.    ABitmap.Height := GetDeviceCaps(DC, VERTRES);
  108.    // BitBlt on our bitmap
  109.    BitBlt(ABitmap.Canvas.Handle,
  110.      0,
  111.      0,
  112.      ABitmap.Width,
  113.      ABitmap.Height,
  114.      DC,
  115.      0,
  116.      0,
  117.      SRCCOPY);
  118.    // Create temp. Icon
  119.    MyCursor := TIcon.Create;
  120.    try
  121.      // Retrieve Cursor info
  122.      CursorInfo := GetCursorInfo2;
  123.      if CursorInfo.hCursor <> 0 then
  124.      begin
  125.        MyCursor.Handle := CursorInfo.hCursor;
  126.        // Get Hotspot information
  127.        GetIconInfo(CursorInfo.hCursor, IconInfo);
  128.        // Draw the Cursor on our bitmap
  129.        ABitmap.Canvas.Draw(CursorInfo.ptScreenPos.X - IconInfo.xHotspot,
  130.                            CursorInfo.ptScreenPos.Y - IconInfo.yHotspot, MyCursor);
  131.      end;
  132.    finally
  133.      // Clean up
  134.      MyCursor.ReleaseHandle;
  135.      MyCursor.Free;
  136.    end;
  137.  finally
  138.    ReleaseDC(GetDesktopWindow, DC);
  139.  end;
  140.  Result := ABitmap;
  141. end;
  142.  
  143.  
  144. procedure TForm1.Button1Click(Sender: TObject);
  145. begin
  146. Inc(arttir);   // eklendii
  147. Image1.Picture.Assign(CaptureScreen);
  148. BmpDenJpgye('C:\deneme.bmp',format('C:\deneme%d.jpg',[arttir])); // değiştirildi
  149.  
  150. end;
  151.  
  152.  
  153. end.
  154.  
  155.  


 buyur arkadaşım yukarıdaki kodları kullan istediğin gibi +1 olarak arttırıp kaydediyor...

değişen ve eklenen yerleri belirttim
kolay gelsin...



Amatör Küme Programcı

tdoktoru

  • Ziyaretçi
Ynt: her zaman farklı isimle kaydetmek
« Yanıtla #2 : 30 Haziran 2009 11:51:02 »
teşekkür ederim Allah razı olsun

Çevrimdışı barutali

  • Administrator
  • *****
  • İleti: 2.116
  • Rep: +51/-0
  • Cinsiyet: Bay
  • Falan filan ...
Ynt: her zaman farklı isimle kaydetmek
« Yanıtla #3 : 30 Haziran 2009 11:51:52 »
Sendende Allah razı olsun kardeşim..



Amatör Küme Programcı