mirror of
https://github.com/greenshot/greenshot
synced 2025-07-31 04:00:13 -07:00
Cleaning HEAD, to replace it with the branch
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1281 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
3514fc0a29
commit
174f653a5a
506 changed files with 0 additions and 76725 deletions
|
@ -1,323 +0,0 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2010 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.Runtime.Serialization;
|
||||
|
||||
namespace PluginExample {
|
||||
/// <summary>
|
||||
/// The BitmapBuffer is exactly what it says, it buffers a Bitmap.
|
||||
/// And it is possible to Draw on the Bitmap with direct memory access for better performance
|
||||
/// </summary>
|
||||
[Serializable()]
|
||||
public unsafe class BitmapBuffer : IDisposable {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(BitmapBuffer));
|
||||
private Bitmap bitmap;
|
||||
public Bitmap Bitmap {
|
||||
get {return bitmap;}
|
||||
}
|
||||
[NonSerialized]
|
||||
private BitmapData bmData;
|
||||
[NonSerialized]
|
||||
private Rectangle rect;
|
||||
[NonSerialized]
|
||||
private byte* pointer;
|
||||
[NonSerialized]
|
||||
private int stride; /* bytes per pixel row */
|
||||
[NonSerialized]
|
||||
private int aIndex = -1;
|
||||
[NonSerialized]
|
||||
private int rIndex = -1;
|
||||
[NonSerialized]
|
||||
private int gIndex = -1;
|
||||
[NonSerialized]
|
||||
private int bIndex = -1;
|
||||
[NonSerialized]
|
||||
private int bytesPerPixel;
|
||||
[NonSerialized]
|
||||
private bool bitsLocked = false;
|
||||
|
||||
public Size Size {
|
||||
get {return rect.Size;}
|
||||
}
|
||||
public int Length {
|
||||
get {return rect.Width*rect.Height;}
|
||||
}
|
||||
public int Width {
|
||||
get {return rect.Width;}
|
||||
}
|
||||
public int Height {
|
||||
get {return rect.Height;}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with just a Bitmap, the Rectangle is the Bitmap itself
|
||||
*/
|
||||
public BitmapBuffer(Bitmap bmp) : this(bmp, Rectangle.Empty) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a BitmapBuffer from a Bitmap and a Rectangle specifying what part from the Bitmap to take
|
||||
*/
|
||||
public BitmapBuffer(Bitmap sourceBmp, Rectangle applyRect) {
|
||||
Rectangle sourceRect = new Rectangle(applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height);
|
||||
Rectangle bitmapRect = new Rectangle(0,0, sourceBmp.Width, sourceBmp.Height);
|
||||
|
||||
if(sourceRect.Equals(Rectangle.Empty)) {
|
||||
sourceRect = bitmapRect;
|
||||
} else {
|
||||
sourceRect.Intersect(bitmapRect);
|
||||
}
|
||||
// Does the rect have any pixels?
|
||||
if (sourceRect.Height <= 0 || sourceRect.Width <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (SupportsPixelFormat(sourceBmp)) {
|
||||
// Create copy with supported format
|
||||
this.bitmap = sourceBmp.Clone(sourceRect, sourceBmp.PixelFormat);
|
||||
} else {
|
||||
// When sourceRect is the whole bitmap there is a GDI+ bug in Clone
|
||||
// Clone will than return the same PixelFormat as the source
|
||||
// a quick workaround is using new Bitmap which uses a default of Format32bppArgb
|
||||
if (sourceRect.Equals(bitmapRect)) {
|
||||
this.bitmap = new Bitmap(sourceBmp);
|
||||
} else {
|
||||
this.bitmap = sourceBmp.Clone(sourceRect, PixelFormat.Format24bppRgb);
|
||||
}
|
||||
}
|
||||
// Set "this" rect to location 0,0
|
||||
// as the Cloned Bitmap is only the part we want to work with
|
||||
this.rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~BitmapBuffer() {
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* The public accessible Dispose
|
||||
* Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice
|
||||
*/
|
||||
public void Dispose() {
|
||||
Dispose(true);
|
||||
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) {
|
||||
Unlock();
|
||||
if (disposing) {
|
||||
if (bitmap != null) {
|
||||
bitmap.Dispose();
|
||||
}
|
||||
}
|
||||
bitmap = null;
|
||||
bmData = null;
|
||||
pointer = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called when deserializing the object
|
||||
*/
|
||||
public BitmapBuffer(SerializationInfo info, StreamingContext ctxt) {
|
||||
this.bitmap = (Bitmap)info.GetValue("bitmap", typeof(Bitmap));
|
||||
this.rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
|
||||
// The rest will be set when Lock is called
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called when serializing the object
|
||||
*/
|
||||
public void GetObjectData(SerializationInfo info, StreamingContext ctxt) {
|
||||
Unlock();
|
||||
info.AddValue("bitmap", this.bitmap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock the bitmap so we have direct access to the memory
|
||||
*/
|
||||
public void Lock() {
|
||||
if(rect.Width > 0 && rect.Height > 0) {
|
||||
bmData = bitmap.LockBits(rect, ImageLockMode.ReadWrite, bitmap.PixelFormat);
|
||||
bitsLocked = true;
|
||||
|
||||
System.IntPtr Scan0 = bmData.Scan0;
|
||||
pointer = (byte*)(void*)Scan0;
|
||||
|
||||
PrepareForPixelFormat();
|
||||
stride = bmData.Stride;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlock the System Memory
|
||||
*/
|
||||
private void Unlock() {
|
||||
if(bitsLocked) {
|
||||
bitmap.UnlockBits(bmData);
|
||||
bitsLocked = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the stored bitmap to the destionation bitmap at the supplied point
|
||||
*/
|
||||
public void DrawTo(Bitmap destinationBitmap, Point destination) {
|
||||
DrawTo(destinationBitmap, null, destination);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the stored Bitmap on the Destination bitmap with the specified rectangle
|
||||
* Be aware that the stored bitmap will be resized to the specified rectangle!!
|
||||
*/
|
||||
public void DrawTo(Bitmap destinationBitmap, Rectangle destinationRect) {
|
||||
DrawTo(destinationBitmap, destinationRect, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* private helper to draw the bitmap
|
||||
*/
|
||||
private void DrawTo(Bitmap destinationBitmap, Rectangle? destinationRect, Point? destination) {
|
||||
if (destinationRect.HasValue) {
|
||||
// Does the rect have any pixels?
|
||||
if (destinationRect.Value.Height <= 0 || destinationRect.Value.Width <= 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Make sure this.bitmap is unlocked
|
||||
Unlock();
|
||||
|
||||
using (Graphics graphics = Graphics.FromImage(destinationBitmap)) {
|
||||
if (destinationRect.HasValue) {
|
||||
LOG.Debug(String.Format("Drawing at: {0},{1} {2},{3}", destinationRect.Value.X, destinationRect.Value.Y, destinationRect.Value.Width, destinationRect.Value.Height));
|
||||
graphics.DrawImage(this.bitmap, destinationRect.Value);
|
||||
} else if (destination.HasValue) {
|
||||
LOG.Debug(String.Format("Drawing at: {0},{1}", destination.Value.X, destination.Value.Y));
|
||||
graphics.DrawImage(this.bitmap, destination.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the color at location x,y
|
||||
* Before the first time this is called the Lock() should be called once!
|
||||
*/
|
||||
public Color GetColorAt(int x, int y) {
|
||||
if(x>=0 && y>=0 && x<rect.Width && y<rect.Height) {
|
||||
int offset = x*bytesPerPixel+y*stride;
|
||||
int a = (aIndex==-1) ? 255 : (int)pointer[aIndex+offset];
|
||||
return Color.FromArgb(a, pointer[rIndex+offset], pointer[gIndex+offset], pointer[bIndex+offset]);
|
||||
} else {
|
||||
return Color.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the color at location x,y
|
||||
* Before the first time this is called the Lock() should be called once!
|
||||
*/
|
||||
public void SetColorAt(int x, int y, Color color) {
|
||||
if(x>=0 && y>=0 && x<rect.Width && y<rect.Height) {
|
||||
int offset = x*bytesPerPixel+y*stride;
|
||||
if(aIndex!=-1) pointer[aIndex+offset] = color.A;
|
||||
pointer[rIndex+offset] = color.R;
|
||||
pointer[gIndex+offset] = color.G;
|
||||
pointer[bIndex+offset] = color.B;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the color at location x,y as an array
|
||||
* Before the first time this is called the Lock() should be called once!
|
||||
*/
|
||||
public int[] GetColorArrayAt(int x, int y) {
|
||||
if(x>=0 && y>=0 && x<rect.Width && y<rect.Height) {
|
||||
int offset = x*bytesPerPixel+y*stride;
|
||||
int a = (aIndex==-1) ? 255 : (int)pointer[aIndex+offset];
|
||||
return new int[]{a, pointer[rIndex+offset], pointer[gIndex+offset], pointer[bIndex+offset]};
|
||||
} else {
|
||||
return new int[]{0,0,0,0};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the color at location x,y as an array
|
||||
* Before the first time this is called the Lock() should be called once!
|
||||
*/
|
||||
public void SetColorArrayAt(int x, int y, int[] colors) {
|
||||
if(x>=0 && y>=0 && x<rect.Width && y<rect.Height) {
|
||||
int offset = x*bytesPerPixel+y*stride;
|
||||
if(aIndex!=-1) pointer[aIndex+offset] = (byte)colors[0];
|
||||
pointer[rIndex+offset] = (byte)colors[1];
|
||||
pointer[gIndex+offset] = (byte)colors[2];
|
||||
pointer[bIndex+offset] = (byte)colors[3];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the supplied Bitmap has a PixelFormat we support
|
||||
*/
|
||||
private bool SupportsPixelFormat(Bitmap bitmap) {
|
||||
return (bitmap.PixelFormat.Equals(PixelFormat.Format32bppArgb) ||
|
||||
bitmap.PixelFormat.Equals(PixelFormat.Format32bppRgb) ||
|
||||
bitmap.PixelFormat.Equals(PixelFormat.Format24bppRgb));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set some internal values for accessing the bitmap according to the PixelFormat
|
||||
*/
|
||||
private void PrepareForPixelFormat() {
|
||||
switch(bitmap.PixelFormat) {
|
||||
case PixelFormat.Format32bppArgb:
|
||||
bIndex = 0;
|
||||
gIndex = 1;
|
||||
rIndex = 2;
|
||||
aIndex = 3;
|
||||
bytesPerPixel = 4;
|
||||
break;
|
||||
case PixelFormat.Format32bppRgb:
|
||||
bIndex = 0;
|
||||
gIndex = 1;
|
||||
rIndex = 2;
|
||||
bytesPerPixel = 4;
|
||||
break;
|
||||
case PixelFormat.Format24bppRgb:
|
||||
bIndex = 0;
|
||||
gIndex = 1;
|
||||
rIndex = 2;
|
||||
bytesPerPixel = 3;
|
||||
break;
|
||||
default:
|
||||
throw new FormatException("Bitmap.Pixelformat."+bitmap.PixelFormat+" is currently not supported. Supported: Format32bpp(A)Rgb, Format24bppRgb");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2010 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.Collections.Generic;
|
||||
using Greenshot.Core;
|
||||
|
||||
namespace PluginExample {
|
||||
public enum Location {
|
||||
TopLeft, TopCenter, TopRight,
|
||||
CenterLeft, CenterCenter, CenterRight,
|
||||
BottomLeft, BottomCenter, BottomRight
|
||||
}
|
||||
/// <summary>
|
||||
/// Description of FlickrConfiguration.
|
||||
/// </summary>
|
||||
[IniSection("Example", Description="Greenshot Example Plugin configuration")]
|
||||
public class ExampleConfiguration : IniSection {
|
||||
[IniProperty("AddAnnotations", Description="Do we need to add annotations?")]
|
||||
public bool AddAnnotations;
|
||||
|
||||
[IniProperty("Annotations", Description="The annotations")]
|
||||
public Dictionary<Location, string> annotations;
|
||||
|
||||
/// <summary>
|
||||
/// Supply values we can't put as defaults
|
||||
/// </summary>
|
||||
/// <param name="property">The property to return a default for</param>
|
||||
/// <returns>object with the default value for the supplied property</returns>
|
||||
public override object GetDefault(string property) {
|
||||
switch(property) {
|
||||
case "Annotations":
|
||||
Dictionary<Location, string> annotationDefaults = new Dictionary<Location, string>();
|
||||
annotationDefaults.Add(Location.TopLeft, "%user%");
|
||||
annotationDefaults.Add(Location.BottomRight, "%hostname%");
|
||||
return annotationDefaults;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,259 +0,0 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2010 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.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Greenshot.Capturing;
|
||||
using Greenshot.Core;
|
||||
using Greenshot.Drawing;
|
||||
using Greenshot.Forms;
|
||||
using Greenshot.Plugin;
|
||||
|
||||
namespace PluginExample {
|
||||
/// <summary>
|
||||
/// An example Plugin so developers can see how they can develop their own plugin
|
||||
/// </summary>
|
||||
public class PluginExample : IGreenshotPlugin {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(PluginExample));
|
||||
private IGreenshotPluginHost host;
|
||||
private ICaptureHost captureHost = null;
|
||||
private PluginAttribute myAttributes;
|
||||
private ExampleConfiguration config;
|
||||
|
||||
public PluginExample() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of the IGreenshotPlugin.Initialize
|
||||
/// </summary>
|
||||
/// <param name="host">Use the IGreenshotPluginHost interface to register events</param>
|
||||
/// <param name="captureHost">Use the ICaptureHost interface to register in the MainContextMenu</param>
|
||||
/// <param name="pluginAttribute">My own attributes</param>
|
||||
public virtual void Initialize(IGreenshotPluginHost pluginHost, ICaptureHost captureHost, PluginAttribute myAttributes) {
|
||||
LOG.Debug("Initialize called of " + myAttributes.Name);
|
||||
|
||||
this.host = (IGreenshotPluginHost)pluginHost;
|
||||
this.captureHost = captureHost;
|
||||
this.myAttributes = myAttributes;
|
||||
|
||||
this.host.OnImageEditorOpen += new OnImageEditorOpenHandler(ImageEditorOpened);
|
||||
this.host.OnSurfaceFromCapture += new OnSurfaceFromCaptureHandler(SurfaceFromCapture);
|
||||
this.host.OnImageOutput += new OnImageOutputHandler(ImageOutput);
|
||||
|
||||
this.config = IniConfig.GetIniSection<ExampleConfiguration>();
|
||||
}
|
||||
|
||||
public virtual void Shutdown() {
|
||||
LOG.Debug("Shutdown of " + myAttributes.Name);
|
||||
this.host.OnImageEditorOpen -= new OnImageEditorOpenHandler(ImageEditorOpened);
|
||||
this.host.OnSurfaceFromCapture -= new OnSurfaceFromCaptureHandler(SurfaceFromCapture);
|
||||
this.host.OnImageOutput -= new OnImageOutputHandler(ImageOutput);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of the IPlugin.Configure
|
||||
/// </summary>
|
||||
public virtual void Configure() {
|
||||
LOG.Debug("Configure called");
|
||||
SettingsForm settingsForm = new SettingsForm(config.AddAnnotations);
|
||||
DialogResult result = settingsForm.ShowDialog();
|
||||
if (result == DialogResult.OK) {
|
||||
config.AddAnnotations = settingsForm.TestAnnotations;
|
||||
}
|
||||
settingsForm.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of the OnImageEditorOpen event
|
||||
/// Using the ImageEditor interface to register in the plugin menu
|
||||
/// </summary>
|
||||
private void ImageEditorOpened(object sender, ImageEditorOpenEventArgs eventArgs) {
|
||||
LOG.Debug("ImageEditorOpened called");
|
||||
ToolStripMenuItem toolStripMenuItem = eventArgs.ImageEditor.GetPluginMenuItem();
|
||||
ToolStripMenuItem saveItem = new ToolStripMenuItem();
|
||||
saveItem.Text = "Save with Plugin";
|
||||
saveItem.Tag = eventArgs.ImageEditor;
|
||||
saveItem.Click += new System.EventHandler(EditMenuClick);
|
||||
toolStripMenuItem.DropDownItems.Add(saveItem);
|
||||
|
||||
ToolStripMenuItem grayscaleItem = new ToolStripMenuItem();
|
||||
grayscaleItem.Text = "Turn bitmap into gray-scales";
|
||||
grayscaleItem.Tag = eventArgs.ImageEditor;
|
||||
grayscaleItem.Click += new System.EventHandler(GrayScaleMenuClick);
|
||||
toolStripMenuItem.DropDownItems.Add(grayscaleItem);
|
||||
}
|
||||
|
||||
private void MainMenuClick(object sender, EventArgs e) {
|
||||
LOG.Debug("Sympathy for the Devil!");
|
||||
Bitmap bitmap = new Bitmap(100, 100, PixelFormat.Format16bppRgb555);
|
||||
captureHost.HandleCapture(bitmap);
|
||||
bitmap.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will be called when the menu item in the Editor is clicked
|
||||
/// Just an example...
|
||||
/// </summary>
|
||||
private void EditMenuClick(object sender, EventArgs e) {
|
||||
ToolStripMenuItem item = (ToolStripMenuItem)sender;
|
||||
IImageEditor imageEditor = (IImageEditor)item.Tag;
|
||||
|
||||
string file = host.GetFilename(OutputFormat.Png, null);
|
||||
string filePath = Path.Combine(host.ConfigurationPath,file);
|
||||
using (FileStream stream = new FileStream(filePath, FileMode.Create)) {
|
||||
imageEditor.SaveToStream(stream, OutputFormat.Png, 100);
|
||||
}
|
||||
LOG.Debug("Saved test file to: " + filePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will be called when the menu item in the Editor is clicked
|
||||
/// Just an example...
|
||||
/// </summary>
|
||||
private void GrayScaleMenuClick(object sender, EventArgs e) {
|
||||
ToolStripMenuItem item = (ToolStripMenuItem)sender;
|
||||
IImageEditor imageEditor = (IImageEditor)item.Tag;
|
||||
ISurface surface = imageEditor.Surface;
|
||||
// copy & do something with the image
|
||||
Image image = (Image)surface.OriginalImage.Clone();
|
||||
|
||||
using (BitmapBuffer bbb = new BitmapBuffer(image as Bitmap)) {
|
||||
// Image is copied, dispose it!
|
||||
image.Dispose();
|
||||
|
||||
bbb.Lock();
|
||||
for(int y=0;y<bbb.Height; y++) {
|
||||
for(int x=0;x<bbb.Width; x++) {
|
||||
Color color = bbb.GetColorAt(x, y);
|
||||
int luma = (int)((0.3*color.R) + (0.59*color.G) + (0.11*color.B));
|
||||
color = Color.FromArgb(luma, luma, luma);
|
||||
bbb.SetColorAt(x, y, color);
|
||||
}
|
||||
}
|
||||
surface.Image = bbb.Bitmap;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Handling of the OnImageOutputHandler event from the IGreenshotPlugin
|
||||
/// </summary>
|
||||
/// <param name="ImageOutputEventArgs">Has the FullPath to the image</param>
|
||||
private void ImageOutput(object sender, ImageOutputEventArgs eventArgs) {
|
||||
LOG.Debug("ImageOutput called with full path: " + eventArgs.FullPath);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Handling of the OnSurfaceFromCapture event from the IGreenshotPlugin
|
||||
/// </summary>
|
||||
/// <param name="SurfaceFromCaptureEventArgs">Has the ICapture and ISurface</param>
|
||||
public void SurfaceFromCapture(object sender, SurfaceFromCaptureEventArgs eventArgs) {
|
||||
LOG.Debug("SurfaceFromCapture called");
|
||||
if (!config.AddAnnotations) {
|
||||
return;
|
||||
}
|
||||
ISurface surface = eventArgs.Surface;
|
||||
|
||||
// Example, add a Cursor
|
||||
//surface.SelectElement(surface.AddCursorContainer(Cursors.Hand, 100, 100));
|
||||
|
||||
DateTime captureTaken = DateTime.Now;
|
||||
// Use default application name for title
|
||||
string title = Application.ProductName;
|
||||
|
||||
// Check if we have capture details
|
||||
if ( eventArgs.Capture.CaptureDetails != null) {
|
||||
captureTaken = eventArgs.Capture.CaptureDetails.DateTime;
|
||||
if (eventArgs.Capture.CaptureDetails.Title != null) {
|
||||
title = eventArgs.Capture.CaptureDetails.Title;
|
||||
}
|
||||
}
|
||||
foreach(Location location in config.annotations.Keys) {
|
||||
string pattern = config.annotations[location];
|
||||
pattern = pattern.Replace("%YYYY%",captureTaken.Year.ToString());
|
||||
pattern = pattern.Replace("%MM%", zeroPad(captureTaken.Month.ToString(), 2));
|
||||
pattern = pattern.Replace("%DD%", zeroPad(captureTaken.Day.ToString(), 2));
|
||||
pattern = pattern.Replace("%hh%", zeroPad(captureTaken.Hour.ToString(), 2));
|
||||
pattern = pattern.Replace("%mm%", zeroPad(captureTaken.Minute.ToString(), 2));
|
||||
pattern = pattern.Replace("%ss%", zeroPad(captureTaken.Second.ToString(), 2));
|
||||
pattern = pattern.Replace("%domain%", Environment.UserDomainName);
|
||||
pattern = pattern.Replace("%user%", Environment.UserName);
|
||||
pattern = pattern.Replace("%hostname%", Environment.MachineName);
|
||||
pattern = pattern.Replace("%title%", title);
|
||||
HorizontalAlignment hAlign = HorizontalAlignment.Center;
|
||||
VerticalAlignment vAlign = VerticalAlignment.CENTER;
|
||||
switch(location) {
|
||||
case Location.TopLeft:
|
||||
hAlign = HorizontalAlignment.Left;
|
||||
vAlign = VerticalAlignment.TOP;
|
||||
break;
|
||||
case Location.TopCenter:
|
||||
hAlign = HorizontalAlignment.Center;
|
||||
vAlign = VerticalAlignment.TOP;
|
||||
break;
|
||||
case Location.TopRight:
|
||||
hAlign = HorizontalAlignment.Right;
|
||||
vAlign = VerticalAlignment.TOP;
|
||||
break;
|
||||
|
||||
case Location.CenterLeft:
|
||||
hAlign = HorizontalAlignment.Left;
|
||||
vAlign = VerticalAlignment.CENTER;
|
||||
break;
|
||||
case Location.CenterCenter:
|
||||
hAlign = HorizontalAlignment.Center;
|
||||
vAlign = VerticalAlignment.CENTER;
|
||||
break;
|
||||
case Location.CenterRight:
|
||||
hAlign = HorizontalAlignment.Right;
|
||||
vAlign = VerticalAlignment.CENTER;
|
||||
break;
|
||||
|
||||
case Location.BottomLeft:
|
||||
hAlign = HorizontalAlignment.Left;
|
||||
vAlign = VerticalAlignment.BOTTOM;
|
||||
break;
|
||||
case Location.BottomCenter:
|
||||
hAlign = HorizontalAlignment.Center;
|
||||
vAlign = VerticalAlignment.BOTTOM;
|
||||
break;
|
||||
case Location.BottomRight:
|
||||
hAlign = HorizontalAlignment.Right;
|
||||
vAlign = VerticalAlignment.BOTTOM;
|
||||
break;
|
||||
}
|
||||
surface.SelectElement(surface.AddTextContainer(pattern, hAlign, vAlign,
|
||||
FontFamily.GenericSansSerif, 12f, false, false, false, 2, Color.Red, Color.White));
|
||||
}
|
||||
}
|
||||
|
||||
private static string zeroPad(string input, int chars) {
|
||||
while(input.Length < chars) input = "0" + input;
|
||||
return input;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{6BD38118-B27F-43A1-951C-FB6464D39260}</ProjectGuid>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>PluginExample</RootNamespace>
|
||||
<AssemblyName>PluginExample</AssemblyName>
|
||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<SourceAnalysisOverrideSettingsFile>C:\Dokumente und Einstellungen\05018085\Anwendungsdaten\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
|
||||
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<NoStdLib>False</NoStdLib>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Platform)' == 'x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
|
||||
<BaseAddress>4194304</BaseAddress>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>Full</DebugType>
|
||||
<Optimize>False</Optimize>
|
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DebugSymbols>False</DebugSymbols>
|
||||
<DebugType>None</DebugType>
|
||||
<Optimize>True</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
|
||||
<ItemGroup>
|
||||
<Reference Include="log4net">
|
||||
<HintPath>..\GreenshotCore\Lib\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DrawingUtils.cs" />
|
||||
<Compile Include="ExampleConfiguration.cs" />
|
||||
<Compile Include="PluginExample.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SettingsForm.cs" />
|
||||
<Compile Include="SettingsForm.Designer.cs">
|
||||
<DependentUpon>SettingsForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<None Include="Properties\AssemblyInfo.cs.template" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>mkdir "$(SolutionDir)bin\$(Configuration)\Plugins\$(ProjectName)"
|
||||
copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp"</PostBuildEvent>
|
||||
<PreBuildEvent>"$(SolutionDir)\tools\TortoiseSVN\SubWCRev.exe" "$(ProjectDir)\" "$(ProjectDir)\Properties\AssemblyInfo.cs.template" "$(ProjectDir)\Properties\AssemblyInfo.cs"</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\GreenshotCore\GreenshotCore.csproj">
|
||||
<Project>{BDC408EE-DEA1-4474-B59D-7F05757B12EC}</Project>
|
||||
<Name>GreenshotCore</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2010 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/>.
|
||||
*/
|
||||
#region Using directives
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using Greenshot.Plugin;
|
||||
|
||||
#endregion
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("PluginExample")]
|
||||
[assembly: AssemblyDescription("An example plugin")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("PluginExample")]
|
||||
[assembly: AssemblyCopyright("Copyright 2010")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
// The PluginAttribute describes the "entryType" and if the plugin is configurable
|
||||
[assembly: PluginAttribute("PluginExample.PluginExample", true)]
|
||||
|
||||
// This sets the default COM visibility of types in the assembly to invisible.
|
||||
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The assembly version has following format :
|
||||
//
|
||||
// Major.Minor.Build.Revision
|
||||
//
|
||||
// You can specify all the values or you can use the default the Revision and
|
||||
// Build Numbers by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.0.0.$WCREV$")]
|
101
PluginExample/SettingsForm.Designer.cs
generated
101
PluginExample/SettingsForm.Designer.cs
generated
|
@ -1,101 +0,0 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2010 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/>.
|
||||
*/
|
||||
namespace PluginExample
|
||||
{
|
||||
partial class SettingsForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Designer variable used to keep track of non-visual components.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Disposes resources used by the form.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing) {
|
||||
if (components != null) {
|
||||
components.Dispose();
|
||||
}
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is required for Windows Forms designer support.
|
||||
/// Do not change the method contents inside the source code editor. The Forms designer might
|
||||
/// not be able to load this method if it was changed manually.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.checkBox1 = new System.Windows.Forms.CheckBox();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.button2 = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// checkBox1
|
||||
//
|
||||
this.checkBox1.Location = new System.Drawing.Point(12, 12);
|
||||
this.checkBox1.Name = "checkBox1";
|
||||
this.checkBox1.Size = new System.Drawing.Size(152, 24);
|
||||
this.checkBox1.TabIndex = 0;
|
||||
this.checkBox1.Text = "Test Annotations";
|
||||
this.checkBox1.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this.button1.Location = new System.Drawing.Point(12, 52);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(75, 23);
|
||||
this.button1.TabIndex = 1;
|
||||
this.button1.Text = "Ok";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.button1.Click += new System.EventHandler(this.Button1Click);
|
||||
//
|
||||
// button2
|
||||
//
|
||||
this.button2.Location = new System.Drawing.Point(93, 52);
|
||||
this.button2.Name = "button2";
|
||||
this.button2.Size = new System.Drawing.Size(75, 23);
|
||||
this.button2.TabIndex = 2;
|
||||
this.button2.Text = "Cancel";
|
||||
this.button2.UseVisualStyleBackColor = true;
|
||||
this.button2.Click += new System.EventHandler(this.Button2Click);
|
||||
//
|
||||
// SettingsForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(187, 105);
|
||||
this.Controls.Add(this.button2);
|
||||
this.Controls.Add(this.button1);
|
||||
this.Controls.Add(this.checkBox1);
|
||||
this.Name = "SettingsForm";
|
||||
this.Text = "SettingsForm";
|
||||
this.ResumeLayout(false);
|
||||
}
|
||||
private System.Windows.Forms.Button button2;
|
||||
private System.Windows.Forms.Button button1;
|
||||
private System.Windows.Forms.CheckBox checkBox1;
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2010 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.Windows.Forms;
|
||||
|
||||
namespace PluginExample {
|
||||
/// <summary>
|
||||
/// Description of SettingsForm.
|
||||
/// </summary>
|
||||
public partial class SettingsForm : Form {
|
||||
public SettingsForm(bool testAnnotations) {
|
||||
//
|
||||
// The InitializeComponent() call is required for Windows Forms designer support.
|
||||
//
|
||||
InitializeComponent();
|
||||
checkBox1.Checked = testAnnotations;
|
||||
}
|
||||
|
||||
void Button1Click(object sender, EventArgs e) {
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
public bool TestAnnotations {
|
||||
get {
|
||||
return checkBox1.Checked;
|
||||
}
|
||||
}
|
||||
|
||||
void Button2Click(object sender, EventArgs e) {
|
||||
DialogResult = DialogResult.Cancel;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue