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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Copy from Tbitmap does not work
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

dcoun

Greece
11 Posts

Posted - Feb 13 2017 :  03:52:32  Show Profile  Reply
I using the following code to get a Tbitmap image from an other component and save it as PNGimage:

var ima:TImageEnIO; b:tbitmap;
begin
b:=TBitmap.Create; ima:=TImageEnIO.CreateFromBitmap(b); try
ima.IEBitmap.Clear; ima.AsyncMode:=false; ima.IEBitmap.ParamsEnabled:=true;
ima.IEBitmap.Location:=ieTBitmap;
b.Assign('Tbitmap from other image component');
b.SaveToFile('c:\temp\test.bmp');
//ima.Params.PNG_Compression:=8; ima.Params.PNG_Filter:=ioPNG_FILTER_ALL;
ima.IEBitmap.UpdateFromTBitmap; ima.SaveToFilePNG('c:\temp\test0.png');
ima.LoadFromFileBMP('c:\temp\test.bmp'); ima.SaveToFilePNG('c:\temp\test1.png');
finally ima.Free; b.free; end;
end;

Results:
test.bmp is OK
test0.png is cropped, black and white, "dizzy"
test1.png is OK

What is missing from my code, that requires saving and reloading the image as a file?


The following is the test0.png

xequte

38182 Posts

Posted - Feb 13 2017 :  15:49:03  Show Profile  Reply

var 
  ima:TImageEnIO; 
  b:tbitmap;
begin
  b:=TBitmap.Create; 
  ima:=TImageEnIO.CreateFromBitmap(b); 
  try
    ima.IEBitmap.Clear; 
    ima.AsyncMode:=false; 
    ima.IEBitmap.ParamsEnabled:=true;
    ima.IEBitmap.Location:=ieTBitmap;
    b.Assign('Tbitmap from other image component'); 
    b.SaveToFile('c:\temp\test.bmp');
    //ima.Params.PNG_Compression:=8; 
    ima.Params.PNG_Filter:=ioPNG_FILTER_ALL;
    ima.IEBitmap.UpdateFromTBitmap; 
    ima.SaveToFilePNG('c:\temp\test0.png');
    ima.LoadFromFileBMP('c:\temp\test.bmp'); 
    ima.SaveToFilePNG('c:\temp\test1.png');
  finally 
    ima.Free; 
    b.free; 
  end;
end;


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

xequte

38182 Posts

Posted - Feb 13 2017 :  15:55:56  Show Profile  Reply
Hi

How about if you use:

var 
  ima: TImageEnIO; 
begin
  ima:=TImageEnIO.Create(nil); 
  try
    ima.IEBitmap.Assign('Tbitmap from other image component'); 
    ima.Params.PNG_Filter:=ioPNG_FILTER_ALL;
    ima.SaveToFilePNG('c:\temp\test0.png');
  finally 
    ima.Free; 
  end;
end;

Note: Don't set ima.IEBitmap.ParamsEnabled:=true; unless you want to use the params of IEBitmap (instead of params of ima)

Or:

var 
  b: TIEBitmap;
begin
  b := TIEBitmap.Create(); 
  try
    b.Params.Enabled
    b.Assign('Tbitmap from other image component'); 
    b.Params.PNG_Filter:=ioPNG_FILTER_ALL;
    b.Write('c:\temp\test0.png');
  finally 
    b.Free; 
  end;
end;


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

dcoun

Greece
11 Posts

Posted - Feb 16 2017 :  06:16:53  Show Profile  Reply
Thank you for your response.
The first solution resulted in a "wave" like coloured image in the same unreadable way. The second gives the same black&width image.
I trying to lock canvas also, but it did not work.
The following memory consuming code works OK: (I do not know why)

var 
  ima:TImageEnIO; 
  b:tbitmap;
  im:Tmemorystream;
