AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

save images from clipboard
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Utilities & Resources
View previous topic :: View next topic  
Author Message
kiu



Joined: 18 Dec 2005
Posts: 229
Location: Italy - Galatro(RC)

PostPosted: Thu Feb 02, 2006 1:47 pm    Post subject: save images from clipboard Reply with quote

use my app:
kiu-clipsave
3.5 KB only

and a code like this

Code:

Send,!{PrintScreen}
Sleep,1000
RunWait, kiu-clipsave.exe, , Hide
Sleep,1000
SplashImage, image.jpg, B2
KeyWait, LButton, down
return

_________________
____________________
______________________
kiu


Last edited by kiu on Thu Feb 02, 2006 4:27 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
kiu



Joined: 18 Dec 2005
Posts: 229
Location: Italy - Galatro(RC)

PostPosted: Thu Feb 02, 2006 1:47 pm    Post subject: Reply with quote

the source code is in c#.If someone is interested, let me know
_________________
____________________
______________________
kiu
Back to top
View user's profile Send private message Visit poster's website
Greg



Joined: 22 Dec 2005
Posts: 246

PostPosted: Thu Feb 02, 2006 1:54 pm    Post subject: Reply with quote

Why use C# when this can all be done with AHK using Clipboard and ClipboardAll?
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Thu Feb 02, 2006 2:15 pm    Post subject: Reply with quote

This has been discussed already. AFAIK, you can't save to a file a picture in the clipboard without an external program. You can do that with IrfanView, Image Magick and probably many other image softwares (but not so many working on the command line; no GUI to flicker).
kiu doesn't like IrfanView (why? just curiosity), so he (?) made his own hand-made program. Why not.

Note to kiu: IIRC, if you make a Windows program without window, you don't need the Hide parameter with RunWait.


Last edited by PhiLho on Wed Sep 13, 2006 4:20 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Greg



Joined: 22 Dec 2005
Posts: 246

PostPosted: Thu Feb 02, 2006 2:39 pm    Post subject: Reply with quote

Quote:
you can't save to a file a picture in the clipboard without an external program.


I quickly tested it, and it appears you are correct. So I retract my previous statement.
Back to top
View user's profile Send private message
kiu



Joined: 18 Dec 2005
Posts: 229
Location: Italy - Galatro(RC)

PostPosted: Thu Feb 02, 2006 3:17 pm    Post subject: Reply with quote

you need .net 1.1 to use it
_________________
____________________
______________________
kiu
Back to top
View user's profile Send private message Visit poster's website
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Thu Feb 02, 2006 3:27 pm    Post subject: Reply with quote

@Greg: kiu's app saves the clipboard to an jpb and png file. So it is something differnt then ClipBoardAll.

Dear kiu,
Thanks for the app and for the comments to my EasyCopy script. There are several reasons why I prefer IrfanView:
1) It supports more image formats then JPG, PNG
2) It can capture regions
3) User can specify file name (could be done with FileMove for your app as well)
4) It can apply/change DPI, bpp, swap B/W, grayscale, sharpen, contrast, sresize, resample
5) It supports different quality level for JPGs and Tiffs

But your source code might be interessting for Chris, since on his "to do" list is an item that is to convert images in DIB format on the clipboard to a file. But it doesn't have high prio.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kiu



Joined: 18 Dec 2005
Posts: 229
Location: Italy - Galatro(RC)

PostPosted: Thu Feb 02, 2006 4:32 pm    Post subject: Reply with quote

Code:
/*
 * User:   kiu - Salvatore Agostino Romeo
 * Date:   02/02/2006
 * Time:   13.05
 * e-mail:   romeo84@hotmail.com
 *
 */

using System;
using System.Windows.Forms;
using System.Drawing;

namespace DefaultNamespace
{
   /// <summary>
   /// Save images from clipboard.
   /// </summary>
   public class GetClip
   {
      public static void Main()
      {
         if (Clipboard.GetDataObject() != null)
         {
            IDataObject data = Clipboard.GetDataObject();
            
            if (data.GetDataPresent(DataFormats.Bitmap))
               {
                  Image image = (Image)data.GetData(DataFormats.Bitmap,true);
                  image.Save("image.png",System.Drawing.Imaging.ImageFormat.Png);
                  image.Save("image.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
               }
         }
         
      }
   }
}


adding

Code:
image.Save("image.png",System.Drawing.Imaging.ImageFormat.Bmp);

will allow to save to bmp, and it is possible to save to gif (and others maybe) too. Let me know if you are interested in other format outputs
_________________
____________________
______________________
kiu
Back to top
View user's profile Send private message Visit poster's website
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Thu Feb 02, 2006 4:41 pm    Post subject: Reply with quote

So the code cannot be used by Chris, since it uses .Net facilities... Sad

kiu, perhaps you can complicate slightly your code and accept one (or several) filename(s) as parameter. The extension would indicate which format is wanted. This would avoid overwritting/renaming previous files and unecessary file creation (if only one format is needed, which is likely).
Back to top
View user's profile Send private message Visit poster's website
kiu



Joined: 18 Dec 2005
Posts: 229
Location: Italy - Galatro(RC)

PostPosted: Thu Feb 02, 2006 4:42 pm    Post subject: Reply with quote

PhiLho wrote:

kiu doesn't like IrfanView (why? just curiosity)


cause you need to install it and I like "unzip and run" programs. Have you ever tried xnview?
-It's not black Very Happy
-no install
-it has a command line version
-it is powerfull like (if not better) irfanview
_________________
____________________
______________________
kiu
Back to top
View user's profile Send private message Visit poster's website
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Thu Feb 02, 2006 6:44 pm    Post subject: Reply with quote

Indeed, IrfanView used to be a simple Zip file, now you have to install it, that's bad...
But I have taken the habit to use it, it is fast, unobstrusive, and I like its interface.
Actually, I usually install XnView too, as they don't cover the same range of image formats (or they did).
Well, writing about that, I just downloaded the latest version of XnView (1.80.3), it seems to have an improved interface and much more image formats... (I downloaded the full version will all plug-ins).

But I am still not fan of the interface, even after playing with the settings, quite numerous. If I want XnView to adapt to the image, when I load a large image (close of screen size), it maximize vertically but has a strangely narrow width... Seems like a bug. Also, if I force to have only one image loaded at a time (tabs are nice, but usually I just want to see the latest chosen image, saving some memory) it shows its underlying MDI nature, ie. it has a subwindow showing the image.
That's what I always disliked in XnView.

That said, I keep XnView handy in the Send To menu, for exotic formats or other features. Eg. IrfanView can read the XPM format (used by SciTE for custom bookmarks) but cannot save it.

And indeed, Nconvert is good too, and much lighter than Image Magick for simple image conversions.
Back to top
View user's profile Send private message Visit poster's website
majkinetor



Joined: 24 May 2006
Posts: 3615
Location: Belgrade

PostPosted: Tue Jan 09, 2007 11:27 am    Post subject: Reply with quote

IrfanView is generaly portable application. THe fact that it has installer doesn't change that. Once installed you can move it around....
_________________
Back to top
View user's profile Send private message MSN Messenger
impecco



Joined: 09 Dec 2007
Posts: 3
Location: Germany

PostPosted: Sun Dec 09, 2007 5:54 pm    Post subject: Save images from clipboard Reply with quote

Isolated some code from Sean's script "ScreenCapture.ahk" posted on
http://www.autohotkey.com/forum/topic18146.html
The code needs the GDI+ libaray "gdiplus.dll" which can be obtained from
http://www.microsoft.com/downloads/details.aspx?FamilyID=6a63ab9c-df12-4d41-933c-be590feaa05a&displaylang=en
and the big advantage is that it works within AutoHotkey without calling external executables and directly captures from the clipboard to a file in bmp or jpg format.

Code:

; Save any bitmaps on the clipboard to file
; isolated by impecco@gmail.com from Sean's script "ScreenCapture.ahk" posted on
;    http://www.autohotkey.com/forum/topic18146.html
; needs GDI+ libaray "gdiplus.dll" which can be obtained from
;    http://www.microsoft.com/downloads/details.aspx?FamilyID=6a63ab9c-df12-4d41-933c-be590feaa05a&displaylang=en

SaveClipBoardToJPG()   ; example
SaveClipBoardToBMP()   ; example

SaveClipBoardToBMP() {
   Convert("", "clip.bmp")
}

SaveClipBoardToJPG() {
   Convert("", "clip.jpg")
}

Convert(sFileFr = "", sFileTo = "")
{
   If   sFileTo  =
      sFileTo := A_ScriptDir . "\screen.bmp"
   SplitPath, sFileTo, , sDirTo, sExtTo, sNameTo

   If Not   hGdiPlus := DllCall("LoadLibrary", "str", "gdiplus.dll")
      Return   sFileFr+0 ? SaveHBITMAPToFile(sFileFr, sDirTo . "\" . sNameTo . ".bmp") : ""
   VarSetCapacity(si, 16, 0), si := Chr(1)
   DllCall("gdiplus\GdiplusStartup", "UintP", pToken, "Uint", &si, "Uint", 0)

   If   !sFileFr
   {
      DllCall("OpenClipboard", "Uint", 0)
      If    DllCall("IsClipboardFormatAvailable", "Uint", 2) && (hBM:=DllCall("GetClipboardData", "Uint", 2)) {
         DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "Uint", hBM, "Uint", 0, "UintP", pImage)
      }   
      DllCall("CloseClipboard")
   }
   Else If   (sFileFr Is Integer) {
      DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "Uint", sFileFr, "Uint", 0, "UintP", pImage)
   }   
   Else {
      DllCall("gdiplus\GdipLoadImageFromFile", "Uint", Unicode4Ansi(wFileFr,sFileFr), "UintP", pImage)
   }   

