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
 Grayscale Tif
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

Sam

21 Posts

Posted - Jan 15 2013 :  03:43:57  Show Profile  Reply
Hi, I try to load 1 bit (grayscale) Tif-Pictures. But the colors are not right after loading it (white is black or orange and black is blue or red...).
How can I load the picture correctly?

Thank you!

Sam

21 Posts

Posted - Jan 16 2013 :  10:15:40  Show Profile  Reply
Hi, can someone please check this Delphi example:

http://www.file-upload.net/download-7066983/ImageEn_1bit_tif.zip.html

When I load the 1Bit Tiff (pictures included in example), the colors are not right! What is wrong?

Thanks for helping!
Go to Top of Page

fab

1310 Posts

Posted - Jan 16 2013 :  10:46:48  Show Profile  Reply
Sorry, but I cannot replicate. Here is my screenshot:




I recompiled your application with the latest version.
Go to Top of Page

Sam

21 Posts

Posted - Jan 17 2013 :  06:41:38  Show Profile  Reply
Hi,

now, I re-installed the ImageEn components. But there is still the same error!
With an older version of ImageEn, it works without problems, but not with 4.1.4 (ImageEn_4.1.4_77293b_Setup.exe). We use Delphi 5.
You can download the compiled EXE file of the project (with Delphi 5) here:

http://www.file-upload.net/download-7070714/Project1.zip.html

Is this working on your computer correctly?
It seems, that there may be a bug for Delphi 5???

Thank you again...
Go to Top of Page

Sam

21 Posts

Posted - Jan 20 2013 :  15:28:41  Show Profile  Reply
No Idea?
Go to Top of Page

Sam

21 Posts

Posted - Jan 22 2013 :  03:28:05  Show Profile  Reply
Hi, Iīm now waiting since 5 days for an answer! Sorry, but this is not a good support!
Can you please just check the EXE-File, that I uploaded???
I have to use the old version of ImageEn, because the new version doesnīt work for me!
Go to Top of Page

fab

1310 Posts

Posted - Jan 22 2013 :  09:26:25  Show Profile  Reply
I'm sorry, I cannot check exe files.
However, actually now I can replicate with Delphi 5. Please wait for a solution.

Anyway let's to say that this is not strictly an ImageEn question. ImageEn correctly loads the images. The problem stays where you paint the ImageEn loaded image to a TImage (or anyway in an another canvas).

Thanks for your patience.
Go to Top of Page

fab

1310 Posts

Posted - Jan 22 2013 :  09:55:38  Show Profile  Reply
I cannot explain because this happens on Delphi 5 (maybe a bug of that Delphi version). However you can render a 24 bit bitmap instead of 1 bit, in this case it seems to work (look at also to "fixed" remarks):

  ImageEx := TImageEnView.Create(nil);  // fixed: nil instead of self

  if ( OpenImageEnDialog1.Execute ) then
  begin
    Screen.Cursor := crHourglass;

    ImageEx.IO.LoadFromFile(OpenImageEnDialog1.FileName);

    ImageEx.IEBitmap.PixelFormat := ie24RGB;     <<< add this

    SetStretchBltMode(im.Canvas.Handle, HALFTONE);
    StretchBlt(im.Canvas.Handle,0,0,im.Width,im.Height,ImageEx.Bitmap.canvas.Handle,0,0,ImageEx.Bitmap.Width,ImageEx.Bitmap.Height,SRCCOPY);

    Screen.Cursor := crArrow;
  end;

  ImageEx.Free; // fixed
Go to Top of Page

Sam

21 Posts

Posted - Jan 23 2013 :  03:42:55  Show Profile  Reply
Hi Fabrizio,

thank you for your answer!

But this solution has a big disadvantage for us:
We have to keep the pictures in memory and we have got big 1 bit images (15000x10000 pixels). If I use your solution, the memory is full after some pictures, because the memory usage increases dramatically with 24 bit. So, we canīt use it this way!

I donīt know, if itīs really a Delphi-Problem, because with the old version of ImageEn, it works correctly!

Do you have another solution?

Thank you!
Go to Top of Page

fab

1310 Posts

Posted - Jan 25 2013 :  00:35:38  Show Profile  Reply
quote:
I donīt know, if itīs really a Delphi-Problem, because with the old version of ImageEn, it works correctly!


Which ImageEn version does work?

quote:
Do you have another solution?


Unfortunately no.
You have only a display context (HDC) where to render the image, is it right?
Have you tried other functions like, ImageEnView.IEBItmap.RenderToCanvas?
Go to Top of Page

Sam

21 Posts

Posted - Jan 28 2013 :  05:50:09  Show Profile  Reply
Hi Fabrizio,

I donīt know the version, but it was a very old version of ImageEn. From 2004, I think.

Yes, Iīve got only the HDC.

With IEBitmap.RenderToCanvas, it works correct, but this function is really slow, so not a really good replacement...
Go to Top of Page

Sam

21 Posts

Posted - Jan 28 2013 :  09:30:01  Show Profile  Reply
I wonder, why "RenderToCanvas" is especially so slow, when zooming into an image (with no active filter, rfNone)??
Go to Top of Page

fab

1310 Posts

Posted - Jan 29 2013 :  23:29:20  Show Profile  Reply
RenderToCanvas is designed for printing. Leaving out all printing related code results to the below code, please try it:

procedure _DIBDrawTo(DestCanvas: TCanvas; fhdib: THANDLE; orgx, orgy, orgdx, orgdy, destx, desty, destdx, destdy: integer);
var
  bminfo: ^TBITMAPINFO;
begin
  bminfo := GlobalLock(fhdib);
  SetStretchBltMode(destcanvas.handle, COLORONCOLOR);
  if bminfo^.bmiHeader.biBitCount <= 8 then
    // <=256 colors
    StretchDIBits(destcanvas.Handle, destx, desty, destdx, destdy, orgx, orgy, orgdx, orgdy,
      pointer(cardinal(bminfo) + sizeof(TBITMAPINFOHEADER) + (1 shl bminfo^.bmiHeader.biBitCount) * 4),
      bminfo^, DIB_RGB_COLORS, SRCCOPY)
  else
    // >256 colors
    StretchDIBits(destcanvas.Handle, destx, desty, destdx, destdy, orgx, orgy, orgdx, orgdy,
      pointer(cardinal(bminfo) + sizeof(TBITMAPINFOHEADER)),
      bminfo^, DIB_RGB_COLORS, SRCCOPY);
  GlobalUnLock(fhdib);
end;

procedure PrintPict(DestCanvas: TCanvas; x, y: integer; const Bitmap: TIEBitmap; srcx, srcy, srcdx, srcdy: integer);
var
  hdib: THandle;
begin
  hdib := _CopyBitmaptoDIBEx(Bitmap, srcx, srcy, srcx + srcdx, srcy + srcdy,200,200);
  _DIBDrawTo(DestCanvas, hdib, 0, 0, srcdx, srcdy, x, y, srcdx, srcdy);
  GlobalFree(hdib);
end;


However this could result still slow, because the creation of a temporary DIB.
Go to Top of Page

Sam

21 Posts

Posted - Jan 30 2013 :  04:02:43  Show Profile  Reply
Hi Fabrizio,

this code is exactly the code, which is already in hyieutils.pas. Whatīs the difference??

When showing the whole picture, RenderToCanvas is fast, but when zooming in, it getīs slower and slower (depends on zoom level).
Go to Top of Page

fab

1310 Posts

Posted - Jan 30 2013 :  04:35:40  Show Profile  Reply
I cut-off all RenderToCanvas printing related code.
How do you zoom?
Go to Top of Page

Sam

21 Posts

Posted - Jan 30 2013 :  05:59:13  Show Profile  Reply
But itīs the same code, which was already there in hyieutils.pas. Hm, strange...

I just use:

myBitmap.RenderToCanvas(myCanvas, ax1, ay1, ax2, ay2, rfNone, 0);

to copy the Bitmap to the canvas. When ax and ay represent only a small area of the bitmap (this is the zoom level, I meant), RenderToCanvas is very slow. If ax and ay have values, which renders the whole image to the canvas and not only a small area of the image, it is really fast...
Go to Top of Page

Sam

21 Posts

Posted - Jan 31 2013 :  04:18:47  Show Profile  Reply
Itīs much faster, when I change the _DIBDrawTo-Method in hyieutils.pas (just a quick test):

// draw an hdib in a canvas
procedure _DIBDrawTo(DestCanvas: TCanvas; fhdib: THANDLE; orgx, orgy, orgdx, orgdy, destx, desty, destdx, destdy: integer);
var
  bminfo: ^TBITMAPINFO;
begin
  bminfo := GlobalLock(fhdib);
  if ((destdx - destx) < bminfo^.bmiHeader.biWidth / 2) and ((destdy - desty) < bminfo^.bmiHeader.biHeight / 2) then
    SetStretchBltMode(destcanvas.handle, COLORONCOLOR)
  else
    SetStretchBltMode(destcanvas.handle, HALFTONE);
   ...
end;

Do you know, if this has some disadvantages?
I have got better image quality and itīs faster when zooming in with "HALFTONE".

Thank you!
Go to Top of Page

fab

1310 Posts

Posted - Feb 01 2013 :  02:40:58  Show Profile  Reply
Do not change the routine in hyieutils.pas, but extract these functions renaming them. This because they are used by other parts of ImageEn.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: