mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 13:10:00 -07:00
Changed code for the Clipboard and changed a lot of "Bitmap" code to work on images, this might give problems but if these are solved we have better support for MetaFiles. This made it possible to remove the MetafileContainer, which is replaced by the ImageContainer (which is the BitmapContainer modified). The clipboard code now knows more ways to load images from the clipboard!
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2398 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
b7a604d93b
commit
f627ce5dd0
15 changed files with 301 additions and 382 deletions
|
@ -125,8 +125,8 @@ namespace Greenshot.Destinations {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
using (Bitmap image = (Bitmap)surface.GetImageForExport()) {
|
using (Image image = surface.GetImageForExport()) {
|
||||||
editor.Surface.AddBitmapContainer(image, 10, 10);
|
editor.Surface.AddImageContainer(image, 10, 10);
|
||||||
}
|
}
|
||||||
exportInformation.ExportMade = true;
|
exportInformation.ExportMade = true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -36,17 +36,17 @@ namespace Greenshot.Drawing {
|
||||||
/// Description of BitmapContainer.
|
/// Description of BitmapContainer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable()]
|
[Serializable()]
|
||||||
public class BitmapContainer : DrawableContainer, IBitmapContainer {
|
public class ImageContainer : DrawableContainer, IImageContainer {
|
||||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(BitmapContainer));
|
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ImageContainer));
|
||||||
|
|
||||||
private Bitmap bitmap;
|
private Image image;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is the shadow version of the bitmap, rendered once to save performance
|
/// This is the shadow version of the bitmap, rendered once to save performance
|
||||||
/// Do not serialize, as the shadow is recreated from the original bitmap if it's not available
|
/// Do not serialize, as the shadow is recreated from the original bitmap if it's not available
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
private Bitmap shadowBitmap = null;
|
private Image shadowBitmap = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is the offset for the shadow version of the bitmap
|
/// This is the offset for the shadow version of the bitmap
|
||||||
|
@ -55,11 +55,11 @@ namespace Greenshot.Drawing {
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
private Point shadowOffset = new Point(-1, -1);
|
private Point shadowOffset = new Point(-1, -1);
|
||||||
|
|
||||||
public BitmapContainer(Surface parent, string filename) : this(parent) {
|
public ImageContainer(Surface parent, string filename) : this(parent) {
|
||||||
Load(filename);
|
Load(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BitmapContainer(Surface parent) : base(parent) {
|
public ImageContainer(Surface parent) : base(parent) {
|
||||||
AddField(GetType(), FieldType.SHADOW, false);
|
AddField(GetType(), FieldType.SHADOW, false);
|
||||||
FieldChanged += BitmapContainer_OnFieldChanged;
|
FieldChanged += BitmapContainer_OnFieldChanged;
|
||||||
}
|
}
|
||||||
|
@ -81,8 +81,8 @@ namespace Greenshot.Drawing {
|
||||||
this.Left = this.Left - this.shadowOffset.X;
|
this.Left = this.Left - this.shadowOffset.X;
|
||||||
this.Top = this.Top - this.shadowOffset.Y;
|
this.Top = this.Top - this.shadowOffset.Y;
|
||||||
} else {
|
} else {
|
||||||
this.Width = bitmap.Width;
|
this.Width = image.Width;
|
||||||
this.Height = bitmap.Height;
|
this.Height = image.Height;
|
||||||
if (shadowBitmap != null) {
|
if (shadowBitmap != null) {
|
||||||
this.Left = this.Left + this.shadowOffset.X;
|
this.Left = this.Left + this.shadowOffset.X;
|
||||||
this.Top = this.Top + this.shadowOffset.Y;
|
this.Top = this.Top + this.shadowOffset.Y;
|
||||||
|
@ -90,16 +90,16 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap Bitmap {
|
public Image Image {
|
||||||
set {
|
set {
|
||||||
// Remove all current bitmaps
|
// Remove all current bitmaps
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
bitmap = ImageHelper.Clone(value);
|
image = ImageHelper.Clone(value);
|
||||||
bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
|
bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
|
||||||
CheckShadow(shadow);
|
CheckShadow(shadow);
|
||||||
if (!shadow) {
|
if (!shadow) {
|
||||||
Width = bitmap.Width;
|
Width = image.Width;
|
||||||
Height = bitmap.Height;
|
Height = image.Height;
|
||||||
} else {
|
} else {
|
||||||
Width = shadowBitmap.Width;
|
Width = shadowBitmap.Width;
|
||||||
Height = shadowBitmap.Height;
|
Height = shadowBitmap.Height;
|
||||||
|
@ -107,13 +107,13 @@ namespace Greenshot.Drawing {
|
||||||
this.Top = this.Top - this.shadowOffset.Y;
|
this.Top = this.Top - this.shadowOffset.Y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
get { return bitmap; }
|
get { return image; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Destructor
|
/// Destructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
~BitmapContainer() {
|
~ImageContainer() {
|
||||||
Dispose(false);
|
Dispose(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,14 +135,14 @@ namespace Greenshot.Drawing {
|
||||||
/// <param name="disposing"></param>
|
/// <param name="disposing"></param>
|
||||||
protected virtual void Dispose(bool disposing) {
|
protected virtual void Dispose(bool disposing) {
|
||||||
if (disposing) {
|
if (disposing) {
|
||||||
if (bitmap != null) {
|
if (image != null) {
|
||||||
bitmap.Dispose();
|
image.Dispose();
|
||||||
}
|
}
|
||||||
if (shadowBitmap != null) {
|
if (shadowBitmap != null) {
|
||||||
shadowBitmap.Dispose();
|
shadowBitmap.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bitmap = null;
|
image = null;
|
||||||
shadowBitmap = null;
|
shadowBitmap = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,8 +154,8 @@ namespace Greenshot.Drawing {
|
||||||
if (File.Exists(filename)) {
|
if (File.Exists(filename)) {
|
||||||
// Always make sure ImageHelper.LoadBitmap results are disposed some time,
|
// Always make sure ImageHelper.LoadBitmap results are disposed some time,
|
||||||
// as we close the bitmap internally, we need to do it afterwards
|
// as we close the bitmap internally, we need to do it afterwards
|
||||||
using (Bitmap tmpImage = ImageHelper.LoadBitmap(filename)) {
|
using (Image tmpImage = ImageHelper.LoadImage(filename)) {
|
||||||
Bitmap = tmpImage;
|
Image = tmpImage;
|
||||||
}
|
}
|
||||||
LOG.Debug("Loaded file: " + filename + " with resolution: " + Height + "," + Width);
|
LOG.Debug("Loaded file: " + filename + " with resolution: " + Height + "," + Width);
|
||||||
}
|
}
|
||||||
|
@ -166,11 +166,11 @@ namespace Greenshot.Drawing {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="rotateFlipType"></param>
|
/// <param name="rotateFlipType"></param>
|
||||||
public override void Rotate(RotateFlipType rotateFlipType) {
|
public override void Rotate(RotateFlipType rotateFlipType) {
|
||||||
Bitmap newBitmap = ImageHelper.RotateFlip((Bitmap)bitmap, rotateFlipType);
|
Image newImage = ImageHelper.RotateFlip((Bitmap)image, rotateFlipType);
|
||||||
if (newBitmap != null) {
|
if (newImage != null) {
|
||||||
// Remove all current bitmaps, also the shadow (will be recreated)
|
// Remove all current bitmaps, also the shadow (will be recreated)
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
bitmap = newBitmap;
|
image = newImage;
|
||||||
}
|
}
|
||||||
base.Rotate(rotateFlipType);
|
base.Rotate(rotateFlipType);
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ namespace Greenshot.Drawing {
|
||||||
/// <param name="shadow"></param>
|
/// <param name="shadow"></param>
|
||||||
private void CheckShadow(bool shadow) {
|
private void CheckShadow(bool shadow) {
|
||||||
if (shadow && shadowBitmap == null) {
|
if (shadow && shadowBitmap == null) {
|
||||||
shadowBitmap = ImageHelper.ApplyEffect(bitmap, new DropShadowEffect(), out shadowOffset);
|
shadowBitmap = ImageHelper.ApplyEffect(image, new DropShadowEffect(), out shadowOffset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ namespace Greenshot.Drawing {
|
||||||
/// <param name="graphics"></param>
|
/// <param name="graphics"></param>
|
||||||
/// <param name="rm"></param>
|
/// <param name="rm"></param>
|
||||||
public override void Draw(Graphics graphics, RenderMode rm) {
|
public override void Draw(Graphics graphics, RenderMode rm) {
|
||||||
if (bitmap != null) {
|
if (image != null) {
|
||||||
bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
|
bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
|
||||||
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
||||||
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||||
|
@ -202,7 +202,7 @@ namespace Greenshot.Drawing {
|
||||||
CheckShadow(shadow);
|
CheckShadow(shadow);
|
||||||
graphics.DrawImage(shadowBitmap, Bounds);
|
graphics.DrawImage(shadowBitmap, Bounds);
|
||||||
} else {
|
} else {
|
||||||
graphics.DrawImage(bitmap, Bounds);
|
graphics.DrawImage(image, Bounds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -215,7 +215,7 @@ namespace Greenshot.Drawing {
|
||||||
|
|
||||||
public override Size DefaultSize {
|
public override Size DefaultSize {
|
||||||
get {
|
get {
|
||||||
return bitmap.Size;
|
return image.Size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,123 +0,0 @@
|
||||||
/*
|
|
||||||
* Greenshot - a free and open source screenshot tool
|
|
||||||
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
|
|
||||||
*
|
|
||||||
* For more information see: http://getgreenshot.org/
|
|
||||||
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 1 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
using System;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Drawing.Imaging;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
using Greenshot.Plugin.Drawing;
|
|
||||||
using System.Drawing.Drawing2D;
|
|
||||||
|
|
||||||
namespace Greenshot.Drawing {
|
|
||||||
/// <summary>
|
|
||||||
/// Description of MetafileContainer.
|
|
||||||
/// </summary>
|
|
||||||
[Serializable()]
|
|
||||||
public class MetafileContainer : DrawableContainer, IMetafileContainer {
|
|
||||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(MetafileContainer));
|
|
||||||
|
|
||||||
protected Metafile metafile;
|
|
||||||
|
|
||||||
public MetafileContainer(Surface parent) : base(parent) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public MetafileContainer(Surface parent, string filename) : base(parent) {
|
|
||||||
Load(filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Metafile Metafile {
|
|
||||||
set {
|
|
||||||
if (metafile != null) {
|
|
||||||
metafile.Dispose();
|
|
||||||
}
|
|
||||||
metafile = (Metafile)value.Clone();
|
|
||||||
Height = Math.Abs(value.Height);
|
|
||||||
if (Height == 0 ) {
|
|
||||||
Height = 100;
|
|
||||||
}
|
|
||||||
Width = Math.Abs(value.Width);
|
|
||||||
if (Width == 0 ) {
|
|
||||||
Width = 100;
|
|
||||||
}
|
|
||||||
while (Height > parent.Height) {
|
|
||||||
Height = Height / 4;
|
|
||||||
Width = Width / 4;
|
|
||||||
}
|
|
||||||
while (Width > parent.Width) {
|
|
||||||
Height = Height / 4;
|
|
||||||
Width = Width / 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
get { return metafile; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destructor
|
|
||||||
*/
|
|
||||||
~MetafileContainer() {
|
|
||||||
Dispose(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The public accessible Dispose
|
|
||||||
* Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice
|
|
||||||
*/
|
|
||||||
public new void Dispose() {
|
|
||||||
Dispose(true);
|
|
||||||
base.Dispose();
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The bulk of the clean-up code is implemented in Dispose(bool)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This Dispose is called from the Dispose and the Destructor.
|
|
||||||
* When disposing==true all non-managed resources should be freed too!
|
|
||||||
*/
|
|
||||||
protected virtual void Dispose(bool disposing) {
|
|
||||||
if (disposing) {
|
|
||||||
if (metafile != null) {
|
|
||||||
metafile.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
metafile = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Load(string filename) {
|
|
||||||
if (File.Exists(filename)) {
|
|
||||||
using (Stream imageFileStream = File.OpenRead(filename)) {
|
|
||||||
Metafile = (Metafile)Image.FromStream(imageFileStream, true, true);
|
|
||||||
LOG.Debug("Loaded file: " + filename + " with resolution: " + Height + "," + Width);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Draw(Graphics graphics, RenderMode rm) {
|
|
||||||
if (metafile != null) {
|
|
||||||
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
|
||||||
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
|
||||||
graphics.CompositingQuality = CompositingQuality.HighQuality;
|
|
||||||
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
|
||||||
graphics.DrawImage(metafile, Bounds);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -620,7 +620,7 @@ namespace Greenshot.Drawing {
|
||||||
undrawnElement = cropContainer;
|
undrawnElement = cropContainer;
|
||||||
break;
|
break;
|
||||||
case DrawingModes.Bitmap:
|
case DrawingModes.Bitmap:
|
||||||
undrawnElement = new BitmapContainer(this);
|
undrawnElement = new ImageContainer(this);
|
||||||
break;
|
break;
|
||||||
case DrawingModes.Path:
|
case DrawingModes.Path:
|
||||||
undrawnElement = new FreehandContainer(this);
|
undrawnElement = new FreehandContainer(this);
|
||||||
|
@ -635,17 +635,17 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Plugin interface implementations
|
#region Plugin interface implementations
|
||||||
public IBitmapContainer AddBitmapContainer(Bitmap bitmap, int x, int y) {
|
public IImageContainer AddImageContainer(Image image, int x, int y) {
|
||||||
BitmapContainer bitmapContainer = new BitmapContainer(this);
|
ImageContainer bitmapContainer = new ImageContainer(this);
|
||||||
bitmapContainer.Bitmap = bitmap;
|
bitmapContainer.Image = image;
|
||||||
bitmapContainer.Left = x;
|
bitmapContainer.Left = x;
|
||||||
bitmapContainer.Top = y;
|
bitmapContainer.Top = y;
|
||||||
AddElement(bitmapContainer);
|
AddElement(bitmapContainer);
|
||||||
return bitmapContainer;
|
return bitmapContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBitmapContainer AddBitmapContainer(string filename, int x, int y) {
|
public IImageContainer AddImageContainer(string filename, int x, int y) {
|
||||||
BitmapContainer bitmapContainer = new BitmapContainer(this);
|
ImageContainer bitmapContainer = new ImageContainer(this);
|
||||||
bitmapContainer.Load(filename);
|
bitmapContainer.Load(filename);
|
||||||
bitmapContainer.Left = x;
|
bitmapContainer.Left = x;
|
||||||
bitmapContainer.Top = y;
|
bitmapContainer.Top = y;
|
||||||
|
@ -684,22 +684,6 @@ namespace Greenshot.Drawing {
|
||||||
AddElement(cursorContainer);
|
AddElement(cursorContainer);
|
||||||
return cursorContainer;
|
return cursorContainer;
|
||||||
}
|
}
|
||||||
public IMetafileContainer AddMetafileContainer(string filename, int x, int y) {
|
|
||||||
MetafileContainer metafileContainer = new MetafileContainer(this);
|
|
||||||
metafileContainer.Load(filename);
|
|
||||||
metafileContainer.Left = x;
|
|
||||||
metafileContainer.Top = y;
|
|
||||||
AddElement(metafileContainer);
|
|
||||||
return metafileContainer;
|
|
||||||
}
|
|
||||||
public IMetafileContainer AddMetafileContainer(Metafile metafile, int x, int y) {
|
|
||||||
MetafileContainer metafileContainer = new MetafileContainer(this);
|
|
||||||
metafileContainer.Metafile = metafile;
|
|
||||||
metafileContainer.Left = x;
|
|
||||||
metafileContainer.Top = y;
|
|
||||||
AddElement(metafileContainer);
|
|
||||||
return metafileContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ITextContainer AddTextContainer(string text, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, FontFamily family, float size, bool italic, bool bold, bool shadow, int borderSize, Color color, Color fillColor) {
|
public ITextContainer AddTextContainer(string text, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, FontFamily family, float size, bool italic, bool bold, bool shadow, int borderSize, Color color, Color fillColor) {
|
||||||
TextContainer textContainer = new TextContainer(this);
|
TextContainer textContainer = new TextContainer(this);
|
||||||
|
@ -735,11 +719,10 @@ namespace Greenshot.Drawing {
|
||||||
if (draggingInProgress || (e.AllowedEffect & DragDropEffects.Copy) != DragDropEffects.Copy) {
|
if (draggingInProgress || (e.AllowedEffect & DragDropEffects.Copy) != DragDropEffects.Copy) {
|
||||||
e.Effect=DragDropEffects.None;
|
e.Effect=DragDropEffects.None;
|
||||||
} else {
|
} else {
|
||||||
List<string> filenames = ClipboardHelper.GetImageFilenames(e.Data);
|
if (ClipboardHelper.ContainsImage(e.Data) || ClipboardHelper.ContainsFormat(e.Data, "DragImageBits")) {
|
||||||
if ((filenames != null && filenames.Count > 0) || ClipboardHelper.ContainsImage(e.Data) || ClipboardHelper.ContainsFormat(e.Data, "DragImageBits")) {
|
e.Effect = DragDropEffects.Copy;
|
||||||
e.Effect=DragDropEffects.Copy;
|
|
||||||
} else {
|
} else {
|
||||||
e.Effect=DragDropEffects.None;
|
e.Effect = DragDropEffects.None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -756,31 +739,19 @@ namespace Greenshot.Drawing {
|
||||||
string possibleUrl = ClipboardHelper.GetText(e.Data);
|
string possibleUrl = ClipboardHelper.GetText(e.Data);
|
||||||
// Test if it's an url and try to download the image so we have it in the original form
|
// Test if it's an url and try to download the image so we have it in the original form
|
||||||
if (possibleUrl != null && possibleUrl.StartsWith("http")) {
|
if (possibleUrl != null && possibleUrl.StartsWith("http")) {
|
||||||
using (Bitmap image = NetworkHelper.DownloadImage(possibleUrl)) {
|
using (Image image = NetworkHelper.DownloadImage(possibleUrl)) {
|
||||||
if (image != null) {
|
if (image != null) {
|
||||||
AddBitmapContainer(image, mouse.X, mouse.Y);
|
AddImageContainer(image, mouse.X, mouse.Y);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((filenames != null && filenames.Count > 0)) {
|
foreach (Image image in ClipboardHelper.GetImages(e.Data)) {
|
||||||
foreach (string filename in filenames) {
|
AddImageContainer(image, mouse.X, mouse.Y);
|
||||||
if (filename != null && filename.Trim().Length > 0) {
|
|
||||||
LOG.Debug("Drop - filename: " + filename);
|
|
||||||
if (filename.ToLower().EndsWith("wmf")) {
|
|
||||||
AddMetafileContainer(filename, mouse.X, mouse.Y);
|
|
||||||
} else {
|
|
||||||
AddBitmapContainer(filename, mouse.X, mouse.Y);
|
|
||||||
}
|
|
||||||
mouse.Offset(10, 10);
|
mouse.Offset(10, 10);
|
||||||
}
|
image.Dispose();
|
||||||
}
|
|
||||||
} else if (e.Data.GetDataPresent(DataFormats.Bitmap)) {
|
|
||||||
AddBitmapContainer((Bitmap)e.Data.GetData(DataFormats.Bitmap, true), mouse.X, mouse.Y);
|
|
||||||
} else if (e.Data.GetDataPresent(DataFormats.EnhancedMetafile)) {
|
|
||||||
AddMetafileContainer((Metafile)e.Data.GetData(DataFormats.EnhancedMetafile, true), mouse.X, mouse.Y);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -847,7 +818,7 @@ namespace Greenshot.Drawing {
|
||||||
try {
|
try {
|
||||||
Rectangle imageRectangle = new Rectangle(Point.Empty, Image.Size);
|
Rectangle imageRectangle = new Rectangle(Point.Empty, Image.Size);
|
||||||
Point offset;
|
Point offset;
|
||||||
Bitmap newImage = ImageHelper.ApplyEffect((Bitmap)Image, effect, out offset);
|
Image newImage = ImageHelper.ApplyEffect(Image, effect, out offset);
|
||||||
if (newImage != null) {
|
if (newImage != null) {
|
||||||
// Make sure the elements move according to the offset the effect made the bitmap move
|
// Make sure the elements move according to the offset the effect made the bitmap move
|
||||||
elements.MoveBy(offset.X, offset.Y);
|
elements.MoveBy(offset.X, offset.Y);
|
||||||
|
@ -1149,7 +1120,7 @@ namespace Greenshot.Drawing {
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private Image GetImage(RenderMode renderMode) {
|
private Image GetImage(RenderMode renderMode) {
|
||||||
// Generate a copy of the original image with a dpi equal to the default...
|
// Generate a copy of the original image with a dpi equal to the default...
|
||||||
Bitmap clone = ImageHelper.Clone(image);
|
Bitmap clone = ImageHelper.Clone(image, PixelFormat.DontCare);
|
||||||
// otherwise we would have a problem drawing the image to the surface... :(
|
// otherwise we would have a problem drawing the image to the surface... :(
|
||||||
using (Graphics graphics = Graphics.FromImage(clone)) {
|
using (Graphics graphics = Graphics.FromImage(clone)) {
|
||||||
// Do not set the following, the containers need to decide themselves
|
// Do not set the following, the containers need to decide themselves
|
||||||
|
@ -1391,11 +1362,16 @@ namespace Greenshot.Drawing {
|
||||||
SelectElements(dcs);
|
SelectElements(dcs);
|
||||||
}
|
}
|
||||||
} else if (ClipboardHelper.ContainsImage(clipboard)) {
|
} else if (ClipboardHelper.ContainsImage(clipboard)) {
|
||||||
using (Image clipboardImage = ClipboardHelper.GetImage(clipboard)) {
|
int x = 10;
|
||||||
|
int y = 10;
|
||||||
|
foreach (Image clipboardImage in ClipboardHelper.GetImages(clipboard)) {
|
||||||
if (clipboardImage != null) {
|
if (clipboardImage != null) {
|
||||||
DeselectAllElements();
|
DeselectAllElements();
|
||||||
IBitmapContainer bitmapContainer = AddBitmapContainer(clipboardImage as Bitmap, 0, 0);
|
IImageContainer container = AddImageContainer(clipboardImage as Bitmap, x, y);
|
||||||
SelectElement(bitmapContainer);
|
SelectElement(container);
|
||||||
|
clipboardImage.Dispose();
|
||||||
|
x += 10;
|
||||||
|
y += 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (ClipboardHelper.ContainsText(clipboard)) {
|
} else if (ClipboardHelper.ContainsText(clipboard)) {
|
||||||
|
|
|
@ -1180,7 +1180,7 @@ namespace Greenshot {
|
||||||
this.Activate();
|
this.Activate();
|
||||||
WindowDetails.ToForeground(this.Handle);
|
WindowDetails.ToForeground(this.Handle);
|
||||||
if (capture!= null && capture.Image != null) {
|
if (capture!= null && capture.Image != null) {
|
||||||
surface.AddBitmapContainer((Bitmap)capture.Image, 100, 100);
|
surface.AddImageContainer((Bitmap)capture.Image, 100, 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -328,7 +328,7 @@ namespace Greenshot.Helpers {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CaptureMode.File:
|
case CaptureMode.File:
|
||||||
Bitmap fileBitmap = null;
|
Image fileImage = null;
|
||||||
string filename = capture.CaptureDetails.Filename;
|
string filename = capture.CaptureDetails.Filename;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(filename)) {
|
if (!string.IsNullOrEmpty(filename)) {
|
||||||
|
@ -345,20 +345,20 @@ namespace Greenshot.Helpers {
|
||||||
MessageBox.Show(Language.GetFormattedString(LangKey.error_openfile, filename));
|
MessageBox.Show(Language.GetFormattedString(LangKey.error_openfile, filename));
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
fileBitmap = ImageHelper.LoadBitmap(filename);
|
fileImage = ImageHelper.LoadImage(filename);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.Error(e.Message, e);
|
LOG.Error(e.Message, e);
|
||||||
MessageBox.Show(Language.GetFormattedString(LangKey.error_openfile, filename));
|
MessageBox.Show(Language.GetFormattedString(LangKey.error_openfile, filename));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fileBitmap != null) {
|
if (fileImage != null) {
|
||||||
capture.CaptureDetails.Title = Path.GetFileNameWithoutExtension(filename);
|
capture.CaptureDetails.Title = Path.GetFileNameWithoutExtension(filename);
|
||||||
capture.CaptureDetails.AddMetaData("file", filename);
|
capture.CaptureDetails.AddMetaData("file", filename);
|
||||||
capture.CaptureDetails.AddMetaData("source", "file");
|
capture.CaptureDetails.AddMetaData("source", "file");
|
||||||
if (capture != null) {
|
if (capture != null) {
|
||||||
capture.Image = fileBitmap;
|
capture.Image = fileImage;
|
||||||
} else {
|
} else {
|
||||||
capture = new Capture(fileBitmap);
|
capture = new Capture(fileImage);
|
||||||
}
|
}
|
||||||
// Force Editor, keep picker, this is currently the only usefull destination
|
// Force Editor, keep picker, this is currently the only usefull destination
|
||||||
if (capture.CaptureDetails.HasDestination(PickerDestination.DESIGNATION)) {
|
if (capture.CaptureDetails.HasDestination(PickerDestination.DESIGNATION)) {
|
||||||
|
|
|
@ -108,7 +108,7 @@ namespace GreenshotPlugin.Core {
|
||||||
/// Create a BitmapBuffer from a Bitmap
|
/// Create a BitmapBuffer from a Bitmap
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sourceBmp">Bitmap</param>
|
/// <param name="sourceBmp">Bitmap</param>
|
||||||
public BitmapBuffer(Bitmap bmp) : this(bmp, Rectangle.Empty) {
|
public BitmapBuffer(Image sourceBmp) : this(sourceBmp, Rectangle.Empty) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -116,7 +116,7 @@ namespace GreenshotPlugin.Core {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sourceBmp">Bitmap</param>
|
/// <param name="sourceBmp">Bitmap</param>
|
||||||
/// <param name="clone">bool specifying if the bitmap needs to be cloned</param>
|
/// <param name="clone">bool specifying if the bitmap needs to be cloned</param>
|
||||||
public BitmapBuffer(Bitmap sourceBmp, bool clone) : this(sourceBmp, Rectangle.Empty, clone) {
|
public BitmapBuffer(Image sourceBmp, bool clone) : this(sourceBmp, Rectangle.Empty, clone) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -124,21 +124,21 @@ namespace GreenshotPlugin.Core {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sourceBmp">Bitmap</param>
|
/// <param name="sourceBmp">Bitmap</param>
|
||||||
/// <param name="applyRect">Rectangle</param>
|
/// <param name="applyRect">Rectangle</param>
|
||||||
public BitmapBuffer(Bitmap sourceBmp, Rectangle applyRect) : this(sourceBmp, applyRect, true) {
|
public BitmapBuffer(Image sourceBmp, Rectangle applyRect) : this(sourceBmp, applyRect, true) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a BitmapBuffer from a Bitmap, a Rectangle specifying what part from the Bitmap to take and a flag if we need a clone
|
/// Create a BitmapBuffer from a Bitmap, a Rectangle specifying what part from the Bitmap to take and a flag if we need a clone
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sourceBmp">Bitmap</param>
|
/// <param name="sourceImage">Image, will be cloned if it's not a bitmap!!!</param>
|
||||||
/// <param name="applyRect">Rectangle</param>
|
/// <param name="applyRect">Rectangle</param>
|
||||||
/// <param name="clone">bool specifying if the bitmap needs to be cloned</param>
|
/// <param name="clone">bool specifying if the bitmap needs to be cloned</param>
|
||||||
public BitmapBuffer(Bitmap sourceBmp, Rectangle applyRect, bool clone) {
|
public BitmapBuffer(Image sourceImage, Rectangle applyRect, bool clone) {
|
||||||
this.clone = clone;
|
this.clone = clone;
|
||||||
Rectangle sourceRect = new Rectangle(applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height);
|
Rectangle sourceRect = new Rectangle(applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height);
|
||||||
Rectangle bitmapRect = new Rectangle(0,0, sourceBmp.Width, sourceBmp.Height);
|
Rectangle bitmapRect = new Rectangle(0,0, sourceImage.Width, sourceImage.Height);
|
||||||
|
|
||||||
if(sourceRect.IsEmpty) {
|
if (sourceRect.IsEmpty) {
|
||||||
sourceRect = bitmapRect;
|
sourceRect = bitmapRect;
|
||||||
} else {
|
} else {
|
||||||
sourceRect.Intersect(bitmapRect);
|
sourceRect.Intersect(bitmapRect);
|
||||||
|
@ -148,15 +148,20 @@ namespace GreenshotPlugin.Core {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(sourceImage is Bitmap) && !clone) {
|
||||||
|
LOG.Warn("Chancing clone to true, as the image is not a bitmap");
|
||||||
|
clone = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (clone) {
|
if (clone) {
|
||||||
this.bitmap = ImageHelper.CloneArea(sourceBmp, sourceRect, PixelFormat.DontCare);
|
this.bitmap = ImageHelper.CloneArea(sourceImage, sourceRect, PixelFormat.DontCare);
|
||||||
// Set "this" rect to location 0,0
|
// Set "this" rect to location 0,0
|
||||||
// as the Cloned Bitmap is only the part we want to work with
|
// as the Cloned Bitmap is only the part we want to work with
|
||||||
this.rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
|
this.rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
|
||||||
} else if (!ImageHelper.SupportsPixelFormat(sourceBmp) && PixelFormat.Format8bppIndexed != sourceBmp.PixelFormat) {
|
} else if (!ImageHelper.SupportsPixelFormat(sourceImage) && PixelFormat.Format8bppIndexed != sourceImage.PixelFormat) {
|
||||||
throw new ArgumentException("Unsupported pixel format: " + sourceBmp.PixelFormat + " set clone to true!");
|
throw new ArgumentException("Unsupported pixel format: " + sourceImage.PixelFormat + " set clone to true!");
|
||||||
} else {
|
} else {
|
||||||
this.bitmap = sourceBmp;
|
this.bitmap = sourceImage as Bitmap;
|
||||||
this.rect = sourceRect;
|
this.rect = sourceRect;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,9 @@ namespace GreenshotPlugin.Core {
|
||||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ClipboardHelper));
|
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ClipboardHelper));
|
||||||
private static readonly Object clipboardLockObject = new Object();
|
private static readonly Object clipboardLockObject = new Object();
|
||||||
private static readonly CoreConfiguration config = IniConfig.GetIniSection<CoreConfiguration>();
|
private static readonly CoreConfiguration config = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
|
private static readonly string FORMAT_FILECONTENTS = "FileContents";
|
||||||
|
private static readonly string FORMAT_JPG = "JPG";
|
||||||
|
private static readonly string FORMAT_PNG = "PNG";
|
||||||
private static IntPtr nextClipboardViewer = IntPtr.Zero;
|
private static IntPtr nextClipboardViewer = IntPtr.Zero;
|
||||||
// Template for the HTML Text on the clipboard
|
// Template for the HTML Text on the clipboard
|
||||||
// see: http://msdn.microsoft.com/en-us/library/ms649015%28v=vs.85%29.aspx
|
// see: http://msdn.microsoft.com/en-us/library/ms649015%28v=vs.85%29.aspx
|
||||||
|
@ -110,16 +113,6 @@ EndSelection:<<<<<<<4
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Wrapper for the SetDataObject with a bool "copy"
|
|
||||||
/// Default is true, the information on the clipboard will stay even if our application quits
|
|
||||||
/// For our own Types the other SetDataObject should be called with false.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ido"></param>
|
|
||||||
private static void SetDataObject(IDataObject ido) {
|
|
||||||
SetDataObject(ido, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The SetDataObject will lock/try/catch clipboard operations making it save and not show exceptions.
|
/// The SetDataObject will lock/try/catch clipboard operations making it save and not show exceptions.
|
||||||
/// The bool "copy" is used to decided if the information stays on the clipboard after exit.
|
/// The bool "copy" is used to decided if the information stays on the clipboard after exit.
|
||||||
|
@ -226,14 +219,26 @@ EndSelection:<<<<<<<4
|
||||||
|| dataObject.GetDataPresent(DataFormats.Dib)
|
|| dataObject.GetDataPresent(DataFormats.Dib)
|
||||||
|| dataObject.GetDataPresent(DataFormats.Tiff)
|
|| dataObject.GetDataPresent(DataFormats.Tiff)
|
||||||
|| dataObject.GetDataPresent(DataFormats.EnhancedMetafile)
|
|| dataObject.GetDataPresent(DataFormats.EnhancedMetafile)
|
||||||
|| dataObject.GetDataPresent("PNG")
|
|| dataObject.GetDataPresent(FORMAT_PNG)
|
||||||
|| dataObject.GetDataPresent("JPG")) {
|
|| dataObject.GetDataPresent(FORMAT_JPG)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
List<string> imageFiles = GetImageFilenames(dataObject);
|
List<string> imageFiles = GetImageFilenames(dataObject);
|
||||||
if (imageFiles != null && imageFiles.Count > 0) {
|
if (imageFiles != null && imageFiles.Count > 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (dataObject.GetDataPresent(FORMAT_FILECONTENTS)) {
|
||||||
|
try {
|
||||||
|
MemoryStream imageStream = dataObject.GetData(FORMAT_FILECONTENTS) as MemoryStream;
|
||||||
|
if (isValidStream(imageStream)) {
|
||||||
|
using (Image tmpImage = Image.FromStream(imageStream)) {
|
||||||
|
// If we get here, there is an image
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -253,25 +258,64 @@ EndSelection:<<<<<<<4
|
||||||
/// <returns>Image if there is an image on the clipboard</returns>
|
/// <returns>Image if there is an image on the clipboard</returns>
|
||||||
public static Image GetImage() {
|
public static Image GetImage() {
|
||||||
IDataObject clipboardData = GetDataObject();
|
IDataObject clipboardData = GetDataObject();
|
||||||
return GetImage(clipboardData);
|
// Return the first image
|
||||||
|
foreach (Image clipboardImage in GetImages(clipboardData)) {
|
||||||
|
return clipboardImage;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get an Image from the IDataObject
|
/// Get all images (multiple if filenames are available) from the dataObject
|
||||||
|
/// Returned images must be disposed by the calling code!
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dataObject"></param>
|
||||||
|
/// <returns>IEnumerable<Image></returns>
|
||||||
|
public static IEnumerable<Image> GetImages(IDataObject dataObject) {
|
||||||
|
Image tmpImage = null;
|
||||||
|
Image returnImage = null;
|
||||||
|
|
||||||
|
// Get single image, this takes the "best" match
|
||||||
|
tmpImage = GetImage(dataObject);
|
||||||
|
if (tmpImage != null) {
|
||||||
|
returnImage = ImageHelper.Clone(tmpImage);
|
||||||
|
// Clean up.
|
||||||
|
tmpImage.Dispose();
|
||||||
|
yield return returnImage;
|
||||||
|
} else {
|
||||||
|
// check if files are supplied
|
||||||
|
List<string> imageFiles = GetImageFilenames(dataObject);
|
||||||
|
if (imageFiles != null) {
|
||||||
|
foreach (string imageFile in imageFiles) {
|
||||||
|
try {
|
||||||
|
returnImage = ImageHelper.LoadImage(imageFile);
|
||||||
|
} catch (Exception streamImageEx) {
|
||||||
|
LOG.Error("Problem retrieving Image from clipboard.", streamImageEx);
|
||||||
|
}
|
||||||
|
if (returnImage != null) {
|
||||||
|
yield return returnImage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get an Image from the IDataObject, don't check for FileDrop
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dataObject"></param>
|
/// <param name="dataObject"></param>
|
||||||
/// <returns>Image or null</returns>
|
/// <returns>Image or null</returns>
|
||||||
public static Image GetImage(IDataObject dataObject) {
|
private static Image GetImage(IDataObject dataObject) {
|
||||||
if (dataObject != null) {
|
if (dataObject != null) {
|
||||||
IList<string> formats = GetFormats(dataObject);
|
IList<string> formats = GetFormats(dataObject);
|
||||||
try {
|
try {
|
||||||
MemoryStream imageStream = null;
|
MemoryStream imageStream = null;
|
||||||
|
|
||||||
if (!isValidStream(imageStream) && formats.Contains("PNG")) {
|
if (!isValidStream(imageStream) && formats.Contains(FORMAT_PNG)) {
|
||||||
imageStream = GetFromDataObject(dataObject, "PNG") as MemoryStream;
|
imageStream = GetFromDataObject(dataObject, FORMAT_PNG) as MemoryStream;
|
||||||
}
|
}
|
||||||
if (!isValidStream(imageStream) && formats.Contains("JPG")) {
|
if (!isValidStream(imageStream) && formats.Contains(FORMAT_JPG)) {
|
||||||
imageStream = GetFromDataObject(dataObject, "JPG") as MemoryStream;
|
imageStream = GetFromDataObject(dataObject, FORMAT_JPG) as MemoryStream;
|
||||||
}
|
}
|
||||||
if (!isValidStream(imageStream) && formats.Contains(DataFormats.Tiff)) {
|
if (!isValidStream(imageStream) && formats.Contains(DataFormats.Tiff)) {
|
||||||
imageStream = GetFromDataObject(dataObject, DataFormats.Tiff) as MemoryStream;
|
imageStream = GetFromDataObject(dataObject, DataFormats.Tiff) as MemoryStream;
|
||||||
|
@ -323,14 +367,16 @@ EndSelection:<<<<<<<4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<string> imageFiles = GetImageFilenames(dataObject);
|
|
||||||
if (imageFiles != null) {
|
// Support for FileContents
|
||||||
foreach (string imageFile in imageFiles) {
|
imageStream = dataObject.GetData(FORMAT_FILECONTENTS) as MemoryStream;
|
||||||
if (File.Exists(imageFile)) {
|
if (isValidStream(imageStream)) {
|
||||||
using (Stream imageFileStream = File.OpenRead(imageFile)) {
|
try {
|
||||||
return Image.FromStream(imageFileStream, true, true);
|
using (Image tmpImage = Image.FromStream(imageStream)) {
|
||||||
}
|
return ImageHelper.Clone(tmpImage);
|
||||||
}
|
}
|
||||||
|
} catch (Exception streamImageEx) {
|
||||||
|
LOG.Error("Problem retrieving Image from clipboard.", streamImageEx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception dibEx) {
|
} catch (Exception dibEx) {
|
||||||
|
@ -370,7 +416,7 @@ EndSelection:<<<<<<<4
|
||||||
public static void SetClipboardData(string text) {
|
public static void SetClipboardData(string text) {
|
||||||
IDataObject ido = new DataObject();
|
IDataObject ido = new DataObject();
|
||||||
ido.SetData(DataFormats.Text, true, text);
|
ido.SetData(DataFormats.Text, true, text);
|
||||||
SetDataObject(ido);
|
SetDataObject(ido, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string getHTMLString(ISurface surface, string filename) {
|
private static string getHTMLString(ISurface surface, string filename) {
|
||||||
|
@ -404,8 +450,8 @@ EndSelection:<<<<<<<4
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set an Image to the clipboard
|
/// Set an Image to the clipboard
|
||||||
/// This method will place 2 images to the clipboard, one of type Bitmap which
|
/// This method will place images to the clipboard depending on the ClipboardFormats setting.
|
||||||
/// works with pretty much everything and one of type Dib for e.g. OpenOffice
|
/// e.g. Bitmap which works with pretty much everything and type Dib for e.g. OpenOffice
|
||||||
/// because OpenOffice has a bug http://qa.openoffice.org/issues/show_bug.cgi?id=85661
|
/// because OpenOffice has a bug http://qa.openoffice.org/issues/show_bug.cgi?id=85661
|
||||||
/// The Dib (Device Indenpendend Bitmap) in 32bpp actually won't work with Powerpoint 2003!
|
/// The Dib (Device Indenpendend Bitmap) in 32bpp actually won't work with Powerpoint 2003!
|
||||||
/// When pasting a Dib in PP 2003 the Bitmap is somehow shifted left!
|
/// When pasting a Dib in PP 2003 the Bitmap is somehow shifted left!
|
||||||
|
@ -430,7 +476,7 @@ EndSelection:<<<<<<<4
|
||||||
ImageOutput.SaveToStream(surface, pngStream, pngOutputSettings);
|
ImageOutput.SaveToStream(surface, pngStream, pngOutputSettings);
|
||||||
pngStream.Seek(0, SeekOrigin.Begin);
|
pngStream.Seek(0, SeekOrigin.Begin);
|
||||||
// Set the PNG stream
|
// Set the PNG stream
|
||||||
ido.SetData("PNG", false, pngStream);
|
ido.SetData(FORMAT_PNG, false, pngStream);
|
||||||
}
|
}
|
||||||
} catch (Exception pngEX) {
|
} catch (Exception pngEX) {
|
||||||
LOG.Error("Error creating PNG for the Clipboard.", pngEX);
|
LOG.Error("Error creating PNG for the Clipboard.", pngEX);
|
||||||
|
@ -475,8 +521,17 @@ EndSelection:<<<<<<<4
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// we need to use the SetDataOject before the streams are closed otherwise the buffer will be gone!
|
// we need to use the SetDataOject before the streams are closed otherwise the buffer will be gone!
|
||||||
|
// Check if Bitmap is wanted
|
||||||
|
if (config.ClipboardFormats.Contains(ClipboardFormat.BITMAP)) {
|
||||||
|
using (Image tmpImage = surface.GetImageForExport()) {
|
||||||
|
ido.SetImage(tmpImage);
|
||||||
// Place the DataObject to the clipboard
|
// Place the DataObject to the clipboard
|
||||||
SetDataObject(ido);
|
SetDataObject(ido, true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Place the DataObject to the clipboard
|
||||||
|
SetDataObject(ido, true);
|
||||||
|
}
|
||||||
|
|
||||||
if (pngStream != null) {
|
if (pngStream != null) {
|
||||||
pngStream.Dispose();
|
pngStream.Dispose();
|
||||||
|
@ -608,16 +663,18 @@ EndSelection:<<<<<<<4
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static List<string> GetImageFilenames(IDataObject dataObject) {
|
public static List<string> GetImageFilenames(IDataObject dataObject) {
|
||||||
List<string> filenames = new List<string>();
|
List<string> filenames = new List<string>();
|
||||||
string[] dropFileNames = (string[])dataObject.GetData(DataFormats.FileDrop);
|
string[] dropFileNames = (string[]) dataObject.GetData(DataFormats.FileDrop);
|
||||||
|
try {
|
||||||
if (dropFileNames != null && dropFileNames.Length > 0) {
|
if (dropFileNames != null && dropFileNames.Length > 0) {
|
||||||
foreach (string filename in dropFileNames) {
|
foreach (string filename in dropFileNames) {
|
||||||
LOG.Debug("Found filename: " + filename);
|
|
||||||
string ext = Path.GetExtension(filename).ToLower();
|
string ext = Path.GetExtension(filename).ToLower();
|
||||||
if ((ext == ".jpg") || (ext == ".jpeg") || (ext == ".tiff") || (ext == ".gif") || (ext == ".png") || (ext == ".bmp") || (ext == ".ico") || (ext == ".wmf")) {
|
if ((ext == ".jpg") || (ext == ".jpeg") || (ext == ".tiff") || (ext == ".gif") || (ext == ".png") || (ext == ".bmp") || (ext == ".ico") || (ext == ".wmf")) {
|
||||||
filenames.Add(filename);
|
filenames.Add(filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
}
|
||||||
return filenames;
|
return filenames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ using Greenshot.Plugin;
|
||||||
|
|
||||||
namespace GreenshotPlugin.Core {
|
namespace GreenshotPlugin.Core {
|
||||||
public enum ClipboardFormat {
|
public enum ClipboardFormat {
|
||||||
PNG, DIB, HTML, HTMLDATAURL
|
PNG, DIB, HTML, HTMLDATAURL, BITMAP
|
||||||
}
|
}
|
||||||
public enum OutputFormat {
|
public enum OutputFormat {
|
||||||
bmp, gif, jpg, png, tiff, greenshot
|
bmp, gif, jpg, png, tiff, greenshot
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace Greenshot.Core {
|
||||||
/// Interface to describe an effect
|
/// Interface to describe an effect
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IEffect {
|
public interface IEffect {
|
||||||
Bitmap Apply(Bitmap sourceBitmap, out Point offsetChange);
|
Image Apply(Image sourceImage, out Point offsetChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -57,8 +57,8 @@ namespace Greenshot.Core {
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
public virtual Bitmap Apply(Bitmap sourceBitmap, out Point offsetChange) {
|
public virtual Image Apply(Image sourceImage, out Point offsetChange) {
|
||||||
return ImageHelper.CreateShadow(sourceBitmap, Darkness, ShadowSize, ShadowOffset, out offsetChange, PixelFormat.Format32bppArgb); //Image.PixelFormat);
|
return ImageHelper.CreateShadow(sourceImage, Darkness, ShadowSize, ShadowOffset, out offsetChange, PixelFormat.Format32bppArgb); //Image.PixelFormat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,8 +84,8 @@ namespace Greenshot.Core {
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
public override Bitmap Apply(Bitmap sourceBitmap, out Point offsetChange) {
|
public override Image Apply(Image sourceImage, out Point offsetChange) {
|
||||||
using (Bitmap tmpTornImage = ImageHelper.CreateTornEdge(sourceBitmap, ToothHeight, HorizontalToothRange, VerticalToothRange)) {
|
using (Image tmpTornImage = ImageHelper.CreateTornEdge(sourceImage, ToothHeight, HorizontalToothRange, VerticalToothRange)) {
|
||||||
return ImageHelper.CreateShadow(tmpTornImage, Darkness, ShadowSize, ShadowOffset, out offsetChange, PixelFormat.Format32bppArgb);
|
return ImageHelper.CreateShadow(tmpTornImage, Darkness, ShadowSize, ShadowOffset, out offsetChange, PixelFormat.Format32bppArgb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,9 +95,9 @@ namespace Greenshot.Core {
|
||||||
/// GrayscaleEffect
|
/// GrayscaleEffect
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GrayscaleEffect : IEffect {
|
public class GrayscaleEffect : IEffect {
|
||||||
public Bitmap Apply(Bitmap sourceBitmap, out Point offsetChange) {
|
public Image Apply(Image sourceImage, out Point offsetChange) {
|
||||||
offsetChange = Point.Empty;
|
offsetChange = Point.Empty;
|
||||||
return ImageHelper.CreateGrayscale(sourceBitmap);
|
return ImageHelper.CreateGrayscale(sourceImage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,9 +105,9 @@ namespace Greenshot.Core {
|
||||||
/// InvertEffect
|
/// InvertEffect
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class InvertEffect : IEffect {
|
public class InvertEffect : IEffect {
|
||||||
public Bitmap Apply(Bitmap sourceBitmap, out Point offsetChange) {
|
public Image Apply(Image sourceImage, out Point offsetChange) {
|
||||||
offsetChange = Point.Empty;
|
offsetChange = Point.Empty;
|
||||||
return ImageHelper.CreateNegative(sourceBitmap);
|
return ImageHelper.CreateNegative(sourceImage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,8 +127,8 @@ namespace Greenshot.Core {
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
public Bitmap Apply(Bitmap sourceBitmap, out Point offsetChange) {
|
public Image Apply(Image sourceImage, out Point offsetChange) {
|
||||||
return ImageHelper.CreateBorder(sourceBitmap, Width, Color, sourceBitmap.PixelFormat, out offsetChange);
|
return ImageHelper.CreateBorder(sourceImage, Width, Color, sourceImage.PixelFormat, out offsetChange);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ namespace Greenshot.Core {
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
public Bitmap Apply(Bitmap sourceBitmap, out Point offsetChange) {
|
public Image Apply(Image sourceImage, out Point offsetChange) {
|
||||||
offsetChange = Point.Empty;
|
offsetChange = Point.Empty;
|
||||||
RotateFlipType flipType;
|
RotateFlipType flipType;
|
||||||
if (Angle == 90) {
|
if (Angle == 90) {
|
||||||
|
@ -153,7 +153,7 @@ namespace Greenshot.Core {
|
||||||
} else {
|
} else {
|
||||||
throw new NotSupportedException("Currently only an angle of 90 or -90 (270) is supported.");
|
throw new NotSupportedException("Currently only an angle of 90 or -90 (270) is supported.");
|
||||||
}
|
}
|
||||||
return ImageHelper.RotateFlip(sourceBitmap, flipType);
|
return ImageHelper.RotateFlip(sourceImage, flipType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,9 +178,9 @@ namespace Greenshot.Core {
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
public Bitmap Apply(Bitmap sourceBitmap, out Point offsetChange) {
|
public Image Apply(Image sourceImage, out Point offsetChange) {
|
||||||
offsetChange = Point.Empty;
|
offsetChange = Point.Empty;
|
||||||
return ImageHelper.ResizeBitmap(sourceBitmap, MaintainAspectRatio, Width, Height);
|
return ImageHelper.ResizeImage(sourceImage, MaintainAspectRatio, Width, Height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,10 +215,10 @@ namespace Greenshot.Core {
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
public Bitmap Apply(Bitmap sourceBitmap, out Point offsetChange) {
|
public Image Apply(Image sourceImage, out Point offsetChange) {
|
||||||
// Make sure the elements move according to the offset the effect made the bitmap move
|
// Make sure the elements move according to the offset the effect made the bitmap move
|
||||||
offsetChange = new Point(Left, Top);
|
offsetChange = new Point(Left, Top);
|
||||||
return ImageHelper.ResizeCanvas(sourceBitmap, BackgroundColor, Left, Right, Top, Bottom);
|
return ImageHelper.ResizeCanvas(sourceImage, BackgroundColor, Left, Right, Top, Bottom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -193,11 +193,14 @@ namespace GreenshotPlugin.Core {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename"></param>
|
/// <param name="filename"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static Bitmap LoadBitmap(string filename) {
|
public static Image LoadImage(string filename) {
|
||||||
if (string.IsNullOrEmpty(filename)) {
|
if (string.IsNullOrEmpty(filename)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Bitmap fileBitmap = null;
|
if (!File.Exists(filename)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Image fileImage = null;
|
||||||
LOG.InfoFormat("Loading image from file {0}", filename);
|
LOG.InfoFormat("Loading image from file {0}", filename);
|
||||||
// Fixed lock problem Bug #3431881
|
// Fixed lock problem Bug #3431881
|
||||||
using (Stream imageFileStream = File.OpenRead(filename)) {
|
using (Stream imageFileStream = File.OpenRead(filename)) {
|
||||||
|
@ -209,20 +212,20 @@ namespace GreenshotPlugin.Core {
|
||||||
try {
|
try {
|
||||||
using (Image tmpImage = ExtractVistaIcon(imageFileStream)) {
|
using (Image tmpImage = ExtractVistaIcon(imageFileStream)) {
|
||||||
if (tmpImage != null) {
|
if (tmpImage != null) {
|
||||||
fileBitmap = Clone(tmpImage);
|
fileImage = Clone(tmpImage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception vistaIconException) {
|
} catch (Exception vistaIconException) {
|
||||||
LOG.Warn("Can't read icon from " + filename, vistaIconException);
|
LOG.Warn("Can't read icon from " + filename, vistaIconException);
|
||||||
}
|
}
|
||||||
if (fileBitmap == null) {
|
if (fileImage == null) {
|
||||||
try {
|
try {
|
||||||
// No vista icon, try normal icon
|
// No vista icon, try normal icon
|
||||||
imageFileStream.Position = 0;
|
imageFileStream.Position = 0;
|
||||||
// We create a copy of the bitmap, so everything else can be disposed
|
// We create a copy of the bitmap, so everything else can be disposed
|
||||||
using (Icon tmpIcon = new Icon(imageFileStream, new Size(1024,1024))) {
|
using (Icon tmpIcon = new Icon(imageFileStream, new Size(1024,1024))) {
|
||||||
using (Image tmpImage = tmpIcon.ToBitmap()) {
|
using (Image tmpImage = tmpIcon.ToBitmap()) {
|
||||||
fileBitmap = Clone(tmpImage);
|
fileImage = Clone(tmpImage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception iconException) {
|
} catch (Exception iconException) {
|
||||||
|
@ -230,19 +233,19 @@ namespace GreenshotPlugin.Core {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fileBitmap == null) {
|
if (fileImage == null) {
|
||||||
// We create a copy of the bitmap, so everything else can be disposed
|
// We create a copy of the bitmap, so everything else can be disposed
|
||||||
imageFileStream.Position = 0;
|
imageFileStream.Position = 0;
|
||||||
using (Image tmpImage = Image.FromStream(imageFileStream, true, true)) {
|
using (Image tmpImage = Image.FromStream(imageFileStream, true, true)) {
|
||||||
LOG.DebugFormat("Loaded {0} with Size {1}x{2} and PixelFormat {3}", filename, tmpImage.Width, tmpImage.Height, tmpImage.PixelFormat);
|
LOG.DebugFormat("Loaded {0} with Size {1}x{2} and PixelFormat {3}", filename, tmpImage.Width, tmpImage.Height, tmpImage.PixelFormat);
|
||||||
fileBitmap = Clone(tmpImage);
|
fileImage = Clone(tmpImage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fileBitmap != null) {
|
if (fileImage != null) {
|
||||||
LOG.InfoFormat("Information about file {0}: {1}x{2}-{3} Resolution {4}x{5}", filename, fileBitmap.Width, fileBitmap.Height, fileBitmap.PixelFormat, fileBitmap.HorizontalResolution, fileBitmap.VerticalResolution);
|
LOG.InfoFormat("Information about file {0}: {1}x{2}-{3} Resolution {4}x{5}", filename, fileImage.Width, fileImage.Height, fileImage.PixelFormat, fileImage.HorizontalResolution, fileImage.VerticalResolution);
|
||||||
}
|
}
|
||||||
return fileBitmap;
|
return fileImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -336,10 +339,10 @@ namespace GreenshotPlugin.Core {
|
||||||
/// <param name="sourceBitmap">Bitmap</param>
|
/// <param name="sourceBitmap">Bitmap</param>
|
||||||
/// <param name="effect">IEffect</param>
|
/// <param name="effect">IEffect</param>
|
||||||
/// <returns>Bitmap</returns>
|
/// <returns>Bitmap</returns>
|
||||||
public static Bitmap ApplyEffect(Bitmap sourceBitmap, IEffect effect, out Point offset) {
|
public static Image ApplyEffect(Image sourceImage, IEffect effect, out Point offset) {
|
||||||
List<IEffect> effects = new List<IEffect>();
|
List<IEffect> effects = new List<IEffect>();
|
||||||
effects.Add(effect);
|
effects.Add(effect);
|
||||||
return ApplyEffects(sourceBitmap, effects, out offset);
|
return ApplyEffects(sourceImage, effects, out offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -348,40 +351,40 @@ namespace GreenshotPlugin.Core {
|
||||||
/// <param name="sourceBitmap">Bitmap</param>
|
/// <param name="sourceBitmap">Bitmap</param>
|
||||||
/// <param name="effects">List<IEffect></param>
|
/// <param name="effects">List<IEffect></param>
|
||||||
/// <returns>Bitmap</returns>
|
/// <returns>Bitmap</returns>
|
||||||
public static Bitmap ApplyEffects(Bitmap sourceBitmap, List<IEffect> effects, out Point offset) {
|
public static Image ApplyEffects(Image sourceImage, List<IEffect> effects, out Point offset) {
|
||||||
Bitmap currentBitmap = sourceBitmap;
|
Image currentImage = sourceImage;
|
||||||
bool disposeImage = false;
|
bool disposeImage = false;
|
||||||
// Default out value for the offset, will be modified there where needed
|
// Default out value for the offset, will be modified there where needed
|
||||||
offset = new Point(0, 0);
|
offset = new Point(0, 0);
|
||||||
Point tmpPoint;
|
Point tmpPoint;
|
||||||
Bitmap tmpBitmap = null;
|
Image tmpImage = null;
|
||||||
foreach (IEffect effect in effects) {
|
foreach (IEffect effect in effects) {
|
||||||
tmpBitmap = effect.Apply(currentBitmap, out tmpPoint);
|
tmpImage = effect.Apply(currentImage, out tmpPoint);
|
||||||
offset.Offset(tmpPoint);
|
offset.Offset(tmpPoint);
|
||||||
if (disposeImage) {
|
if (disposeImage) {
|
||||||
currentBitmap.Dispose();
|
currentImage.Dispose();
|
||||||
}
|
}
|
||||||
currentBitmap = tmpBitmap;
|
currentImage = tmpImage;
|
||||||
// Make sure the "new" image is disposed
|
// Make sure the "new" image is disposed
|
||||||
disposeImage = true;
|
disposeImage = true;
|
||||||
}
|
}
|
||||||
return tmpBitmap;
|
return tmpImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Make the picture look like it's torn
|
/// Make the picture look like it's torn
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sourceBitmap">Bitmap to make torn edge off</param>
|
/// <param name="sourceImage">Bitmap to make torn edge off</param>
|
||||||
/// <param name="toothHeight">How large (height) is each tooth</param>
|
/// <param name="toothHeight">How large (height) is each tooth</param>
|
||||||
/// <param name="horizontalToothRange">How wide is a horizontal tooth</param>
|
/// <param name="horizontalToothRange">How wide is a horizontal tooth</param>
|
||||||
/// <param name="verticalToothRange">How wide is a vertical tooth</param>
|
/// <param name="verticalToothRange">How wide is a vertical tooth</param>
|
||||||
/// <returns>Changed bitmap</returns>
|
/// <returns>Changed bitmap</returns>
|
||||||
public static Bitmap CreateTornEdge(Bitmap sourceBitmap, int toothHeight, int horizontalToothRange, int verticalToothRange) {
|
public static Image CreateTornEdge(Image sourceImage, int toothHeight, int horizontalToothRange, int verticalToothRange) {
|
||||||
Bitmap returnImage = CreateEmpty(sourceBitmap.Width, sourceBitmap.Height, PixelFormat.Format32bppArgb, Color.Empty, sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution);
|
Image returnImage = CreateEmpty(sourceImage.Width, sourceImage.Height, PixelFormat.Format32bppArgb, Color.Empty, sourceImage.HorizontalResolution, sourceImage.VerticalResolution);
|
||||||
using (GraphicsPath path = new GraphicsPath()) {
|
using (GraphicsPath path = new GraphicsPath()) {
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
int HorizontalRegions = (int)(sourceBitmap.Width / horizontalToothRange);
|
int HorizontalRegions = (int)(sourceImage.Width / horizontalToothRange);
|
||||||
int VerticalRegions = (int)(sourceBitmap.Height / verticalToothRange);
|
int VerticalRegions = (int)(sourceImage.Height / verticalToothRange);
|
||||||
|
|
||||||
// Start
|
// Start
|
||||||
Point previousEndingPoint = new Point(horizontalToothRange, random.Next(1, toothHeight));
|
Point previousEndingPoint = new Point(horizontalToothRange, random.Next(1, toothHeight));
|
||||||
|
@ -397,7 +400,7 @@ namespace GreenshotPlugin.Core {
|
||||||
|
|
||||||
// Right
|
// Right
|
||||||
for (int i = 0; i < VerticalRegions; i++) {
|
for (int i = 0; i < VerticalRegions; i++) {
|
||||||
int x = sourceBitmap.Width - random.Next(1, toothHeight);
|
int x = sourceImage.Width - random.Next(1, toothHeight);
|
||||||
int y = (int)previousEndingPoint.Y + verticalToothRange;
|
int y = (int)previousEndingPoint.Y + verticalToothRange;
|
||||||
newEndingPoint = new Point(x, y);
|
newEndingPoint = new Point(x, y);
|
||||||
path.AddLine(previousEndingPoint, newEndingPoint);
|
path.AddLine(previousEndingPoint, newEndingPoint);
|
||||||
|
@ -407,7 +410,7 @@ namespace GreenshotPlugin.Core {
|
||||||
// Bottom
|
// Bottom
|
||||||
for (int i = 0; i < HorizontalRegions; i++) {
|
for (int i = 0; i < HorizontalRegions; i++) {
|
||||||
int x = (int)previousEndingPoint.X - horizontalToothRange;
|
int x = (int)previousEndingPoint.X - horizontalToothRange;
|
||||||
int y = sourceBitmap.Height - random.Next(1, toothHeight);
|
int y = sourceImage.Height - random.Next(1, toothHeight);
|
||||||
newEndingPoint = new Point(x, y);
|
newEndingPoint = new Point(x, y);
|
||||||
path.AddLine(previousEndingPoint, newEndingPoint);
|
path.AddLine(previousEndingPoint, newEndingPoint);
|
||||||
previousEndingPoint = newEndingPoint;
|
previousEndingPoint = newEndingPoint;
|
||||||
|
@ -429,7 +432,7 @@ namespace GreenshotPlugin.Core {
|
||||||
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||||
graphics.CompositingQuality = CompositingQuality.HighQuality;
|
graphics.CompositingQuality = CompositingQuality.HighQuality;
|
||||||
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||||
using (Brush brush = new TextureBrush(sourceBitmap)) {
|
using (Brush brush = new TextureBrush(sourceImage)) {
|
||||||
// Imporant note: If the target wouldn't be at 0,0 we need to translate-transform!!
|
// Imporant note: If the target wouldn't be at 0,0 we need to translate-transform!!
|
||||||
graphics.FillPath(brush, path);
|
graphics.FillPath(brush, path);
|
||||||
}
|
}
|
||||||
|
@ -948,10 +951,10 @@ namespace GreenshotPlugin.Core {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return negative of Bitmap
|
/// Return negative of Bitmap
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sourceBitmap">Bitmap to create a negative off</param>
|
/// <param name="sourceImage">Bitmap to create a negative off</param>
|
||||||
/// <returns>Negative bitmap</returns>
|
/// <returns>Negative bitmap</returns>
|
||||||
public static Bitmap CreateNegative(Bitmap sourceBitmap) {
|
public static Bitmap CreateNegative(Image sourceImage) {
|
||||||
using (BitmapBuffer bb = new BitmapBuffer(sourceBitmap, true)) {
|
using (BitmapBuffer bb = new BitmapBuffer(sourceImage, true)) {
|
||||||
bb.Lock();
|
bb.Lock();
|
||||||
for (int y = 0; y < bb.Height; y++) {
|
for (int y = 0; y < bb.Height; y++) {
|
||||||
for (int x = 0; x < bb.Width; x++) {
|
for (int x = 0; x < bb.Width; x++) {
|
||||||
|
@ -968,18 +971,18 @@ namespace GreenshotPlugin.Core {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new bitmap where the sourceBitmap has a Simple border around it
|
/// Create a new bitmap where the sourceBitmap has a Simple border around it
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sourceBitmap">Bitmap to make a border on</param>
|
/// <param name="sourceImage">Bitmap to make a border on</param>
|
||||||
/// <param name="borderSize">Size of the border</param>
|
/// <param name="borderSize">Size of the border</param>
|
||||||
/// <param name="borderColor">Color of the border</param>
|
/// <param name="borderColor">Color of the border</param>
|
||||||
/// <param name="targetPixelformat">What pixel format must the returning bitmap have</param>
|
/// <param name="targetPixelformat">What pixel format must the returning bitmap have</param>
|
||||||
/// <param name="offset">How many pixels is the original image moved?</param>
|
/// <param name="offset">How many pixels is the original image moved?</param>
|
||||||
/// <returns>Bitmap with the shadow, is bigger than the sourceBitmap!!</returns>
|
/// <returns>Bitmap with the shadow, is bigger than the sourceBitmap!!</returns>
|
||||||
public static Bitmap CreateBorder(Bitmap sourceBitmap, int borderSize, Color borderColor, PixelFormat targetPixelformat, out Point offset) {
|
public static Image CreateBorder(Image sourceImage, int borderSize, Color borderColor, PixelFormat targetPixelformat, out Point offset) {
|
||||||
// "return" the shifted offset, so the caller can e.g. move elements
|
// "return" the shifted offset, so the caller can e.g. move elements
|
||||||
offset = new Point(borderSize, borderSize);
|
offset = new Point(borderSize, borderSize);
|
||||||
|
|
||||||
// Create a new "clean" image
|
// Create a new "clean" image
|
||||||
Bitmap newImage = CreateEmpty(sourceBitmap.Width + (borderSize * 2), sourceBitmap.Height + (borderSize * 2), targetPixelformat, Color.Empty, sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution);
|
Bitmap newImage = CreateEmpty(sourceImage.Width + (borderSize * 2), sourceImage.Height + (borderSize * 2), targetPixelformat, Color.Empty, sourceImage.HorizontalResolution, sourceImage.VerticalResolution);
|
||||||
using (Graphics graphics = Graphics.FromImage(newImage)) {
|
using (Graphics graphics = Graphics.FromImage(newImage)) {
|
||||||
// Make sure we draw with the best quality!
|
// Make sure we draw with the best quality!
|
||||||
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
||||||
|
@ -996,10 +999,10 @@ namespace GreenshotPlugin.Core {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// draw original with a TextureBrush so we have nice antialiasing!
|
// draw original with a TextureBrush so we have nice antialiasing!
|
||||||
using (Brush textureBrush = new TextureBrush(sourceBitmap, WrapMode.Clamp)) {
|
using (Brush textureBrush = new TextureBrush(sourceImage, WrapMode.Clamp)) {
|
||||||
// We need to do a translate-tranform otherwise the image is wrapped
|
// We need to do a translate-tranform otherwise the image is wrapped
|
||||||
graphics.TranslateTransform(offset.X, offset.Y);
|
graphics.TranslateTransform(offset.X, offset.Y);
|
||||||
graphics.FillRectangle(textureBrush, 0, 0, sourceBitmap.Width, sourceBitmap.Height);
|
graphics.FillRectangle(textureBrush, 0, 0, sourceImage.Width, sourceImage.Height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return newImage;
|
return newImage;
|
||||||
|
@ -1008,12 +1011,12 @@ namespace GreenshotPlugin.Core {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new bitmap where the sourceBitmap is in grayscale
|
/// Create a new bitmap where the sourceBitmap is in grayscale
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sourceBitmap">Original bitmap</param>
|
/// <param name="sourceImage">Original bitmap</param>
|
||||||
/// <returns>Bitmap with grayscale</returns>
|
/// <returns>Bitmap with grayscale</returns>
|
||||||
public static Bitmap CreateGrayscale(Bitmap sourceBitmap) {
|
public static Image CreateGrayscale(Image sourceImage) {
|
||||||
//create a blank bitmap the same size as original
|
//create a blank bitmap the same size as original
|
||||||
// If using 8bpp than the following exception comes: A Graphics object cannot be created from an image that has an indexed pixel format.
|
// If using 8bpp than the following exception comes: A Graphics object cannot be created from an image that has an indexed pixel format.
|
||||||
Bitmap newBitmap = CreateEmpty(sourceBitmap.Width, sourceBitmap.Height, PixelFormat.Format24bppRgb, Color.Empty, sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution);
|
Bitmap newBitmap = CreateEmpty(sourceImage.Width, sourceImage.Height, PixelFormat.Format24bppRgb, Color.Empty, sourceImage.HorizontalResolution, sourceImage.VerticalResolution);
|
||||||
//ColorPalette imagePalette = newBitmap.Palette;
|
//ColorPalette imagePalette = newBitmap.Palette;
|
||||||
//for (int i = 0; i <= 255; i++) {
|
//for (int i = 0; i <= 255; i++) {
|
||||||
// // create greyscale color table
|
// // create greyscale color table
|
||||||
|
@ -1040,7 +1043,7 @@ namespace GreenshotPlugin.Core {
|
||||||
attributes.SetColorMatrix(colorMatrix);
|
attributes.SetColorMatrix(colorMatrix);
|
||||||
|
|
||||||
//draw the original image on the new image using the grayscale color matrix
|
//draw the original image on the new image using the grayscale color matrix
|
||||||
graphics.DrawImage(sourceBitmap, new Rectangle(0, 0, sourceBitmap.Width, sourceBitmap.Height), 0, 0, sourceBitmap.Width, sourceBitmap.Height, GraphicsUnit.Pixel, attributes);
|
graphics.DrawImage(sourceImage, new Rectangle(0, 0, sourceImage.Width, sourceImage.Height), 0, 0, sourceImage.Width, sourceImage.Height, GraphicsUnit.Pixel, attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
return newBitmap;
|
return newBitmap;
|
||||||
|
@ -1049,10 +1052,10 @@ namespace GreenshotPlugin.Core {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if the supplied Bitmap has a PixelFormat we support
|
/// Checks if the supplied Bitmap has a PixelFormat we support
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="bitmap">bitmap to check</param>
|
/// <param name="image">bitmap to check</param>
|
||||||
/// <returns>bool if we support it</returns>
|
/// <returns>bool if we support it</returns>
|
||||||
public static bool SupportsPixelFormat(Bitmap bitmap) {
|
public static bool SupportsPixelFormat(Image image) {
|
||||||
return SupportsPixelFormat(bitmap.PixelFormat);
|
return SupportsPixelFormat(image.PixelFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1070,11 +1073,15 @@ namespace GreenshotPlugin.Core {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Wrapper for just cloning which calls the CloneArea
|
/// Wrapper for just cloning which calls the CloneArea
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sourceBitmap">Image to clone</param>
|
/// <param name="sourceImage">Image to clone</param>
|
||||||
/// <returns>Bitmap with clone image data</returns>
|
/// <returns>Bitmap with clone image data</returns>
|
||||||
public static Bitmap Clone(Image sourceBitmap) {
|
public static Image Clone(Image sourceImage) {
|
||||||
return CloneArea(sourceBitmap, Rectangle.Empty, PixelFormat.DontCare);
|
if (sourceImage is Metafile) {
|
||||||
|
return (Image)sourceImage.Clone();
|
||||||
}
|
}
|
||||||
|
return CloneArea(sourceImage, Rectangle.Empty, PixelFormat.DontCare);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Wrapper for just cloning & TargetFormat which calls the CloneArea
|
/// Wrapper for just cloning & TargetFormat which calls the CloneArea
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1092,24 +1099,24 @@ namespace GreenshotPlugin.Core {
|
||||||
/// a quick workaround is using new Bitmap which uses a default of Format32bppArgb
|
/// a quick workaround is using new Bitmap which uses a default of Format32bppArgb
|
||||||
/// 2) When going from a transparent to a non transparent bitmap, we draw the background white!
|
/// 2) When going from a transparent to a non transparent bitmap, we draw the background white!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sourceBitmap">Source bitmap to clone</param>
|
/// <param name="sourceImage">Source bitmap to clone</param>
|
||||||
/// <param name="sourceRect">Rectangle to copy from the source, use Rectangle.Empty for all</param>
|
/// <param name="sourceRect">Rectangle to copy from the source, use Rectangle.Empty for all</param>
|
||||||
/// <param name="targetFormat">Target Format, use PixelFormat.DontCare if you want the original (or a default if the source PixelFormat is not supported)</param>
|
/// <param name="targetFormat">Target Format, use PixelFormat.DontCare if you want the original (or a default if the source PixelFormat is not supported)</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static Bitmap CloneArea(Image sourceBitmap, Rectangle sourceRect, PixelFormat targetFormat) {
|
public static Bitmap CloneArea(Image sourceImage, Rectangle sourceRect, PixelFormat targetFormat) {
|
||||||
Bitmap newImage = null;
|
Bitmap newImage = null;
|
||||||
Rectangle bitmapRect = new Rectangle(0, 0, sourceBitmap.Width, sourceBitmap.Height);
|
Rectangle bitmapRect = new Rectangle(0, 0, sourceImage.Width, sourceImage.Height);
|
||||||
|
|
||||||
// Make sure the source is not Rectangle.Empty
|
// Make sure the source is not Rectangle.Empty
|
||||||
if (Rectangle.Empty.Equals(sourceRect)) {
|
if (Rectangle.Empty.Equals(sourceRect)) {
|
||||||
sourceRect = new Rectangle(0, 0, sourceBitmap.Width, sourceBitmap.Height);
|
sourceRect = new Rectangle(0, 0, sourceImage.Width, sourceImage.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no pixelformat is supplied
|
// If no pixelformat is supplied
|
||||||
if (PixelFormat.DontCare == targetFormat || PixelFormat.Undefined == targetFormat) {
|
if (PixelFormat.DontCare == targetFormat || PixelFormat.Undefined == targetFormat) {
|
||||||
if (SupportsPixelFormat(sourceBitmap.PixelFormat)) {
|
if (SupportsPixelFormat(sourceImage.PixelFormat)) {
|
||||||
targetFormat = sourceBitmap.PixelFormat;
|
targetFormat = sourceImage.PixelFormat;
|
||||||
} else if (Image.IsAlphaPixelFormat(sourceBitmap.PixelFormat)) {
|
} else if (Image.IsAlphaPixelFormat(sourceImage.PixelFormat)) {
|
||||||
targetFormat = PixelFormat.Format32bppArgb;
|
targetFormat = PixelFormat.Format32bppArgb;
|
||||||
} else {
|
} else {
|
||||||
targetFormat = PixelFormat.Format24bppRgb;
|
targetFormat = PixelFormat.Format24bppRgb;
|
||||||
|
@ -1126,15 +1133,15 @@ namespace GreenshotPlugin.Core {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool destinationIsTransparent = Image.IsAlphaPixelFormat(targetFormat);
|
bool destinationIsTransparent = Image.IsAlphaPixelFormat(targetFormat);
|
||||||
bool sourceIsTransparent = Image.IsAlphaPixelFormat(sourceBitmap.PixelFormat);
|
bool sourceIsTransparent = Image.IsAlphaPixelFormat(sourceImage.PixelFormat);
|
||||||
bool fromTransparentToNon = !destinationIsTransparent && sourceIsTransparent;
|
bool fromTransparentToNon = !destinationIsTransparent && sourceIsTransparent;
|
||||||
bool isBitmap = sourceBitmap is Bitmap;
|
bool isBitmap = sourceImage is Bitmap;
|
||||||
bool isAreaEqual = sourceRect.Equals(bitmapRect);
|
bool isAreaEqual = sourceRect.Equals(bitmapRect);
|
||||||
if (isAreaEqual || fromTransparentToNon || !isBitmap) {
|
if (isAreaEqual || fromTransparentToNon || !isBitmap) {
|
||||||
// Rule 1: if the areas are equal, always copy ourselves
|
// Rule 1: if the areas are equal, always copy ourselves
|
||||||
newImage = new Bitmap(bitmapRect.Width, bitmapRect.Height, targetFormat);
|
newImage = new Bitmap(bitmapRect.Width, bitmapRect.Height, targetFormat);
|
||||||
// Make sure both images have the same resolution
|
// Make sure both images have the same resolution
|
||||||
newImage.SetResolution(sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution);
|
newImage.SetResolution(sourceImage.HorizontalResolution, sourceImage.VerticalResolution);
|
||||||
|
|
||||||
using (Graphics graphics = Graphics.FromImage(newImage)) {
|
using (Graphics graphics = Graphics.FromImage(newImage)) {
|
||||||
if (fromTransparentToNon) {
|
if (fromTransparentToNon) {
|
||||||
|
@ -1143,16 +1150,16 @@ namespace GreenshotPlugin.Core {
|
||||||
}
|
}
|
||||||
// decide fastest copy method
|
// decide fastest copy method
|
||||||
if (isAreaEqual) {
|
if (isAreaEqual) {
|
||||||
graphics.DrawImageUnscaled(sourceBitmap, 0, 0);
|
graphics.DrawImageUnscaled(sourceImage, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
graphics.DrawImage(sourceBitmap, 0, 0, sourceRect, GraphicsUnit.Pixel);
|
graphics.DrawImage(sourceImage, 0, 0, sourceRect, GraphicsUnit.Pixel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Let GDI+ decide how to convert, need to test what is quicker...
|
// Let GDI+ decide how to convert, need to test what is quicker...
|
||||||
newImage = (sourceBitmap as Bitmap).Clone(sourceRect, targetFormat);
|
newImage = (sourceImage as Bitmap).Clone(sourceRect, targetFormat);
|
||||||
// Make sure both images have the same resolution
|
// Make sure both images have the same resolution
|
||||||
newImage.SetResolution(sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution);
|
newImage.SetResolution(sourceImage.HorizontalResolution, sourceImage.VerticalResolution);
|
||||||
}
|
}
|
||||||
return newImage;
|
return newImage;
|
||||||
}
|
}
|
||||||
|
@ -1160,27 +1167,27 @@ namespace GreenshotPlugin.Core {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Rotate the bitmap
|
/// Rotate the bitmap
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sourceBitmap"></param>
|
/// <param name="sourceImage"></param>
|
||||||
/// <param name="rotateFlipType"></param>
|
/// <param name="rotateFlipType"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static Bitmap RotateFlip(Bitmap sourceBitmap, RotateFlipType rotateFlipType) {
|
public static Image RotateFlip(Image sourceImage, RotateFlipType rotateFlipType) {
|
||||||
Bitmap returnBitmap = Clone(sourceBitmap);
|
Image returnImage = Clone(sourceImage);
|
||||||
returnBitmap.RotateFlip(rotateFlipType);
|
returnImage.RotateFlip(rotateFlipType);
|
||||||
return returnBitmap;
|
return returnImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A generic way to create an empty image
|
/// A generic way to create an empty image
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sourceBitmap">the source bitmap as the specifications for the new bitmap</param>
|
/// <param name="sourceImage">the source bitmap as the specifications for the new bitmap</param>
|
||||||
/// <param name="backgroundColor">The color to fill with, or Color.Empty to take the default depending on the pixel format</param>
|
/// <param name="backgroundColor">The color to fill with, or Color.Empty to take the default depending on the pixel format</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static Bitmap CreateEmptyLike(Bitmap sourceBitmap, Color backgroundColor) {
|
public static Bitmap CreateEmptyLike(Image sourceImage, Color backgroundColor) {
|
||||||
PixelFormat pixelFormat = sourceBitmap.PixelFormat;
|
PixelFormat pixelFormat = sourceImage.PixelFormat;
|
||||||
if (backgroundColor.A < 255) {
|
if (backgroundColor.A < 255) {
|
||||||
pixelFormat = PixelFormat.Format32bppArgb;
|
pixelFormat = PixelFormat.Format32bppArgb;
|
||||||
}
|
}
|
||||||
return CreateEmpty(sourceBitmap.Width, sourceBitmap.Height, pixelFormat, backgroundColor, sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution);
|
return CreateEmpty(sourceImage.Width, sourceImage.Height, pixelFormat, backgroundColor, sourceImage.HorizontalResolution, sourceImage.VerticalResolution);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1236,17 +1243,17 @@ namespace GreenshotPlugin.Core {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Resize canvas with pixel to the left, right, top and bottom
|
/// Resize canvas with pixel to the left, right, top and bottom
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sourceBitmap"></param>
|
/// <param name="sourceImage"></param>
|
||||||
/// <param name="backgroundColor">The color to fill with, or Color.Empty to take the default depending on the pixel format</param>
|
/// <param name="backgroundColor">The color to fill with, or Color.Empty to take the default depending on the pixel format</param>
|
||||||
/// <param name="left"></param>
|
/// <param name="left"></param>
|
||||||
/// <param name="right"></param>
|
/// <param name="right"></param>
|
||||||
/// <param name="top"></param>
|
/// <param name="top"></param>
|
||||||
/// <param name="bottom"></param>
|
/// <param name="bottom"></param>
|
||||||
/// <returns>a new bitmap with the source copied on it</returns>
|
/// <returns>a new bitmap with the source copied on it</returns>
|
||||||
public static Bitmap ResizeCanvas(Bitmap sourceBitmap, Color backgroundColor, int left, int right, int top, int bottom) {
|
public static Image ResizeCanvas(Image sourceImage, Color backgroundColor, int left, int right, int top, int bottom) {
|
||||||
Bitmap newBitmap = CreateEmpty(sourceBitmap.Width + left + right, sourceBitmap.Height + top + bottom, sourceBitmap.PixelFormat, backgroundColor, sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution);
|
Bitmap newBitmap = CreateEmpty(sourceImage.Width + left + right, sourceImage.Height + top + bottom, sourceImage.PixelFormat, backgroundColor, sourceImage.HorizontalResolution, sourceImage.VerticalResolution);
|
||||||
using (Graphics graphics = Graphics.FromImage(newBitmap)) {
|
using (Graphics graphics = Graphics.FromImage(newBitmap)) {
|
||||||
graphics.DrawImageUnscaled(sourceBitmap, left, top);
|
graphics.DrawImageUnscaled(sourceImage, left, top);
|
||||||
}
|
}
|
||||||
return newBitmap;
|
return newBitmap;
|
||||||
}
|
}
|
||||||
|
@ -1254,30 +1261,30 @@ namespace GreenshotPlugin.Core {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Wrapper for the more complex Resize, this resize could be used for e.g. Thumbnails
|
/// Wrapper for the more complex Resize, this resize could be used for e.g. Thumbnails
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sourceBitmap"></param>
|
/// <param name="sourceImage"></param>
|
||||||
/// <param name="maintainAspectRatio">true to maintain the aspect ratio</param>
|
/// <param name="maintainAspectRatio">true to maintain the aspect ratio</param>
|
||||||
/// <param name="newWidth"></param>
|
/// <param name="newWidth"></param>
|
||||||
/// <param name="newHeight"></param>
|
/// <param name="newHeight"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static Bitmap ResizeBitmap(Bitmap sourceBitmap, bool maintainAspectRatio, int newWidth, int newHeight) {
|
public static Image ResizeImage(Image sourceImage, bool maintainAspectRatio, int newWidth, int newHeight) {
|
||||||
Point throwAway;
|
Point throwAway;
|
||||||
return ResizeBitmap(sourceBitmap, maintainAspectRatio, false, Color.Empty, newWidth, newHeight, out throwAway);
|
return ResizeImage(sourceImage, maintainAspectRatio, false, Color.Empty, newWidth, newHeight, out throwAway);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Count how many times the supplied color exists
|
/// Count how many times the supplied color exists
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sourceBitmap">Bitmap to count the pixels of</param>
|
/// <param name="sourceImage">Image to count the pixels of</param>
|
||||||
/// <param name="colorToCount">Color to count/param>
|
/// <param name="colorToCount">Color to count/param>
|
||||||
/// <param name="includeAlpha">true if Alpha needs to be checked</param>
|
/// <param name="includeAlpha">true if Alpha needs to be checked</param>
|
||||||
/// <returns>int with the number of pixels which have colorToCount</returns>
|
/// <returns>int with the number of pixels which have colorToCount</returns>
|
||||||
public static int CountColor(Bitmap sourceBitmap, Color colorToCount, bool includeAlpha) {
|
public static int CountColor(Image sourceImage, Color colorToCount, bool includeAlpha) {
|
||||||
int colors = 0;
|
int colors = 0;
|
||||||
int toCount = colorToCount.ToArgb();
|
int toCount = colorToCount.ToArgb();
|
||||||
if (!includeAlpha) {
|
if (!includeAlpha) {
|
||||||
toCount = toCount & 0xffffff;
|
toCount = toCount & 0xffffff;
|
||||||
}
|
}
|
||||||
using (BitmapBuffer bb = new BitmapBuffer(sourceBitmap, true)) {
|
using (BitmapBuffer bb = new BitmapBuffer(sourceImage)) {
|
||||||
bb.Lock();
|
bb.Lock();
|
||||||
for (int y = 0; y < bb.Height; y++) {
|
for (int y = 0; y < bb.Height; y++) {
|
||||||
for (int x = 0; x < bb.Width; x++) {
|
for (int x = 0; x < bb.Width; x++) {
|
||||||
|
@ -1298,57 +1305,57 @@ namespace GreenshotPlugin.Core {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Scale the bitmap, keeping aspect ratio, but the canvas will always have the specified size.
|
/// Scale the bitmap, keeping aspect ratio, but the canvas will always have the specified size.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sourceBitmap">Bitmap to scale</param>
|
/// <param name="sourceImage">Image to scale</param>
|
||||||
/// <param name="maintainAspectRatio">true to maintain the aspect ratio</param>
|
/// <param name="maintainAspectRatio">true to maintain the aspect ratio</param>
|
||||||
/// <param name="backgroundColor">The color to fill with, or Color.Empty to take the default depending on the pixel format</param>
|
/// <param name="backgroundColor">The color to fill with, or Color.Empty to take the default depending on the pixel format</param>
|
||||||
/// <param name="newWidth">new width</param>
|
/// <param name="newWidth">new width</param>
|
||||||
/// <param name="newHeight">new height</param>
|
/// <param name="newHeight">new height</param>
|
||||||
/// <returns>a new bitmap with the specified size, the source-bitmap scaled to fit with aspect ratio locked</returns>
|
/// <returns>a new bitmap with the specified size, the source-Image scaled to fit with aspect ratio locked</returns>
|
||||||
public static Bitmap ResizeBitmap(Bitmap sourceBitmap, bool maintainAspectRatio, bool canvasUseNewSize, Color backgroundColor, int newWidth, int newHeight, out Point offset) {
|
public static Image ResizeImage(Image sourceImage, bool maintainAspectRatio, bool canvasUseNewSize, Color backgroundColor, int newWidth, int newHeight, out Point offset) {
|
||||||
int destX = 0;
|
int destX = 0;
|
||||||
int destY = 0;
|
int destY = 0;
|
||||||
|
|
||||||
float nPercentW = 0;
|
float nPercentW = 0;
|
||||||
float nPercentH = 0;
|
float nPercentH = 0;
|
||||||
|
|
||||||
nPercentW = ((float)newWidth / (float)sourceBitmap.Width);
|
nPercentW = ((float)newWidth / (float)sourceImage.Width);
|
||||||
nPercentH = ((float)newHeight / (float)sourceBitmap.Height);
|
nPercentH = ((float)newHeight / (float)sourceImage.Height);
|
||||||
if (maintainAspectRatio) {
|
if (maintainAspectRatio) {
|
||||||
if (nPercentH != 0 && nPercentH < nPercentW) {
|
if (nPercentH != 0 && nPercentH < nPercentW) {
|
||||||
nPercentW = nPercentH;
|
nPercentW = nPercentH;
|
||||||
if (canvasUseNewSize) {
|
if (canvasUseNewSize) {
|
||||||
destX = Math.Max(0, System.Convert.ToInt32((newWidth - (sourceBitmap.Width * nPercentW)) / 2));
|
destX = Math.Max(0, System.Convert.ToInt32((newWidth - (sourceImage.Width * nPercentW)) / 2));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nPercentH = nPercentW;
|
nPercentH = nPercentW;
|
||||||
if (canvasUseNewSize) {
|
if (canvasUseNewSize) {
|
||||||
destY = Math.Max(0, System.Convert.ToInt32((newHeight - (sourceBitmap.Height * nPercentH)) / 2));
|
destY = Math.Max(0, System.Convert.ToInt32((newHeight - (sourceImage.Height * nPercentH)) / 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
offset = new Point(destX, destY);
|
offset = new Point(destX, destY);
|
||||||
|
|
||||||
int destWidth = (int)(sourceBitmap.Width * nPercentW);
|
int destWidth = (int)(sourceImage.Width * nPercentW);
|
||||||
int destHeight = (int)(sourceBitmap.Height * nPercentH);
|
int destHeight = (int)(sourceImage.Height * nPercentH);
|
||||||
if (newWidth == 0) {
|
if (newWidth == 0) {
|
||||||
newWidth = destWidth;
|
newWidth = destWidth;
|
||||||
}
|
}
|
||||||
if (newHeight == 0) {
|
if (newHeight == 0) {
|
||||||
newHeight = destHeight;
|
newHeight = destHeight;
|
||||||
}
|
}
|
||||||
Bitmap newBitmap = null;
|
Image newImage = null;
|
||||||
if (maintainAspectRatio && canvasUseNewSize) {
|
if (maintainAspectRatio && canvasUseNewSize) {
|
||||||
newBitmap = CreateEmpty(newWidth, newHeight, sourceBitmap.PixelFormat, backgroundColor, sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution);
|
newImage = CreateEmpty(newWidth, newHeight, sourceImage.PixelFormat, backgroundColor, sourceImage.HorizontalResolution, sourceImage.VerticalResolution);
|
||||||
} else {
|
} else {
|
||||||
newBitmap = CreateEmpty(destWidth, destHeight, sourceBitmap.PixelFormat, backgroundColor, sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution);
|
newImage = CreateEmpty(destWidth, destHeight, sourceImage.PixelFormat, backgroundColor, sourceImage.HorizontalResolution, sourceImage.VerticalResolution);
|
||||||
}
|
}
|
||||||
|
|
||||||
using (Graphics graphics = Graphics.FromImage(newBitmap)) {
|
using (Graphics graphics = Graphics.FromImage(newImage)) {
|
||||||
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||||
graphics.DrawImage(sourceBitmap, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(0, 0, sourceBitmap.Width, sourceBitmap.Height), GraphicsUnit.Pixel);
|
graphics.DrawImage(sourceImage, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(0, 0, sourceImage.Width, sourceImage.Height), GraphicsUnit.Pixel);
|
||||||
}
|
}
|
||||||
return newBitmap;
|
return newImage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -247,7 +247,7 @@ namespace GreenshotPlugin.Core {
|
||||||
if (string.IsNullOrEmpty(fullPath)) {
|
if (string.IsNullOrEmpty(fullPath)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Bitmap fileBitmap = null;
|
Image fileImage = null;
|
||||||
LOG.InfoFormat("Loading image from file {0}", fullPath);
|
LOG.InfoFormat("Loading image from file {0}", fullPath);
|
||||||
// Fixed lock problem Bug #3431881
|
// Fixed lock problem Bug #3431881
|
||||||
using (Stream surfaceFileStream = File.OpenRead(fullPath)) {
|
using (Stream surfaceFileStream = File.OpenRead(fullPath)) {
|
||||||
|
@ -258,7 +258,7 @@ namespace GreenshotPlugin.Core {
|
||||||
surfaceFileStream.Position = 0;
|
surfaceFileStream.Position = 0;
|
||||||
using (Image tmpImage = Image.FromStream(surfaceFileStream, true, true)) {
|
using (Image tmpImage = Image.FromStream(surfaceFileStream, true, true)) {
|
||||||
LOG.DebugFormat("Loaded {0} with Size {1}x{2} and PixelFormat {3}", fullPath, tmpImage.Width, tmpImage.Height, tmpImage.PixelFormat);
|
LOG.DebugFormat("Loaded {0} with Size {1}x{2} and PixelFormat {3}", fullPath, tmpImage.Width, tmpImage.Height, tmpImage.PixelFormat);
|
||||||
fileBitmap = ImageHelper.Clone(tmpImage);
|
fileImage = ImageHelper.Clone(tmpImage);
|
||||||
}
|
}
|
||||||
// Start at -14 read "GreenshotXX.YY" (XX=Major, YY=Minor)
|
// Start at -14 read "GreenshotXX.YY" (XX=Major, YY=Minor)
|
||||||
const int markerSize = 14;
|
const int markerSize = 14;
|
||||||
|
@ -280,9 +280,9 @@ namespace GreenshotPlugin.Core {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fileBitmap != null) {
|
if (fileImage != null) {
|
||||||
returnSurface.Image = fileBitmap;
|
returnSurface.Image = fileImage;
|
||||||
LOG.InfoFormat("Information about file {0}: {1}x{2}-{3} Resolution {4}x{5}", fullPath, fileBitmap.Width, fileBitmap.Height, fileBitmap.PixelFormat, fileBitmap.HorizontalResolution, fileBitmap.VerticalResolution);
|
LOG.InfoFormat("Information about file {0}: {1}x{2}-{3} Resolution {4}x{5}", fullPath, fileImage.Width, fileImage.Height, fileImage.PixelFormat, fileImage.HorizontalResolution, fileImage.VerticalResolution);
|
||||||
}
|
}
|
||||||
return returnSurface;
|
return returnSurface;
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,16 +86,15 @@ namespace GreenshotPlugin.Core {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="baseUri"></param>
|
/// <param name="baseUri"></param>
|
||||||
/// <returns>Bitmap</returns>
|
/// <returns>Bitmap</returns>
|
||||||
public static Bitmap DownloadImage(string url) {
|
public static Image DownloadImage(string url) {
|
||||||
try {
|
try {
|
||||||
HttpWebRequest request = (HttpWebRequest)NetworkHelper.CreateWebRequest(url);
|
HttpWebRequest request = (HttpWebRequest)NetworkHelper.CreateWebRequest(url);
|
||||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||||
if (request.HaveResponse) {
|
if (request.HaveResponse) {
|
||||||
using (Image image = Image.FromStream(response.GetResponseStream())) {
|
using (Image image = Image.FromStream(response.GetResponseStream())) {
|
||||||
return new Bitmap(image);
|
return ImageHelper.Clone(image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.Error("Problem downloading the image from: " + url, e);
|
LOG.Error("Problem downloading the image from: " + url, e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,8 +103,8 @@ namespace Greenshot.Plugin.Drawing {
|
||||||
void FitToText();
|
void FitToText();
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IBitmapContainer: IDrawableContainer {
|
public interface IImageContainer: IDrawableContainer {
|
||||||
Bitmap Bitmap {
|
Image Image {
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,14 +110,12 @@ namespace Greenshot.Plugin {
|
||||||
/// <param name="fillColor">Color of background (e.g. Color.Transparent)</param>
|
/// <param name="fillColor">Color of background (e.g. Color.Transparent)</param>
|
||||||
ITextContainer AddTextContainer(string text, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, FontFamily family, float size, bool italic, bool bold, bool shadow, int borderSize, Color color, Color fillColor);
|
ITextContainer AddTextContainer(string text, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, FontFamily family, float size, bool italic, bool bold, bool shadow, int borderSize, Color color, Color fillColor);
|
||||||
|
|
||||||
IBitmapContainer AddBitmapContainer(Bitmap bitmap, int x, int y);
|
IImageContainer AddImageContainer(Image image, int x, int y);
|
||||||
ICursorContainer AddCursorContainer(Cursor cursor, int x, int y);
|
ICursorContainer AddCursorContainer(Cursor cursor, int x, int y);
|
||||||
IIconContainer AddIconContainer(Icon icon, int x, int y);
|
IIconContainer AddIconContainer(Icon icon, int x, int y);
|
||||||
IMetafileContainer AddMetafileContainer(Metafile metafile, int x, int y);
|
IImageContainer AddImageContainer(string filename, int x, int y);
|
||||||
IBitmapContainer AddBitmapContainer(string filename, int x, int y);
|
|
||||||
ICursorContainer AddCursorContainer(string filename, int x, int y);
|
ICursorContainer AddCursorContainer(string filename, int x, int y);
|
||||||
IIconContainer AddIconContainer(string filename, int x, int y);
|
IIconContainer AddIconContainer(string filename, int x, int y);
|
||||||
IMetafileContainer AddMetafileContainer(string filename, int x, int y);
|
|
||||||
long SaveElementsToStream(Stream stream);
|
long SaveElementsToStream(Stream stream);
|
||||||
void LoadElementsFromStream(Stream stream);
|
void LoadElementsFromStream(Stream stream);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue