• Welcome to Vampyre Imaging Library Forum. Please login or sign up.
 

transparent MNG

Started by Robert, 21 May 2008, 18:32:58

Previous topic - Next topic

Robert

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

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

Galfar

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.



robert

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.

Galfar

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?

robert

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?

Galfar


robert

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);
//------------

Galfar

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

robert

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.

Galfar

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.

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Name:
Email:

Shortcuts: ALT+S save/post or ALT+P preview

SMF spam blocked by CleanTalk