Posts: 795
Threads: 136
Joined: Feb 2009
Hi Gintaras, I all,
Gintaras, from previous posts, you showed me to convert an image on disk via the GflAx library.
Now for my project, i'd like to:
1. find an image in google image, copy it to clipboard (easy part i've done).
Note that clipboard can be filled by image from any size and any extension (png, gif, jpg etc)
Now, the tough part:
2. change size directly from THE CLIPBOARD IMAGE i.e in memory to a chosen size (say : 300x300)
3. be able to paste it as jpg or png only.
Example:
copy in firefox a png image of 950x950, then resize it to 300x300 in memory, and paste it in another program
as a 300x300 jpg, quality 80.
Possible in QM?
Thanks
Posts: 12,028
Threads: 139
Joined: Dec 2002
Possible to convert/resize, but I don't know how to paste as png or jpg, there are no standard clipboard formats for it. But maybe possible, look in stackoverflow etc.
For the convert/resize part, also search QM forum, all I know about it is already here.
Even the copy part has problems. Web browser probably copies only as bitmap, without alpha channel.
Posts: 795
Threads: 136
Joined: Feb 2009
Found my old post only, but thanks, as usual...
Posts: 795
Threads: 136
Joined: Feb 2009
OK, found a way.
Now menu interaction.
Easy to simulate key presses, but is possible to send directly a menu item to a control, without using
simulated menu buttons?
Record menu in tools->options only "replays".
so is some code like
1. child("control name" "TDropPanel" w)
and send directly paste command or drop command (it is a tdroppanel) so i suppose
it can be simulated an image drag'n'drop from clipboard on it?
2. Same thing in firefox, can I send
rig and then copy to clipboard directly?
Thanks
Posts: 12,028
Threads: 139
Joined: Dec 2002
Copy image in Firefox directly (without Ctrl+C or menu) - don't know is it possible. More chances if using IE.
Paste directly (without Ctrl+V or menu) - try WM_PASTE message. Or men(), if the program has standard menu bar.
Posts: 795
Threads: 136
Joined: Feb 2009
int w=win("program" "TMainform")
int c=child("control" "TDropPanel" w)
SendMessage c WM_PASTE 0 0
like that?
Posts: 12,028
Threads: 139
Joined: Dec 2002
Yes. Some controls support it.
Posts: 795
Threads: 136
Joined: Feb 2009
nope, no cookie, does not work
not possible via acc?
I think i'll stick to "normal" way
Posts: 795
Threads: 136
Joined: Feb 2009
Gintaras, according to MSDN
http://msdn.microsoft.com/en-us/library/...85%29.aspx
http://msdn.microsoft.com/en-us/library/...85%29.aspx
GdipImage.Save implemented in QM lacks the possibility to provide quality parameter to save to jpeg.
Can you show me how to call GdipImage.Save with this feature?
Posts: 12,028
Threads: 139
Joined: Dec 2002
Macro Macro2185
#compile "__Gdip"
GdipImage g
;...
GDIP.EncoderParameters p
p.Count=1
memcpy &p.Parameter[0].Guid GDIP.EncoderQuality sizeof(GUID)
p.Parameter[0].Type=GDIP.EncoderParameterValueTypeLong
p.Parameter[0].NumberOfValues=1
int quality=0
p.Parameter[0].Value=&quality
g.Save2("file" &p)
Let Save2 is a copy of Save, with added parameter GDIP.EncoderParameters*p, and let it pass p to GdipSaveImageToFile.
Posts: 795
Threads: 136
Joined: Feb 2009
ok, i must recode Save2 to:
Member function GdipImage.Save2
function! $imageFile GDIP.EncoderParameters&p
;Saves this image to file.
;Supported formats: BMP, GIF, JPEG, PNG, TIFF.
;Returns 1 on success, 0 if failed.
;Cannot save to the same file from which FromFile'ed.
str s1.GetFilenameExt(imageFile)
sel(s1) case "jpg" s1="jpeg"; case "tif" s1="tiff"
s1-"image/"
GUID clsEncoder
if(!__GdipGetEncoderClsid(s1 clsEncoder)) ret
_hresult=GDIP.GdipSaveImageToFile(m_i @s1.expandpath(imageFile) &clsEncoder &p)
ret !_hresult
and last one : how to copy a jpeg GdipBitmap to clipboard?
Posts: 12,028
Threads: 139
Joined: Dec 2002
Get bitmap handle, and SetClipboardData(CF_BITMAP
Posts: 795
Threads: 136
Joined: Feb 2009
Macro Macro29
#compile "__Gdip"
GdipBitmap t_im t_out
GDIP.EncoderParameters p
p.Count=1
memcpy &p.Parameter[0].Guid GDIP.EncoderQuality sizeof(GUID)
p.Parameter[0].Type=GDIP.EncoderParameterValueTypeLong
p.Parameter[0].NumberOfValues=1
int quality=100
p.Parameter[0].Value=&quality
OpenClipboard(0)
t_im.FromHBITMAP(GetClipboardData(CF_BITMAP))
CloseClipboard
if(!t_im) out "failed to get bitmap from clipboard"
__MemBmp mb.Create(300 300)
t_im.DrawResize(mb.dc 0 0 300 300 0)
;**************************************
;**************************************
t_out.FromHBITMAP(mb.bm)
_i=t_out.GetHBITMAP
EmptyClipboard
SetClipboardData(CF_BITMAP _i)
t_out.Save2("q:\g.jpg" &p)
i'm struggling with that for a moment now, but this code pastes original image to clipboard (t_im),
not the resized one (t_out).
Grrrr.....
Posts: 12,028
Threads: 139
Joined: Dec 2002
Posts: 795
Threads: 136
Joined: Feb 2009
Macro Macro29
#compile "__Gdip"
GdipBitmap t_im t_out
GDIP.EncoderParameters p
p.Count=1
memcpy &p.Parameter[0].Guid GDIP.EncoderQuality sizeof(GUID)
p.Parameter[0].Type=GDIP.EncoderParameterValueTypeLong
p.Parameter[0].NumberOfValues=1
int quality=100
p.Parameter[0].Value=&quality
OpenClipboard(0)
t_im.FromHBITMAP(GetClipboardData(CF_BITMAP))
CloseClipboard
if(!t_im) out "failed to get bitmap from clipboard"
__MemBmp mb.Create(300 300)
t_im.DrawResize(mb.dc 0 0 300 300 0)
OpenClipboard(0)
t_out.FromHBITMAP(mb.bm)
_i=t_out.GetHBITMAP
SetClipboardData(CF_BITMAP _i)
CloseClipboard
sorry for being so stupid, but still copies the big original image, not the resized (300x300) one....
Posts: 12,028
Threads: 139
Joined: Dec 2002
Posts: 795
Threads: 136
Joined: Feb 2009
Macro Macro29
OpenClipboard(_hwndqm)
t_im.FromHBITMAP(GetClipboardData(CF_BITMAP))
CloseClipboard
EmptyClipboard
if(!t_im) out "failed to get bitmap from clipboard"
__MemBmp mb.Create(300 300)
t_im.DrawResize(mb.dc 0 0 300 300 0)
EmptyClipboard
OpenClipboard(_hwndqm)
t_out.FromHBITMAP(mb.bm)
_i=t_out.GetHBITMAP
SetClipboardData(CF_BITMAP _i)
CloseClipboard
same thing, no change
but
Macro Macro29
GDIP.EncoderParameters p
p.Count=1
memcpy &p.Parameter[0].Guid GDIP.EncoderQuality sizeof(GUID)
p.Parameter[0].Type=GDIP.EncoderParameterValueTypeLong
p.Parameter[0].NumberOfValues=1
int quality=100
p.Parameter[0].Value=&quality
OpenClipboard(_hwndqm)
t_im.FromHBITMAP(GetClipboardData(CF_BITMAP))
CloseClipboard
EmptyClipboard
if(!t_im) out "failed to get bitmap from clipboard"
__MemBmp mb.Create(300 300)
t_im.DrawResize(mb.dc 0 0 300 300 0)
EmptyClipboard
OpenClipboard(_hwndqm)
t_out.FromHBITMAP(mb.bm)
EmptyClipboard; SetClipboardData(CF_BITMAP mb.Detach); CloseClipboard
t_out.Save2("q:\g.jpg" &p)
is a success, i can't see why.......I was supposed to paste t_out not mb..
Posts: 795
Threads: 136
Joined: Feb 2009
ok, it works great now, i just need a little explanation (if you can)
int quality=100
p.Parameter[0].Value=&quality
t_im.DrawResize(mb.dc 0 0 300 300 7)
both parameters to best values for quality.
jpg saved to file=114ko
image pasted from clipboard=27ko
Do you know why?
Posts: 12,028
Threads: 139
Joined: Dec 2002
No. Try some other graphics library, eg GflAx.
Posts: 795
Threads: 136
Joined: Feb 2009
Nope, the purpose of all that fuss was about doing all from QM without external libraries.
Anyway, i tweaked your code so i could achieve that goal, except that it involves a temporary
file saved to disk, deleted when job's done. I would have loved to do all in memory but
my low skills/QM limitations prevent me to do so.
Anyway, with my high end laptop, it's perfectly bearable and smooth.
Tha day lost in coding and asking for help will save me hours of manual procedures and
is valuable and worthy.
Thanks again for your patience and time Gintaras.
I'll be back soon with new stuff to deal with.....
|