   DllCall("gdiplus\GdipGetImageEncodersSize", "UintP", nCount, "UintP", nSize)
   VarSetCapacity(ci, nSize)
   DllCall("gdiplus\GdipGetImageEncoders", "Uint", nCount, "Uint", nSize, "Uint", &ci)
   Loop,   %nCount%
   {
      If   !InStr(Ansi4Unicode(NumGet(ci, 76 * (A_Index - 1) + 44)), "." . sExtTo)
         Continue
      pCodec := &ci + 76 * (A_Index - 1)
         Break
   }

   If   pImage
      pCodec   ? DllCall("gdiplus\GdipSaveImageToFile", "Uint", pImage, "Uint", Unicode4Ansi(wFileTo,sFileTo), "Uint", pCodec, "Uint", 0) : DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", "Uint", pImage, "UintP", hBitmap, "Uint", 0) . SetClipboardData(hBitmap), DllCall("gdiplus\GdipDisposeImage", "Uint", pImage)

   DllCall("gdiplus\GdiplusShutdown" , "Uint", pToken)
   DllCall("FreeLibrary", "Uint", hGdiPlus)
}

SaveHBITMAPToFile(hBitmap, sFile)
{
   DllCall("GetObject", "Uint", hBitmap, "int", VarSetCapacity(oi,84,0), "Uint", &oi)
   hFile:=   DllCall("CreateFile", "Uint", &sFile, "Uint", 0x40000000, "Uint", 0, "Uint", 0, "Uint", 2, "Uint", 0, "Uint", 0)
   DllCall("WriteFile", "Uint", hFile, "int64P", 0x4D42|14+40+NumGet(oi,44)<<16, "Uint", 6, "UintP", 0, "Uint", 0)
   DllCall("WriteFile", "Uint", hFile, "int64P", 54<<32, "Uint", 8, "UintP", 0, "Uint", 0)
   DllCall("WriteFile", "Uint", hFile, "Uint", &oi+24, "Uint", 40, "UintP", 0, "Uint", 0)
   DllCall("WriteFile", "Uint", hFile, "Uint", NumGet(oi,20), "Uint", NumGet(oi,44), "UintP", 0, "Uint", 0)
   DllCall("CloseHandle", "Uint", hFile)
}

Unicode4Ansi(ByRef wString, sString)
{
   nSize := DllCall("MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", 0, "int", 0)
   VarSetCapacity(wString, nSize * 2)
   DllCall("MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", &wString, "int", nSize)
   Return   &wString
}

Ansi4Unicode(pString)
{
   nSize := DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "Uint", pString, "int", -1, "Uint", 0, "int",  0, "Uint", 0, "Uint", 0)
   VarSetCapacity(sString, nSize)
   DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "Uint", pString, "int", -1, "str", sString, "int", nSize, "Uint", 0, "Uint", 0)
   Return   sString
}

SetClipboardData(hBitmap)
{
   DllCall("GetObject", "Uint", hBitmap, "int", VarSetCapacity(oi,84,0), "Uint", &oi)
   hDIB :=   DllCall("GlobalAlloc", "Uint", 2, "Uint", 40+NumGet(oi,44))
   pDIB :=   DllCall("GlobalLock", "Uint", hDIB)
   DllCall("RtlMoveMemory", "Uint", pDIB, "Uint", &oi+24, "Uint", 40)
   DllCall("RtlMoveMemory", "Uint", pDIB+40, "Uint", NumGet(oi,20), "Uint", NumGet(oi,44))
   DllCall("GlobalUnlock", "Uint", hDIB)
   DllCall("DeleteObject", "Uint", hBitmap)
   DllCall("OpenClipboard", "Uint", 0)
   DllCall("EmptyClipboard")
   DllCall("SetClipboardData", "Uint", 8, "Uint", hDIB)
   DllCall("CloseClipboard")
}

 

_________________
Impecco: Rerum Cognoscere Causas!
Back to top
View user's profile Send private message
mindless



Joined: 09 Mar 2006
Posts: 2

PostPosted: Wed Feb 13, 2008 12:14 pm    Post subject: Reply with quote

I downloaded your script impecco but couldn't get it to work, when I tried running it an error pops up saying:

Error at line 10.

Line Text: SaveClipBoardToBMP() {
Error: This line does not contain a recognized action.

The program will exit.

Any ideas what i'm doing wrong. (i'm using windows XP)
Back to top
View user's profile Send private message
BoBoĻ
Guest





PostPosted: Wed Feb 13, 2008 4:19 pm    Post subject: Reply with quote

Check out if functions really allow One True Brace (OTB) style.
Code:
SaveBMPToFile() {
   }

vs
Code:
SaveBMPToFile()
{
   }
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Utilities & Resources All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group