Jump to content

gregdosborne

Newbies
  • Posts

    3
  • Joined

  • Last visited

Posts posted by gregdosborne

  1. The bitmap data (DIB) that Paint.NET copies should be stored in PBGRA format (premultiplied alpha), even though DIB doesn't allow you to specify anything about how the alpha channel is encoded. You simply need to divide each color component by the alpha value. There will be a loss of precision, but it will give you transparency you need.

    ColorBgra c = ...; // get color from clipboard bitmap, which is in PBGRA
    int newBlue = (c.Blue * 255) / c.Alpha; // this is the regular BGRA value
    int newGreen = (c.Green * 255) / c.Alpha; // this is the regular BGRA value
    int newRed = (c.Red * 255) / c.Alpha; // this is the regular BGRA value
    int newAlpha = c.Alpha;
    etc.

    You can make this much faster by using a lookup table. That's what Paint.NET does.

    I'm hesitant to add yet another format to what Paint.NET copies to the clipboard. This is a very delicate code path, and already has all sorts of problems with out of memory errors.

    Thanks Rick, but I was looking for a way to paste an entire image into my application from Paint.NET.

  2. My primary graphics tool is Paint.Net, but I have found an inadequacy for what I am doing.

    Paint.NET copies data to the clipboard in the following formats

    PaintDotNet.MaskedSurface

    Format17

    System.Drawing.Bitmap

    Bitmap

    DeviceIndependentBitmap

    found by examining data.GetFormats() in C#. I cannot use PaintDotNet.MaskedSurface in my application and the others don't provide full transparency information for PNGs. Is there a way to have Paint.NET copy data to the clipboard using "PNG" format?

    In my app, I can copy an image into the clipboard using the following code, and all transparency information is retained.

    using (MemoryStream stream = new MemoryStream())

    {

    _Bitmap.Save(stream, ImageFormat.Png);

    var data = new DataObject("PNG", stream);

    Clipboard.Clear();

    Clipboard.SetDataObject(data, true);

    }

    and I can read the same from the clipboard using the following

    IDataObject data = Clipboard.GetDataObject();

    if (data.GetFormats().Contains("PNG")){

    MemoryStream ms = (System.IO.MemoryStream)data.GetData("PNG");

    _Bitmap = (Bitmap)Bitmap.FromStream(ms, true);

    }

    Can this be accomplished in Paint.NET, or can an extension be created that will do this?

    Thanks in advance...

  3. It is not the file, it is a png image. I know the difference.

    I copy it using .net.

    Clipboard.SetData("PNG", image);

    image is a standard 32bpp png which opens fine in Paint.NET and renders fine in .net Windows.Forms.

    Clipboard.SetImage(image);

    does the job, but the image loses its transparency when pasted, so it's of no use.

    So, why does Paint.NET not recognize the "PNG" Clipboard format?

    To properly paste a PNG image to the clipboard, do the following

    using (MemoryStream stream = new MemoryStream())

    {

    _Bitmap.Save(stream, ImageFormat.Png);

    var data = new DataObject("PNG", stream);

    Clipboard.Clear();

    Clipboard.SetDataObject(data, true);

    }

    This should take care of your problems.

×
×
  • Create New...