Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

save images from clipboard


  • Please log in to reply
16 replies to this topic
kiu
  • Members
  • 234 posts
  • Last active: Oct 10 2010 07:30 PM
  • Joined: 18 Dec 2005
use my app:
kiu-clipsave
3.5 KB only

and a code like this

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


kiu
  • Members
  • 234 posts
  • Last active: Oct 10 2010 07:30 PM
  • Joined: 18 Dec 2005
the source code is in c#.If someone is interested, let me know

Greg
  • Members
  • 245 posts
  • Last active: Jun 02 2006 05:39 PM
  • Joined: 22 Dec 2005
Why use C# when this can all be done with AHK using Clipboard and ClipboardAll?

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
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.

Greg
  • Members
  • 245 posts
  • Last active: Jun 02 2006 05:39 PM
  • Joined: 22 Dec 2005

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.

kiu
  • Members
  • 234 posts
  • Last active: Oct 10 2010 07:30 PM
  • Joined: 18 Dec 2005
you need .net 1.1 to use it

toralf
  • Moderators
  • 4034 posts
  • Last active: Jul 19 2014 02:32 AM
  • Joined: 31 Jan 2005
@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.

kiu
  • Members
  • 234 posts
  • Last active: Oct 10 2010 07:30 PM
  • Joined: 18 Dec 2005
/*
 * 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

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

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
So the code cannot be used by Chris, since it uses .Net facilities... :-(

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).

kiu
  • Members
  • 234 posts
  • Last active: Oct 10 2010 07:30 PM
  • Joined: 18 Dec 2005

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 :D
-no install
-it has a command line version
-it is powerfull like (if not better) irfanview

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
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.

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Oct 02 2013 02:33 PM
  • Joined: 24 May 2006
IrfanView is generaly portable application. THe fact that it has installer doesn't change that. Once installed you can move it around....

impecco
  • Members
  • 3 posts
  • Last active: Feb 13 2008 08:55 PM
  • Joined: 09 Dec 2007
Isolated some code from Sean's script "ScreenCapture.ahk" posted on
http://www.autohotke...topic18146.html
The code needs the GDI+ libaray "gdiplus.dll" which can be obtained from
http://www.microsoft... ... laylang=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.

; 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")
}



mindless
  • Members
  • 2 posts
  • Last active: Feb 13 2008 03:55 PM
  • Joined: 09 Mar 2006
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)

BoBo¨
  • Guests
  • Last active:
  • Joined: --
Check out if functions really allow One True Brace (OTB) style.
SaveBMPToFile() {
   }
vs
SaveBMPToFile()
{
   }