c# - Black image when saving PNG from clipboard -
i trying save png image has been copied clipboard, either turning out solid black, or black around areas should transparent.
here code using capture , save image
var clipboardimage = (interopbitmap)clipboard.getimage(); image.saveimage(clipboardimage, path.combine(config.app.applicationdataimagespath, string.format("{0}.{1}", imageid, "png"))); public static void saveimage(bitmapsource bitmapimage, string filename) { using (var filestream = new filestream(filename, filemode.create)) { var pngbitmapencoder = new pngbitmapencoder(); pngbitmapencoder.frames.add(bitmapframe.create(bitmapimage)); pngbitmapencoder.save(filestream); filestream.close(); filestream.dispose(); } }
does have ideas why won't persrve alpha channels of png?
thanks
dan
edit: should of mentioned black images happening when copying image internet explorer 9. works when copying image either chrome or firefox. workarounds ie9 issue?
what happens if this:
clipboard.getimage().save ("xxx.png", system.drawing.imaging.imageformat.png);
edit - wpf try this:
public static void saveclipboardimagetofile(string filepath) { var image = clipboard.getimage(); using (var filestream = new filestream(filepath, filemode.create)) { bitmapencoder encoder = new pngbitmapencoder(); encoder.frames.add(bitmapframe.create(image)); encoder.save(filestream); } }
Comments
Post a Comment