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
 IEvolution: GetNetImage and transparency

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
andrejzr Posted - Sep 02 2014 : 04:22:09
I am using GetNetImage call to get a System.Drawing.Image from IEImage (IEvolution).

If the loaded image is PNG with transparency, the resulting Image does not contain Alpha Channel.

Looking at the Format of the IEImage, it is ie24RBG. So it makes sense. But setting it to ie32RGB and then calling SynchronizeRGBA (like suggested in another post) does not work. After setting the Format to ie32RGB, the format is still 24 bit, and calling SynchronizeRGBA after that causes Access violation.

Workarround is to save IEImage to memory stream and load Image from the same stream. But I am afraid that this would affect the performance.

Do you have any other hints how to get a .NET image with alpha channel?

Thanks
Andrej
1   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Sep 15 2014 : 22:46:36
The current version of IEvolution cannot transfer transparency to .net Image object.

You can try the following workaround:

ieViewer1.Image.LoadImage(“test.png");
pictureBox1.Image = CreateImageWithTransparency(ieViewer1.Image);

Where CreateImageWithTransparency is defined as:

    public static Image CreateImageWithTransparency(IEImage image)
    {
      const int bytesPerPixel = 4;
      Image originalImage = image.GetNetImage();
      if ((originalImage.PixelFormat & PixelFormat.Indexed) == PixelFormat.Indexed)
      {
        return originalImage;
      }
      Bitmap bmp = new Bitmap(originalImage);
      PixelFormat pxf = PixelFormat.Format32bppArgb;
      Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
      BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite, pxf);
      IntPtr ptr = bmpData.Scan0;
      int numBytes = bmp.Width * bmp.Height * bytesPerPixel;
      byte[] argbValues = new byte[numBytes];
      System.Runtime.InteropServices.Marshal.Copy(ptr, argbValues, 0, numBytes);
      for (int counter = 0, x = 0, y = 0; counter < argbValues.Length; counter += bytesPerPixel)
      {
        int pos = 0;
        pos++; // B value
        pos++; // G value
        pos++; // R value
        argbValues[counter + pos] = (byte)image.GetAlpha(x, y);
        if (++x == bmp.Width)
        {
          x = 0;
          ++y;
        }
      }
      System.Runtime.InteropServices.Marshal.Copy(argbValues, 0, ptr, numBytes);
      bmp.UnlockBits(bmpData);
      return bmp;
    }


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com