Jump to content

Recommended Posts

Posted

this Code perfectly works in VCL

...
twic:=TWICImage.Create;
twic.LoadFromFile(
'C:\DELPHI\MyStudyProjects\379_UniShowCase\Win32\Debug\UploadFolder\1{9BC6125C-1114-4350-B769-D998BF1D6357}.JPG'
);

Image.Picture.Bitmap.Assign(twic);
...

The same code in UniGUI gives AV on LoadFromFile

twic:=TWICImage.Create;
twic.LoadFromFile(
'C:\DELPHI\MyStudyProjects\379_UniShowCase\Win32\Debug\UploadFolder\1{9BC6125C-1114-4350-B769-D998BF1D6357}.JPG'
);

uniImage1.Picture.Bitmap.Assign(twic);

How to avoid? I like TWIC because it supports a lot of picture formats.

Posted

Ok, changed for

uniimage:=TUniImage.Create(UniApplication);

uniImage.Picture.LoadFromFile(
'C:\DELPHI\MyStudyProjects\379_UniShowCase\Win32\Debug\UploadFolder\1{9BC6125C-1114-4350-B769-D998BF1D6357}.JPG'
);

works perfect but which formats support? I tested with JPG. Where can I see full list of supported formats - is it the same as TImage?

Posted

I diminish pic like this but cannot save it to file. Uniimage doesn't have save methods and uniimage.picture has origin sizes after such diminishing

procedure TDiminishPic.ProportionalDiminishPicSize(
FilePath:string;
var uniimageSource:TUniImage;
var uniimageDest:TUniImage;
maxWidth:Integer;
maxHeight:Integer

);
var
  currentWidth: integer;
  currentHeight: integer;
  koeff: Extended;

begin

// Checks...

if FilePath='' then exit;
if not ( Assigned(uniimageSource) ) or not ( Assigned(uniimageDest) ) then exit;


//Proportional diminishing
uniimageSource.Picture.LoadFromFile(FilePath);


currentWidth:=uniimageSource.Picture.Width;
currentHeight:=uniimageSource.Picture.Height;

if (currentWidth>maxWidth) or (currentHeight>maxHeight) then
koeff:=Min(maxWidth/currentWidth,maxHeight/currentHeight) else
koeff:=1;

if koeff<>1 then

 begin


  uniimageDest.Width:=MaxWidth;
  uniimageDest.Height:=MaxHeight;


  uniimageDest.Proportional:=true;
  uniimageDest.Stretch:=true;
  uniimageDest.Assign(uniimageSource);


 end else

 begin

  uniimageDest.Width:=uniimageSource.Width;
  uniimageDest.Height:=uniimageSource.Height;

  uniimageDest.Assign(uniimageSource);


 end;


end;

if to put uniImageDest on form - it is Ok - image is shown diminished.

 

But how to save diminished picture to file? tuniimage doesn't have SaveToFile method

Posted

Changed code to use GDI+ and all works fine now

uses GDIPOBJ
procedure TDiminishPic.ProportionalDiminishPicSize2
(FilePath:string; maxWidth,maxHeight:Integer; var bmpDest:TBitmap);
 
var uniimage:TUniImage;
  currentWidth: Integer;
  currentHeight: Integer;
  koeff: Extended;
  NewWidth: Integer;
  NewHeight: Integer;
 
 
begin
//
 
 
uniimage:=TUniImage.Create(UniMainModule.UniApplication);
uniimage.Picture.LoadFromFile(FilePath);
 
            currentWidth:=uniimage.Picture.Width;
            currentHeight:=uniimage.Picture.Height;
 
            //Calculating koeff
            if (currentWidth>maxWidth) or (currentHeight>maxHeight) then
            koeff:=Min(maxWidth/currentWidth,maxHeight/currentHeight) else
            koeff:=1;
 
 
 
if koeff<>1 then
 
 begin
 
  NewWidth:=trunc(currentWidth*koeff);
  NewHeight:=Trunc(currentHeight*koeff);
 
 
  LoadAAImageFromFile(FilePath,NewWidth,NewHeight,bmpDest);
 
 
 
 end else
 
LoadAAImageFromFile(FilePath,currentWidth,currentHeight,bmpDest);
 
 end;
procedure TDiminishPic.LoadAAImageFromFile(FileName: String; W,H: Integer; Pic: TBitmap);
var ImageTemp: TGPImage;
graphicsGDIPlus: TGPGraphics;
begin
 
if FileExists(FileName) then
  begin
  Pic.Width:=W;
  Pic.Height:=H;
  graphicsGDIPlus:=TGPGraphics.Create (Pic.Canvas.Handle);
 
  ImageTemp:=TGPImage.Create(FileName ); // Trouble here
 
  graphicsGDIPlus.DrawImage(ImageTemp , 0,0,W,H);
  ImageTemp.Free;
  graphicsGDIPlus.Free;
  end;
end;

Example how to use

...
bmp:=tbitmap.Create;
 
DiminishPic.ProportionalDiminishPicSize2(
'C:\DELPHI\MyStudyProjects\379_UniShowCase\Win32\Debug\UploadFolder\1{32B0316E-82F5-4CD8-B0DA-20451D7AC7F0}.JPG',
128,
128,
bmp
);
 
bmp.SaveToFile('C:\DELPHI\MyStudyProjects\379_UniShowCase\Win32\Debug\UploadFolder\thumbnails\123_thumb.jpg');
...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...