ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Maintaining aspect ratio when Pasting a bitmap

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
wvisser Posted - Dec 27 2011 : 11:40:11
Hello,

I have a suggestion to extend the functionality of SelPasteFromClip with functionality to make sure aspect ratio of the pasted bitmap is maintained regardless of the area selected by the user.

Can this be somehow added in a next version using an extra switch or something?

see code below for an adapted version of SelPasteFromClip that does this :

regards, Wilfried

procedure TImageEnProc.SelPasteFromClip_WV(MergeAlpha:boolean);
var
pabitmap, pbBitmap: TIEBitmap;
fSX1, fSY1, fSX2, fSY2: integer;
fPolyS: PPointArray;
fPolySCount: integer;
hbi: THandle;
mask: TIEMask;
memPtr:pointer;
pa_aratio, pb_aratio : Double;
begin
if not MakeConsistentBitmap([]) then
exit;
if GetReSel(fsx1, fsy1, fsx2, fsy2, fPolyS, fPolySCount, mask) then
begin
if IEOpenClipboard then
begin

try

if IsClipboardFormatAvailable(IERAWCLIPFORMAT) then
begin
// internal format
hbi := GetClipboardData(IERAWCLIPFORMAT);
if hbi <> 0 then
begin
pabitmap := TIEBitmap.create;
if fAutoUndo then
SaveUndoCaptioned(IERS_SELPASTEFROMCLIP, ieuImage);
memPtr:=GlobalLock(hbi);
pabitmap.LoadRAWFromBufferOrStream(memPtr,nil);
GlobalUnLock(hbi);
pbBitmap := TIEBitmap.Create;

if pabitmap.Height>0 then
begin
pa_aratio:=pabitmap.Width/pabitmap.Height;
if (fsy2 - fsy1)>0 then pb_aratio:=(fsx2 - fsx1)/(fsy2 - fsy1)
else pb_aratio:=0;
if pa_aratio>pb_aratio then // reduce selection height to correct pb_aratio to pa_aratio
fsy2:=Round((fsx2 - fsx1)/pa_aratio + fsy1)
else // reduce selection width to correct pb_aratio to pa_aratio
fsx2:=Round((fsy2 - fsy1)*pa_aratio + fsx1);
end;

pbBitmap.Allocate(fsx2 - fsx1, fsy2 - fsy1, paBitmap.PixelFormat);
_IEBmpStretchEx(paBitmap, pbBitmap, nil, nil);
if paBitmap.HasAlphaChannel then
begin
_IEBmpStretchEx(paBitmap.AlphaChannel, pbBitmap.AlphaChannel, nil, nil);
if MergeAlpha then
mask.CombineWithAlpha(pbBitmap.AlphaChannel,mask.x1,mask.y1,false);
end;
pbBitmap.CopyWithMask2(fIEBitmap,mask);
FreeAndNil(pbBitmap);
FreeAndNil(pabitmap);
Update;
end;
end

// DIB format
else if IsClipboardFormatAvailable(CF_DIB) then
begin
hbi := GetClipboardData(CF_DIB);
if hbi <> 0 then
begin
pabitmap := TIEBitmap.create;
if fAutoUndo then
SaveUndoCaptioned(IERS_SELPASTEFROMCLIP, ieuImage);
_CopyDIB2BitmapEx(hbi, paBitmap, nil, false);
pbBitmap := TIEBitmap.Create;
pbBitmap.Allocate(fsx2 - fsx1, fsy2 - fsy1, paBitmap.PixelFormat);
_IEBmpStretchEx(paBitmap, pbBitmap, nil, nil);
mask.CopyIEBitmap(fIEBitmap, pbBitmap, false, true, false);
FreeAndNil(pbBitmap);
FreeAndNil(pabitmap);
Update;
end;
end;

finally
CloseClipboard;
end;
end;
end
else
PasteFromClipboard;
end;


wpjvisser
1   L A T E S T    R E P L I E S    (Newest First)
fab Posted - Dec 29 2011 : 09:17:05
Thank you,
next minor release (I can send you a preview if you like) will have an optional parameter in TImageEnProc.SelPasteFromClip to enable maintaing aspect ratio.