| 
                 wvisser 
                 
                 
                
                Netherlands 
                8 Posts  | 
                
                  
                    
                      
                       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 | 
                     
                   
                 |