begin
  im:=TMemoryStream.Create;
  ima:=TImageEnIO.Create(nil); 
  try
    ima.Params.PNG_Filter:=ioPNG_FILTER_ALL;
    b:=('Tbitmap from other image component'); 
    b.SaveTostream(im);
    b.free;
    im.position:=0;
    ima.LoadFromstreamBMP(im); 
    ima.SaveToFilePNG('c:\temp\test1.png');
  finally 
    ima.Free; 
    im.free; 
  end;
end;
Go to Top of Page

xequte

38182 Posts

Posted - Feb 16 2017 :  15:31:12  Show Profile  Reply
There is something unexpected about your source image, can you advise the properties of the "Tbitmap from other image component"? Particularly, PixelFormat, AlphaFormat and HandleType?

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

dcoun

Greece
11 Posts

Posted - Feb 16 2017 :  18:07:39  Show Profile  Reply
Component = Gnostice's PDFtoolkit

PixelFormat = pf32bit;
AlphaFormat = afIgnored;
HandleType = bmDIB;
Go to Top of Page

xequte

38182 Posts

Posted - Feb 22 2017 :  14:53:34  Show Profile  Reply
Hi

What version of ImageEn are you using? V6.3.2?



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

dcoun

Greece
11 Posts

Posted - Feb 23 2017 :  01:09:49  Show Profile  Reply
Yes, v6.3.2
Go to Top of Page

xequte

38182 Posts

Posted - Feb 23 2017 :  19:49:00  Show Profile  Reply
Hi

I'm afraid I cannot reproduce that, nor can I see any reason 32bit BMP's should not process.

Try making a simple demo that does not require any third party libraries or code.

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

dcoun

Greece
11 Posts

Posted - Mar 06 2017 :  02:03:59  Show Profile  Reply
I apologize for the delay. The following code works:

procedure TForm1.Button1Click(Sender: TObject);
var t:TgtPDFDocument; b:tbitmap; ima:TImageEnIO;
begin t:=TgtPDFDocument.Create(nil);
ima:=TImageEnIO.Create(nil); try
if not t.LoadFromFile('c:\temp\6thNL Final.pdf') then exit;
b:=t.GetBitmap(1,200,200);
b.PixelFormat:=pf24bit;
ima.IEBitmap.Assign(b); ima.Params.PNG_Filter:=ioPNG_FILTER_ALL;
ima.SaveToFilePNG('c:\temp\test.png'); finally ima.free; b.Free; t.Free; end;
end;

BUT the following DOES NOT work and gives similar image like the attached in the first post:

procedure TForm1.Button1Click(Sender: TObject);
var t:TgtPDFDocument; b:tbitmap; ima:TImageEnIO;
begin t:=TgtPDFDocument.Create(nil);
ima:=TImageEnIO.Create(nil); try
if not t.LoadFromFile('c:\temp\6thNL Final.pdf') then exit;
b:=t.GetBitmap(1,200,200);
b.PixelFormat:=pf24bit;
b.PixelFormat:=pf32bit;
ima.IEBitmap.Assign(b); ima.Params.PNG_Filter:=ioPNG_FILTER_ALL;
ima.SaveToFilePNG('c:\temp\test.png'); finally ima.free; b.Free; t.Free; end;
end;


I am using Delphi 10.1 Berlin
Go to Top of Page

xequte

38182 Posts

Posted - Mar 07 2017 :  22:44:56  Show Profile  Reply
Wow, your code is very hard to read. Is your "Enter" key broken?

We don't have TgtPDFDocument so cannot test this.





Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

dcoun

Greece
11 Posts

Posted - Mar 08 2017 :  03:04:02  Show Profile  Reply
concerning Enter, just different way our mind works. all our fingers have not the same length.
Concerning our subject, will an executable with the above code could help you?
(select pdf file, save to png file)
Go to Top of Page

xequte

38182 Posts

Posted - Mar 08 2017 :  19:13:48  Show Profile  Reply
Sorry, I need some source code that reproduces the issue without requiring any third party libraries.



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: