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
 Wrong Color after AppenImage from IEBitmap

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
Ralf Posted - Apr 21 2017 : 05:19:30
Hi,

when i insert a IEBitMap in an ImageEnMView with ImageEnMView_AppendImage(ThumbIEMV,IEBitMap) the SamplesPerPixel and BitsPerSample become the wrong Values.

The Pixelformat of the IEBitMap is ie1g (Black and White). The SamplePerPixel then is 3 and the BitsperSample is 8. I thought both must be 1. Or is there any other way to see what color the image is?

Thanks
Ralf
11   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - May 11 2017 : 19:11:46
Hi

Further to Bill's comments, when pasting in ImageEn, you are always pasting into an existing image, so the image is not changed to match what is pasted. Rather, as you would expect when adding to existing content, the pasted image is adjusted, if needed.

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
w2m Posted - May 11 2017 : 09:52:40
<blockquote id="quote"><font size="1" face="Arial, Helvetica" id="quote"> <hr height="1" noshade id="quote">Do i understood it right?
If the Image in the Clipboard is 24 bit it should be 24 bit after Pastefromclipboard
If it is Black and white is should be monochrome..[/quote]

No! All colored images will be 24-bit.

Read the help file PasteFromClipboard. ImageEn does not support automatic conversion because all colored images in the clipboard will be pasted as 24-bit so you have to ask what bit depth to convert to and do the conversion in code after the paste. ImageEn does not support what you want to do automatically.

If ImageEn does not show the image as monochrome 1-bit after a paste and the clipboard image is indeed 1-bit then the help file is incorrect:
PasteFromClipboard
Color images of 4, 8, 15, 16, 24 or 32 bits are converted to 24 bit. Monochrome images (1 bit) will remain 1 bit.

By default, ImageEn converts all paletted images to 24 bit (true color). Only black/white images are stored in the original format with 1 bit per pixel.
Setting NativePixelFormat to True disables the conversion and uses the image's native format.

Note: LegacyBitmap must be False to enable NativePixelFormat. Also, use of NativePixelFormat will prevent execution of some image processing operations.

This may solve your problem:
ImageEnView1.LegacyBitmap := False; // Do not use TBitmap
ImageEnView1.IO.NativePixelFormat := True; // Use the original pixel format

As far as io24RGB all images are usually io24RGB which has nothing to do with bitdepth. Even 1-bit images will be io24RGB when loaded from a file or pasted from the clipboard.

The TIEPixelFormat may provide you with more information:
iePixelFormat := ImageEnView.IEBitmap.PixelFormat;
  case iePixelFormat of
  ie1g:  MessageBox(0, 'Gray scale (black/white)', 'PixelFormat', MB_ICONINFORMATION or MB_OK);
  ie8p:  MessageBox(0, 'Color pallet', 'PixelFormat', MB_ICONINFORMATION or MB_OK);
  ie8g:  MessageBox(0, 'Gray scale (256 levels)', 'PixelFormat', MB_ICONINFORMATION or MB_OK);
  ie16g: MessageBox(0, 'Gray scale (65536 levels)', 'PixelFormat', MB_ICONINFORMATION or MB_OK);
  ie24RGB: MessageBox(0, 'RGB 24 bit (8 bit per channel)', 'PixelFormat', MB_ICONINFORMATION or MB_OK);
  ie32f: MessageBox(0, 'Floating point values, 32 bit - Single in Pascal - gray scale', 'PixelFormat', MB_ICONINFORMATION or MB_OK);
  ieCMYK: MessageBox(0, 'CMYK (reversed 8 bit values)', 'PixelFormat', MB_ICONINFORMATION or MB_OK);
  ie48RGB: MessageBox(0, 'RGB 48 bit (16 bit per channel)', 'PixelFormat', MB_ICONINFORMATION or MB_OK);
  ieCIELab: MessageBox(0, 'CIELab (8 bit per channel)', 'PixelFormat', MB_ICONINFORMATION or MB_OK);
  ie32RGB:  MessageBox(0, ' RGB 32 bit (8 bit per channel), last 8 bit are unused with some exceptions', 'PixelFormat', MB_ICONINFORMATION or MB_OK); //
end;

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Ralf Posted - May 11 2017 : 09:44:44
Hi Bill,

do i understood it right?
If the Image in the Clipboard is 24 bit it should be 24 bit after Pastefromclipboard.
If it is Black and white is should be monochrome.

I made a screenshot and this ieBitmap says io24RGB after Pastefromclipboard the BitsperSample was 1 and also the Samplesperpixel.

We don't want to convert we only want that the insert image has the color the Image in the clipboard has.

Regards
Ralf
w2m Posted - May 11 2017 : 09:35:08
You will have to ask the user to convert from 24-bit to the desired bit depth. If the clipboard contains a colored image the image will be 24-bit after the paste. If the clipboard contains a 1-bit image the pasted image should be 1-bit after the paste. If the clipboard image is not 1-bit and you want the image to be a different bit depth, the ask the user what the bit depth should be and convert the image accordingly. There are a number of procedures to convert from 24-bit to 1-bit.

One way to do this:
procedure TForm1.ConvertTo1Bit;
begin
  if Assigned(PageControl1.ActivePage) then
  begin
    ImageEnView := TImageEnView(PageControl1.ActivePage.Controls[0]);
    if Assigned(ImageEnView) then
    begin
      ImageEnView.Proc.SaveUndo('Convert to 1-Bit ' + IntToStr(ImageEnView.Proc.UndoCount));
      Undo1.Hint := ImageEnView.Proc.UndoCaptions[0];
      Undo1.Enabled := ImageEnView.Proc.CanUndo;
      ImageEnView.RemoveAlphaChannel();
      ImageEnView.Proc.ConvertToBW_FloydSteinberg;
      ImageEnView.IO.Params.BitsPerSample := 1;
      ImageEnView.IO.Params.SamplesPerPixel := 1;
      ImageEnView.IEBitmap.Modified := True;
      ImageEnView.BackgroundStyle := iebsSolid;
      ImageEnView.Update;
      ImageEnMView1.SetIEBitmapEx(ImageEnMView1.SelectedImage, ImageEnView.IEBitmap);
      ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].BitsPerSample := 1;
      ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].SamplesPerPixel := 1;
      ImageEnMView1.Update;
    end;
  end;
end;

Other conversions include:
procedure TForm1.ConvertTo4Bit;
begin
  if Assigned(PageControl1.ActivePage) then
  begin
    ImageEnView := TImageEnView(PageControl1.ActivePage.Controls[0]);
    if Assigned(ImageEnView) then
    begin
      ImageEnView.Proc.SaveUndo('Convert to 4-Bit ' + IntToStr(ImageEnView.Proc.UndoCount));
      Undo1.Hint := ImageEnView.Proc.UndoCaptions[0];
      Undo1.Enabled := ImageEnView.Proc.CanUndo;
      ImageEnView.RemoveAlphaChannel();
      ImageEnView.Proc.ConvertTo(16);
      ImageEnView.IO.Params.BitsPerSample := 4;
      ImageEnView.IO.Params.SamplesPerPixel := 1;
      ImageEnView.IEBitmap.Modified := True;
      ImageEnView.BackgroundStyle := iebsSolid;
      ImageEnView.Update;
      ImageEnMView1.SetIEBitmapEx(ImageEnMView1.SelectedImage, ImageEnView.IEBitmap);
      ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].BitsPerSample := 4;
      ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].SamplesPerPixel := 1;
      ImageEnMView1.Update;
    end;
  end;
end;
procedure TForm1.ConvertTo8Bit;
begin
  if Assigned(PageControl1.ActivePage) then
  begin
    ImageEnView := TImageEnView(PageControl1.ActivePage.Controls[0]);
    if Assigned(ImageEnView) then
    begin
      ImageEnView.Proc.SaveUndo('Convert to 8-Bit ' + IntToStr(ImageEnView.Proc.UndoCount));
      Undo1.Hint := ImageEnView.Proc.UndoCaptions[0];
      Undo1.Enabled := ImageEnView.Proc.CanUndo;
      ImageEnView.RemoveAlphaChannel();
      ImageEnView.Proc.ConvertTo(256);
      ImageEnView.IO.Params.BitsPerSample := 8;
      ImageEnView.IO.Params.SamplesPerPixel := 1;
      ImageEnView.BackgroundStyle := iebsSolid;
      ImageEnView.Update;
      ImageEnView.IEBitmap.Modified := True;
      ImageEnMView1.SetIEBitmapEx(ImageEnMView1.SelectedImage, ImageEnView.IEBitmap);
      ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].BitsPerSample := 8;
      ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].SamplesPerPixel := 1;
      ImageEnMView1.Update;
    end;
  end;
end;

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Ralf Posted - May 11 2017 : 08:03:50
Hi Bill,

i now make it
IEPixelFormatToBPSAndSPP( PixelFormat, iBitsPerSample, iSamplesPerPixel );
BitsPerSample :=iBitsperSample;
SamplesPerPixel:=iSamplesPerPixel;
I don't know why the PastefromClipboard have no parameter to say how i want to get the image and do a convert to monochrome.

Thanks
Ralf
w2m Posted - May 11 2017 : 07:32:20
When pasting from the clipboard ImageEn is designed to convert color images of 4, 8, 15, 16, 24 or 32 bits to 24 bit. Monochrome images (1 bit) will remain 1 bit. See the help file. After you paste just set the ImageEnView.IO.Params.BitsPerSample := 8 and ImageEnView.IO.Params.SamplesPerPixel to 3.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Ralf Posted - May 11 2017 : 06:58:17
Hi Bill,

sorry but i must come back to my problem!
I do
ImageEnView.Proc.PasteFromClipboard;
The Picture in the Clipboard is Color
When i look in the
ImageEnView.IEBitmap.PixelFormat then it is ie24RGB.
My Problem is, that the ImageEnView.IO.Params.BitsPerSample and ImageEnView.IO.Params.SamplesPerPixel is still 1.
That's really Bad.
I Think by doing PasteFromClipboard also the BitsperSample and SamplesPerPixel should be set to the correct values.

Ralf
Ralf Posted - May 01 2017 : 11:27:31
Hi Bill,
i have implement your idears and it work.
Thanks
Ralf
w2m Posted - Apr 26 2017 : 08:09:07
If the IO.Params are correct in your stream you could also try
TImageEnIO.ParamsFromStream

Declaration
function ParamsFromStream(Stream: TStream; Format: TIOFileType = ioUnknown): Boolean;

Description

Reads the image properties without loading the image (and without changing the current image). Result is false if a loading error is encountered due to a corrupt or unknown image format.

Stream is a TStream that contains the image.
Format is the file format that the stream or file contains. If ioUnknown is specified then the file content is analyzed to determine the format.

 
The Pixeltype of IENIO.BitMap is ie1g (Black and White).

You should use IO.Params.BitsPerSample * IO.Params.SamplesPerPixel and not the PixelType.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Ralf Posted - Apr 26 2017 : 03:03:17
Hallo Bill,

sorry for my late feedback and thanks for your help.
I do following to get an IEBitMap:
IENIO:=TImageEnIO.create(nil);
IENIO.LoadFromStream(ImageStream);
ImageEnMView_AppendImage(ThumbIEMV,IENIO.IEBitmap);

The Pixeltype of IENIO.BitMap is ie1g (Black and White). I think that then the ImageEnMView_AppenImage should set the new/insert Image to Black and White.

I will test your idear to Assign the BitsperSample and SamplePerPixel.

Thanks
Ralf


w2m Posted - Apr 21 2017 : 10:29:12
You can get the color of the IEBitmap from the IO.Params.BitsPerSample and IO.Params.SamplesPerPixel where the bitdepth or color is calculated by
IO.Params.BitsPerSample * IO.Params.SamplesPerPixel.

The key to this is how did you put the image into IEBitmap?
Did you load it into IEBitmap from a file?

Generally for this to work correctly the IO.Params should be assigned to MIO.Params[Index].Assign(IO.Params) or specifically MIO.Params[Index].BitsPerSample.Assign(IO.Params.BitsPerSample) and MIO.Params[Index].SamplesPerPixel.Assign(IO.Params.SamplesPerPixel).

This is because the IO.Params are not assigned when AppendImage is used.

You did not show the code you are using to determine how the IEBitmap was loaded. If you are working with two TImageEnMView then assign the MIO.Params[Index] from the source to the destination MIO.Params[Index]:

ImageEnMView2.AppendImage...
ImageEnMView2.MIO.Params[ImageEnMView2.SelectedImage].Assign(ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage]);

If you provide the actual code you are using I can be more helpful.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development