0
        private void ConvertButton_Click(object sender, EventArgs e)
        {
          Bitmap original = new Bitmap(@"filepath.cover.png");
          Bitmap clone = new Bitmap(original.Width, original.Height, PixelFormat.Format32bppPArgb);
          using (Graphics conv = Graphics.FromImage(clone))
          {
            conv.DrawImage(original, new Rectangle(0, 0, clone.Width, clone.Height));
          }
        }

Hello everyone, i need some help.

I trying to convert PNG or JPEG files to TGA 32bit files and save them, I am still new to programming and could not find an answer here. I found only this code snip here and tried to get him to run, i tried alot of versions to get an output file, but nothing worked, sometimes I got a blank file, sometimes a corrupt one

thank you to everyone who helps me.

Edit: First of all, thank you, I tried your code and it gives me an empty file. I'm just trying this:

private void TgaConvert_Click(object sender, EventArgs e)
{
    TGA original = new TGA(@"file.path.cover.png");
    TGA clone = new TGA(original.Width, original.Height, TgaPixelDepth.Bpp32,
    TgaImageType.Uncompressed_TrueColor);

    using (??? conv = ???(clone))
    {
        conv.???(original, new ???(0, 0, clone.Width, clone.Height));
        clone.Save(@"file.path.cover.tga");
    }
}

at the places with "???" I can't get any further

1

3 Answers 3

1

Unfortunately there is no write support for TGA included in the .net framefork. But there are other open source libraries available. Have a look at TGASharpLib from Zelenskyi Alexandr (https://github.com/ALEXGREENALEX/TGASharpLib).

If a apply his sample to your code, then this is the result:

using TGASharpLib;
...

private void ConvertButton_Click(object sender, EventArgs e)
{
    var tga = new TGA(@"filepath.cover.png");
    tga.Save(@"filepath.cover.tga");        
}
Sign up to request clarification or add additional context in comments.

1 Comment

see my answer :)
0

You can use below code to convert PNG to TGA tested and working.

    public static void ConvertPngToTga(string pngFilePath, string tgaFilePath)
    {
        // Load the PNG image into a Bitmap object
        Bitmap pngBitmap = new Bitmap(pngFilePath);

        // Convert the Bitmap object to a TGA object
        TGA tgaImage = TGA.FromBitmap(pngBitmap);

        // Save the TGA object to a file
        tgaImage.Save(tgaFilePath);
    }

Comments

-1

I did it:

using TGASharpLib;
....
TGA T;
private void ConvertButton_Click(object sender, EventArgs e)
    {
        using (Bitmap original = new Bitmap("file.path.jpg"))
        using (Bitmap clone = new Bitmap(original))
        using (Bitmap newbmp = clone.Clone(new Rectangle(0, 0, clone.Width, clone.Height), PixelFormat.Format32bppArgb))
        T = (TGA)newbmp;
        T.Save("file.path.cover.tga");
    }

1 Comment

T = (TGA)newbmp; Here T is not defined and this code doesnt work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.