Author Topic: transparent MNG  (Read 5161 times)

Robert

  • Guest
transparent MNG
« on: 21 May 2008, 18:32:58 »
Hi,

I'm trying to display an MNG. Putting it on screen is easy, but even though TMultiImage.FormatInfo.HasAlphaChannel is true the image has a black backdrop, not the image I put below this down. What else shall I do to remedy this problem?
Another question is whether this library handles animations or do I have to implement the playback by displaying the different images in the TMultiImage component?

Thanks,
Robert.

Robert

  • Guest
Re: transparent MNG
« Reply #1 on: 21 May 2008, 23:46:13 »
Got transparency, it was a stupid mistake on my part. Alas, alpha doesn't really work well, the edges of the object are very rugged and pixelated. As if the alpha channel would be only 1 bit.

Any ideas?

Thanks

Offline Galfar

  • Administrator
  • Imaging User
  • *****
  • Posts: 357
    • View Profile
    • Galfar's Homepage
Re: transparent MNG
« Reply #2 on: 25 May 2008, 17:13:38 »
Animation:
Imaging just loads all frames from MNG file, application must do the playback.

Alpha:
Is this is a problem with all MNG images?
Maybe those MNGs have lossy JPEG-compressed alpha channel which could
produce ugly results.
Attach some of the problematic MNGs here or post some more info please.



Offline robert

  • Imaging User
  • *
  • Posts: 4
    • View Profile
Re: transparent MNG
« Reply #3 on: 27 May 2008, 20:36:13 »
Hi!

The problem is consistent with all MNG frames and animations.
I don't think it's a problem with jpeg-compression, PNGs are used for the anim.

I attached a simple 2 frame animation.

Thanks for the help.

Offline Galfar

  • Administrator
  • Imaging User
  • *****
  • Posts: 357
    • View Profile
    • Galfar's Homepage
Re: transparent MNG
« Reply #4 on: 31 May 2008, 01:26:12 »
I've checked your anim and there's no problem with alpha channel loading.

But maybe there's problem with display. Are you sure you are displaying
images with proper alpha blending?

Attached image 1 is your anim with proper blending, image 2 is
pixelated 1bit alpha look you probably described. Is that correct?

Offline robert

  • Imaging User
  • *
  • Posts: 4
    • View Profile
Re: transparent MNG
« Reply #5 on: 31 May 2008, 05:02:34 »
Thanks for your help.

To answer the question, yes image1.png is perfect, while image2.png is the version I could display.

Where did I go wrong? How could I display the same image as image1.png?

Offline Galfar

  • Administrator
  • Imaging User
  • *****
  • Posts: 357
    • View Profile
    • Galfar's Homepage
Re: transparent MNG
« Reply #6 on: 31 May 2008, 10:49:38 »
Well, how do you display it now?

Offline robert

  • Imaging User
  • *
  • Posts: 4
    • View Profile
Re: transparent MNG
« Reply #7 on: 31 May 2008, 19:34:49 »
That's all, taken from your example.

//-----------
  FFileName := 'c:\a3.mng';
  FImage := TMultiImage.Create;
  FBitmap := TImagingBitmap.Create;
  Image.Picture.Graphic := FBitmap;
  try
    FImage.LoadMultiFromFile(FFileName);
  except
    FImage.CreateFromParams(32, 32, ifA8R8G8B8, 1);
    MessageDlg('Error when loading file: ' + FFileName, mtError, [mbOK], 0);
  end;
  FImage.ActiveImage := 0;

  Image.Picture.Graphic.Assign(FImage);
//------------

Offline Galfar

  • Administrator
  • Imaging User
  • *****
  • Posts: 357
    • View Profile
    • Galfar's Homepage
Re: transparent MNG
« Reply #8 on: 5 June 2008, 12:12:22 »
This won't give you alpha blending. You convert Imaging image to TBitmap but
this bitmap is displayed by VCL.
VCL uses StretchBlt WinAPI function, you need to use
AlphaBlend WinAPI function to get the correct results or write your own blending code.

There's some AlphaBlend Delphi usage info:
http://users.telenet.be/ws36637/transparent3.html

Offline robert

  • Imaging User
  • *
  • Posts: 4
    • View Profile
Re: transparent MNG
« Reply #9 on: 11 June 2008, 17:48:48 »
I really tried to make it work, but I have a problem.

To be able to display the image with the AlphaBlend API function or to use the function which is on the link you sent, I'd need to have an HDC to the image. This one I don't how to obtain for the current image in the TMultiImage object. Since speed is an issue for me I'd really like to have some streamlined solution and not converting the image back and forth between formats. Since you're the most familiar with the library I'd like to ask your opinion on this.

I'd appreciate any help.

Thanks.

Offline Galfar

  • Administrator
  • Imaging User
  • *****
  • Posts: 357
    • View Profile
    • Galfar's Homepage
Re: transparent MNG
« Reply #10 on: 12 June 2008, 23:03:15 »
Just convert TMultiImage to TImagingBitmap like you did in the code you posted earlier.
TImagingBitmap is descendant of standard VCL TBitmap and its Handle property is
just the HDC you need. Destination HDC would be the Handle of TImage of TForm components or
wherever you want to draw.