Convert SWF to PNG image with transparency - c#

I'm converting a swf file to png image using SWFtoImage tool in c#. I'm able to convert the file successfully, but the problem is transparency. The converted image contains a black background instead of transparent, as you can see in the attached image.
how can I fix this? since the tool fails to create a transparent image, is it possible in .net to manipulate on the converted png image and make its background transparent?
Current Code:
//Namespace: BytescoutSWFToVideo;
// Create an instance of SWFToVideo ActiveX object
SWFToVideo converter = new SWFToVideo();
// Register SWFToVideo
converter.RegistrationName = "demo";
converter.RegistrationKey = "demo";
// set input SWF file
converter.InputSWFFileName = #"D:\image2069.swf";
// Enable trasparency
converter.RGBAMode = true;
// Extract all frames to .\Output sub-folder
converter.ConvertAllToPNG(#"D:\Result\");
This is the swf file.

I don't know much about SWFToImage. But the company's web site contains demo code with the following comment (translated to C#):
// Enable trasparency - set BEFORE setting input SWF filename
converter.RGBAMode = true;
So possibly you have to change the order of your statements.

Related

How to make the background of an image ( logo ) transparent in C# WPF?

I've an image ( logo ) and I would like to pass it as an argument and make the background transparent and then save it.
How can I achieve this ?
This what I've tried :
public string SaveImage(Bitmap bmp,string SavePath,string Name)
{
string path = "";
var format = ImageFormat.Jpeg;
using (var m = new MemoryStream())
{
bmp.Save(m, format);
var img = System.Drawing.Image.FromStream(m);
using (var g = Graphics.FromImage(img)) // This is what I've used for making the background transparent
{
g.Clear(System.Drawing.Color.Transparent);
g.Save();
}
var ImgPath = Path.Combine(SavePath, Path.ChangeExtension(Name,"png"));
img.Save(ImgPath);
path = ImgPath;
}
return path;
}
After testing this function I'm getting a black image as an output ( save image )
Some remarks for your code:
You use System.Drawing types wrapping native GDI+ components, not WPF.
You save the Bitmap with JPEG encoder, which does not support transparency. Even if the logo had a transparent background it is removed by the JPEG encoder
Now you reload the saved image and clear the complete content with transparent color (which will not work either as the reloaded JPEG image will have 24-bit RGB pixel format without alpha support so the whole image will be black)
Possible solutions:
Use PNG encoder instead, which supports transparency. If the logo had a transparent background you don't even need anything else.
If the logo was not transparent originally, use the MakeTransparent method instead of Clear. It will replace a single color so it is not able to restore possible anti-aliased alpha blending. It will also convert the pixel format so can be used also on the reloaded JPEG.
To do the same in WPF you can use this library (disclaimer: written by me). You can use the GetReadWriteBitmapData extension method on a WriteableBitmap to access the same MakeTransparent functionality as above along with a sort of other features. But to restore a nicely anti-aliased alpha background you might want to use the TransformColors method instead if you know how to separate the blended colors.

Displaying editable image in c#

I want to display an image (.tif, gray value 16 bit) which is editable for the user via sliders. The displayed image should directly react to the changes, so the user knows what he's doing to the image.
Currently I only seem to be creating new files with every change and displaying the latest one, which is a terrible solution.
My idea would be to load the original pixeldata, put it in some sort of temporary file which isn't and won't be saved, then saving the parameters of the sliders and when hitting save applying the parameters to the original image (since in the end the filter is used on an intire set of images).
An Image is not a File. If might be that you display the Image that is in a file, but once you've loaded the file into an Image object don't ever use the file again, until the edited image needs to be saved in a file.
You say you want to display an image. As you are using winforms, I assume you are using a PictureBox control. If not, you have a class that you order to display an Image.
Image imageToDisplay = GetImageToDisplay();
this.PictureBox1.Image = imageToDisplay;
GetImageTodisplay will read the file and return it as an Image
System.Drawing.Image GetImageToDisplay()
{
FileStream imageStream = new FileStream(this.GetImageFileName(), FileMode.Open);
System.Drawing.Image image = new Image(imageStream);
return image;
}
Apparently you also have sliders. You don't mention the class of your sliders, but apparently it is an object that notifies your form about a new slider value.
void OnSliderValueChanged(object sender, int sliderValue)
{
Image displayedImage = this.PictureBox1.Image;
this.ProcessSliderChanged(image, sliderValue);
}
Until now I don't see the creation of a new file. So this should be in ProcessSliderChange. Luckily that is a function you created yourself. All you have to do is change the image according to your new slider value. Don't do anything with file handling and you won't get a new file
void ProcessSliderChange(System.Drawing.Image image, int sliderValue)
{ // what do you want to do with the image?
// make it darker? move it? change contrast?
}
Unfortunately the Image class doesn't have a lot of functions to edit images, I assume you have a library with functions that act on System.Drawing.Image objects. Just use those functions to change your Image.

Dynamically create a picture with some texts and background image as PNG

I have the following:
A headline (text)
A tagline (text)
A background image (url to this image)
I need to set these dynamically together in an image, and then store it as a PNG file. All of this happens in a web service which sends some kind of stream back.
I would love to be able to style this with CSS, as it would be nice to add some CSS effects to the picture. If that is not possible, it is fine as well.
So far I've thought about using the Bitmap class, and then insert my things dynamically. This is definetely one way to go, but I would really prefer some more design-friendly way like CSS.
What is the prefered way to do this? Any experiences?
Check out System.Drawing.Graphics.
Bitmap bmp = new Bitmap(500, 500);
using (Graphics g = Graphics.FromImage(bmp)) {
g.Clear(Color.Black);
// ...
}
You can then call Image.Save (bmp.Save(...)) to save the image to disk or even to a MemoryStream.
The answer from Angelo Geels will let you create a dynamic bitmap in your code. If you need more flexibility then you might want to use the SVG format instead, and possibly render it as a PNG file if you absolutely need that format.
SVG is an XML based image format where you define a viewport and shapes that should be drawn into it. It is vector based so the images can be scaled up and down to any size.
It should be quite easy to write an ASP.Net Http Handler that outputs an SVG xml file with some dynamic content based on user input. An even easier option would be to serve static SVG files that your designers create, but then you might as well serve static PNG files.
If you want to use the SVG approach for its flexibility but still need to output PNG's then you can use the SVG.Net library to read the SVG file and then use the SvgDocument.Draw method to draw the image to a Bitmap object that can then be written out as a PNG file.

How to load an in-memory image on a WinForms WebBrowser control

I'm developing a .NET 3.5 WinForms project in C# and I would like opinions on the best method to render an image in a WebBrowser control, directly from an in-memory source?
By in-memory, I mean that I have a collection of images that are in a Base64 encoded string format and I wish to render them on an embedded page in a WebBrowser control.
I had hoped to use the embedded Data URI option example however this approach is limited to images < 32KB.
I'm hoping that it is possible to convert it to a System.Drawing.Image instance and somehow reference this image in a the src html tag like so: <img src="<insert reference here?>" </img>. Is such a technique possible?
If it's not possible to do this, then I wonder on the feasibility of creating the file in the windows temporary directory and reference from there?
Another approach is to set up a web server and to load the image via the localhost <img src='http://localhost/img.jpg'>. This prevents creating temporary images images on disk.
If you don't want to deal with a web server, simple image tiling combined with the mentioned data URI parameter would work. A single tile can be obtained by:
Rectangle region = new Rectangle(x, y, tileWidth, tileHeight);
Bitmap tile = sourceBitmap.Clone(region, sourceBitmap.Clone.PixelFormat);
You just repeat the tile generation for varying parameters of Rectangle region until you have covered the complete source image. You might try out which tileWidth and tileHeight are appropriate to result in tiles with data size lower than 32kB.

Apply Image Manipulations to an image to make a new image

I am working on an Image manipulation application which will be developed using Flash/ C#.Net. Is this possible to save the image manipulations (not the image) saved from Adobe Lightroom for a specific image & then merge these change sets with an image to make a new image using C#.Net?
Also, the application for image manipulation will be developed in the Flash/ Action Script. Please share some links as to how we can save the image manipulations for an image (not the image) so that it can be merged with an image later on.
Kindly suggest some links.
Just store a list of commands e.g.
1 -> rotate on 90 degree
2 -> move 10px. left
....

Categories

Resources