Problem with TdxComponentPrinter (Delphi) - delphi

TdxComponentPrinter is a componenet that allow me print a TPanel on a paper. But there is problem and when the panel contains TImage, the background of the image will be converted to black in the paper.
Before print :
After print (on the paper) :
I have tried different ways to solve this problem. for example i used Repaint; method of TPanel,...
but doesn't work and the background of image is still black. I don't know why!!!
Help me please.

This is a png file, which might not be supported completely in your Delphi version. Did you try to change it to a TcxImage which might be more compatible with the DevExpress printing system?
It also might be worth it to submit this issue to DevExpress if you can't fix it. They reply really quick and know more about their components then all of use here on SO :-)

If it is already a jpg then you should improve the quality of the jpg. It looks like the black parts are compression artifacts where there is a mix between white and another color. If you clean up the background of the image with a paint program it will probably look a lot better.

Related

Painting issues with TScaledLayout & custom styles

I'm experiencing painting issues when combining TScaledLayout and custom styles created from the bitmap style designer in fmx.
To demonstrate, I loaded the default custom style created by chosing "New style for VCL / FMX" -> "save as .style" in the bitmap style designer. I dropped several standard controls on some colored rectangles: The red & green ones on a TScaledLayout, the blue one directly on the form. As I stretch the form, colored lines appear on the controls on the ScaledLayout; the background is partially visible:
If I size the form to exactly match the design-time dimensions, the lines disappear. That seems like a pretty significant issue, I certainly can't use those two together like that. Does anybody have an idea for a possible fix or workaround?
Looks like this is a known issue with scaling and bitmaps. See the Google+ discussion here - https://plus.google.com/+PaulThornton/posts/ACAHkJD3a84. I'll quote Marco Cantu's thoughts:
I've found an internally reported issue of a similar case, but haven't
found one that matches this scenario. Certainly worth adding to quality
portal. Having said this, I fear that bitmap-based operations and
scaling don't really fit together very well, and it might be difficult
to have an all encompassing solution.
Let me explain with an example. Take a button. This is painted by FMX
with 9 sections (borders, corners, central part) so that regardless of
the size the bitmap elements are stretched in one direction at most,
often just draw. Stretching a single bitmap for the button to the
target size would break anti-aliasing and create a blurred image when
using colors.
This is example what happens with a ScaledLayout, given it takes the
complete final image and transforms it. ScaledLayout was originally
introduced with vector styles, and worked very well in that scenario.
With todays's bitmap styles things get a bit more complex.
Regardless of this explanation of there the issue lies, I'd recommend
reporting it on QC, and I'll make sure it doesn't get closed as design
(it could naturally happen, this is how the system works) but that we
do some investigation to address the issue -- turning this into a
feature request.

GIF to AVI with windows Animate Control

I was trying to convert a GIF image (Ajax waiting like):
to AVI that will be used with TAnimate control (win32 animation control).
I have tried a few tools, but the problem is that the output AVI is either not suitable for the Animation control or not transparent.
Notes:
I don't use windows XP Themes manifest (D5).
the Common Avi's are transparent even if my program is not themed.
Using the GIF itself to show animation is not an option.
Do you know any tool that can help me with this conversion?
EDIT:
I have tried using ImageMagic with ffmpeg as described here. but I can't seem to set ffmpeg to encode to msrle.
Jasc Animation Shop is able to directly read an animated GIF and write out a compressed AVI. This is an old program that appears to be no longer offered by Corel (who acquired Jasc), but you may still be able to find the free trial version for example.
You could try the TGIFImage component (written for Delphi 5), which claims not only to support Animated GIFs, but also Transparency, as well as a means of converting a GIF to an AVI (and vice-versa).
Whether it does all that or not I cannot say as I haven't personally tested it. Like TLama mentioned in the OP comments above, I use my own means of playing each frame in an animated fashion (only mine uses a RES file and a TImage, where each frame is stored as a PNG for full semi-transparency support).
Many commercial tools do this conversion, including Corel Photo Paint, and others. A free trial is available for Corel Photo Paint, which comes included in the Corel Draw package. (Warning: It's huge, and expensive.) I don't think the transparency will be solved any more by corel photo paint's conversion than by anybody else.
Typing some words into Google, also reveals that DSPack from ProgDigy might help you.
The last time I did this, I abandoned the attempt to convert GIF transparency into AVI-with-transparency, because no AVI-encoding tool that I could find would preserve transparency. Thus the solution of leaving it as a gif, and putting a new control into your app (as LaKraven suggests) may be superior in the end, to fighting it.
I would suggest using GDIPlus native image renderer which can easily handle animated GIFs as well as many other image types, including multi-frame TIFFs (no MNG so far). I was able to find an example component which animates TImage instance:
http://www.progdigy.com/forums/viewtopic.php?p=13156
Please note I am aware that you are looking for a solution to AVI transparency, this is just an alternative way of presenting user with a "progress", which seems to be more lightweight (no dependency on windows media playback facilities) and flexible (such animation controller can be used on any image).

Resizing an image in Delphi XE

I got a jpeg image in which is 1020x780, I am trying to resize this to 111x85 (which is in proportion) but it comes out pixelated.
I am tried just
a) Assign the image to a TImage component and set the Scaled/Resize property.
b) The resize code here http://www.delphigroups.info/2/4/313095.html
c) The resize code here http://www.swissdelphicenter.ch/torry/showcode.php?id=1896
However they all come out pixelated.
If I resize in Photoshop then it comes out nice. Getting it THAT good would be ideal, however I know they spent a lot of time/code into resize so something even halfway between would be great.
Any suggestions?
Have a look at Graphics32 library. It implements various image resampling and transformation algorithms for 32-bit bitmaps.
In my blog I talk about resize images using/implementing antialiasing.
Read the article and test the code here. It's writed in Spanish but you can use authomatic translate. In any case you can read only the code.
See the difference of apply and not apply the code:
The code work with BMP, but you can convert the image first and apply it.
Instead of using the built-in TImage for scaling, you could use an external library or component, e.g. ImageMagick or some off-the-shelf component. There exists at least one Pascal wrapper for ImageMagick
http://wiki.freepascal.org/PascalMagick)
, but I've never used it myself.
I have successfully used HiComponents ImageEn library to resize an image down to approx 250 pixels. It was a while ago, but I recall that the results were quite pleasing. http://www.hicomponents.com/main/products/products-imageenvcl - it's free now, and well worth a look if you're doing any graphics programming in Delphi.

How to make the form into fully transparent 32bit alpha?

i use to create a full transparent form, but the png and the 32bit image will not blend to the form and images is not properly displayed its trnsparency. i get the concept here but i cannot put button on it. all abject are invisible except the image backgound. by the way my compiler is delphi7 and D2009
Seems that Andreas Hausladen stumbled upon a similar problem and has already implemented a solution: he rewrote TJvTransparentForm in the JVCL library.
Even if you are not going to use that component directly you may gain some insight by studying the source.
Here is the link to Andreas' article.
If you want to use a PNG to control transparency you might want to look into "layered windows":
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
UpdateLayeredWindow
This allows you to have variable transparency accross the window, just as PNG allows! The problem is, controls on layered windows don't really work, I guess it's a Windows issue. My solution was to actually brake up the big window into multiple smaller windows, with all the controls on non-layered windows. This creates yet an other problem, because you now have multiple windows and you want them to move like a single window. The solution: implement your own algorithm for moving the window accross the screen and use:
BeginDeferWindowPos
DeferWindowPos
EndDeferWindowPos
... to move all windows at once, so the user has no idea she's looking at multiple windows! Finally, if you want to get fancy, you might want to look into SetWindowRgn: this allows you to create a window with a non-rectangular shape.
P.S: Reading Andrea's link from Uwe Raabe, he's using the same technique, only he packaged it ready for action!

How do I print a partially transparent image to a PDF Canvas using Delphi?

My program needs to output a (fairly complex) form to the printer, including several images. I’m currently doing this using Delphi (2006)’s Printer.Canvas, after selecting a PDF printer (PDF995). This works like a treat.
However, I’m now running into a problem: there’s one partially transparent image that needs to be placed on top of other elements (borders, background and such), with portions of that text still visible through parts of the image.
Doing this on a regular screen Canvas works fine with regular TBitmaps, by using the TransparentColor property. However, when I try to do this on a printer, it doesn’t always work; and when I try this on a PDF printer, it never works: the background turns black, or (the best result so far), turns white, but still overwrites anything underneath it.
I’ve tried achieving the same result by inserting a PNG image with alpha transparency (a.k.a. translucency) in a Word document, and then sending that to said PDF printer. The translucency disappears, but pixel transparency is maintained. So that, at least, should somehow be possible.
Anybody know how?
You mention you are using the TransparentColor property, so is it correct to say you don't really need alpha transparency and can get away with using binary transparency (transparency for each pixel is either off or on)?
If so, it might be possible to generate a Region from your bitmap.
You then use this region as a clipping region and draw the bitmap.
The PDF printer might be able to handle a clipping region correctly.
Here's an example of generating a region from a bitmap, it's used to make non-rectangular forms but the idea is the same:
http://www.delphi-central.com/BitmapShapedForm.aspx
Here is another example of setting a clipping region for your TCanvas:
http://www.efg2.com/Lab/OtherProjects/PrinterDemo2.htm
I don't think you can achieve partial transparency using a pdf printer. What you can do is get the VisPDF package. With it you can add a mask to the images contained in the pdf that you actually produce right in you're application. If this is not an option, you could combine all your background stuff in to one image. Drawing the alphachanneled thing on this image.
I also had this problem before, If I recall correctly, what I ended up doing was to create an off screen bitmap that I manipulated, then after I was done copied again and used the new bitmap copy on the canvas I was sending to the printer.
You may want to consider using a third-party PDF component in your application to render the canvas directly to PDF. I use this technique for specialized reporting (RTF, Radioemtric JPEGs, Tables, Text etc) in a commercial product I developed for Infrared Thermography. I am very happy with the performance and quality. The component I am using llPDFLib was just updated and I believe now supports full image transparency.
Best of luck. Printing images with an Alpha channel can be challenging at times in my experience.

Resources