forked from nulastudio/pic2meme
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 14f9347
Showing
22 changed files
with
3,034 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# macOS | ||
.DS_Store | ||
__MACOSX | ||
|
||
# vscode | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
|
||
# vs | ||
.vs/ | ||
|
||
# Build results | ||
[Bb]in/ | ||
[Oo]bj/ | ||
[Rr]elease/ | ||
|
||
# sublime | ||
*.sublime-workspace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CPOL-1.02 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<h1 align="center">微信表情包工具</h1> | ||
<h3 align="center">快速将QQ或其他表情包转换成微信可添加的表情</h3> | ||
|
||
## 举个栗子 | ||
|
||
### 普通图片 | ||
|
||
 | ||
|
||
### 转换为表情包 | ||
|
||
 | ||
|
||
## 支持图片格式 | ||
|
||
`png` `jpg` `bmp` | ||
|
||
不支持大图以及透明图,微信原生支持`gif`动图直接添加为表情,所以不需要转换。 | ||
|
||
## 代码引用 | ||
|
||
[NGif, Animated GIF Encoder for .NET](https://www.codeproject.com/Articles/11505/NGif-Animated-GIF-Encoder-for-NET) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.28307.421 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "pic2meme", "pic2meme\pic2meme.csproj", "{0DAF5660-6734-4678-B69D-AF988F733AFB}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{0DAF5660-6734-4678-B69D-AF988F733AFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{0DAF5660-6734-4678-B69D-AF988F733AFB}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{0DAF5660-6734-4678-B69D-AF988F733AFB}.Debug|x86.ActiveCfg = Debug|x86 | ||
{0DAF5660-6734-4678-B69D-AF988F733AFB}.Debug|x86.Build.0 = Debug|x86 | ||
{0DAF5660-6734-4678-B69D-AF988F733AFB}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{0DAF5660-6734-4678-B69D-AF988F733AFB}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{0DAF5660-6734-4678-B69D-AF988F733AFB}.Release|x86.ActiveCfg = Release|x86 | ||
{0DAF5660-6734-4678-B69D-AF988F733AFB}.Release|x86.Build.0 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {1E55E386-C1C8-404A-A66E-D3D39DC7342B} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Application x:Class="pic2meme.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:pic2meme" | ||
StartupUri="MainWindow.xaml"> | ||
<Application.Resources> | ||
|
||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Windows; | ||
|
||
namespace pic2meme | ||
{ | ||
/// <summary> | ||
/// App.xaml 的交互逻辑 | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Window x:Class="pic2meme.MainWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:local="clr-namespace:pic2meme" | ||
mc:Ignorable="d" | ||
Title="微信表情包工具" Height="364.4" Width="550" AllowDrop="True" Drop="Window_Drop" KeyDown="Window_KeyDown"> | ||
<Grid> | ||
<Label x:Name="Notice" Content="拖动或粘贴图片到此处进行表情包转换" FontSize="22" Margin="20,20,20,0" VerticalAlignment="Top" Height="54" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/> | ||
<Image x:Name="Preview" HorizontalAlignment="Left" Height="200" Margin="175,106,0,0" VerticalAlignment="Top" Width="200" Stretch="Uniform" /> | ||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Navigation; | ||
using System.Windows.Shapes; | ||
using System.Drawing; | ||
using System.Drawing.Imaging; | ||
using Gif.Components; | ||
using Image = System.Drawing.Image; | ||
using System.IO; | ||
using System.Collections.Specialized; | ||
|
||
namespace pic2meme | ||
{ | ||
/// <summary> | ||
/// MainWindow.xaml 的交互逻辑 | ||
/// </summary> | ||
public partial class MainWindow : Window | ||
{ | ||
private enum ConvertMode | ||
{ | ||
QuickConvert, | ||
CompatibleConvert, | ||
} | ||
|
||
private ConvertMode convertMode = ConvertMode.CompatibleConvert; | ||
|
||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
this.MinWidth = this.MaxWidth = this.Width; | ||
this.MinHeight = this.MaxHeight = this.Height; | ||
} | ||
|
||
private void Window_KeyDown(object sender, KeyEventArgs e) | ||
{ | ||
if (Keyboard.Modifiers == ModifierKeys.Control && e.Key == Key.V) | ||
{ | ||
HandleDataObject(Clipboard.GetDataObject()); | ||
} | ||
} | ||
|
||
private void Window_Drop(object sender, DragEventArgs e) | ||
{ | ||
HandleDataObject(e.Data); | ||
} | ||
|
||
private void HandleDataObject(IDataObject dataObject) | ||
{ | ||
try | ||
{ | ||
if (dataObject.GetDataPresent(DataFormats.FileDrop)) | ||
{ | ||
var file = ((System.Array)dataObject.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); | ||
pic2meme(file); | ||
} | ||
else if (dataObject.GetDataPresent(DataFormats.Bitmap)) | ||
{ | ||
var image = dataObject.GetData(DataFormats.Bitmap) as BitmapSource; | ||
var tmp = SaveBitmapSource(image); | ||
pic2meme(tmp); | ||
} | ||
} | ||
catch | ||
{ | ||
} | ||
} | ||
|
||
private string pic2meme(string image) | ||
{ | ||
Notice.Content = "转换中..."; | ||
|
||
var tmpImage = GenerateTempFile(".gif"); | ||
|
||
if (convertMode == ConvertMode.QuickConvert) | ||
{ | ||
try | ||
{ | ||
File.Copy(image, tmpImage); | ||
} | ||
catch | ||
{ | ||
tmpImage = null; | ||
} | ||
} | ||
else | ||
{ | ||
try | ||
{ | ||
AnimatedGifEncoder e = new AnimatedGifEncoder(); | ||
e.Start(tmpImage); | ||
//e.SetQuality(10); | ||
e.SetDelay(1000); | ||
e.SetRepeat(-1); | ||
if (File.Exists(image)) | ||
{ | ||
e.AddFrame(Image.FromFile(image)); | ||
} | ||
else | ||
{ | ||
tmpImage = null; | ||
} | ||
e.Finish(); | ||
} | ||
catch | ||
{ | ||
tmpImage = null; | ||
} | ||
} | ||
|
||
if (!string.IsNullOrEmpty(tmpImage)) | ||
{ | ||
Notice.Content = "转换成功,直接粘贴到微信发送即可"; | ||
SetImageToClipboard(tmpImage); | ||
SetPreview(tmpImage); | ||
} | ||
else | ||
{ | ||
Notice.Content = "转换失败"; | ||
} | ||
|
||
return tmpImage; | ||
} | ||
|
||
private string SaveBitmapSource(BitmapSource source) | ||
{ | ||
BitmapEncoder encoder = new PngBitmapEncoder(); | ||
encoder.Frames.Add(BitmapFrame.Create(source)); | ||
|
||
var tmp = GenerateTempFile(".jpg"); | ||
|
||
try | ||
{ | ||
using (var stream = new FileStream(tmp, FileMode.Create)) | ||
{ | ||
encoder.Save(stream); | ||
} | ||
} | ||
catch | ||
{ | ||
tmp = null; | ||
} | ||
|
||
return tmp; | ||
} | ||
|
||
private string GenerateTempFile(string ext) | ||
{ | ||
var file = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString().ToUpper() + ext; | ||
return File.Exists(file) ? GenerateTempFile(ext) : file; | ||
} | ||
|
||
private void SetPreview(string imageFile) | ||
{ | ||
BitmapImage bitmapImage = new BitmapImage(); | ||
bitmapImage.BeginInit(); | ||
bitmapImage.UriSource = new Uri(imageFile); | ||
bitmapImage.EndInit(); | ||
Preview.Source = bitmapImage; | ||
} | ||
|
||
private void SetImageToClipboard(string imageFile) | ||
{ | ||
var list = new StringCollection | ||
{ | ||
imageFile | ||
}; | ||
Clipboard.SetFileDropList(list); | ||
} | ||
} | ||
} |
Oops, something went wrong.