Created
July 13, 2016 08:32
-
-
Save Magnagames/1e87e9c8c67c4278dca65112b3761b2d to your computer and use it in GitHub Desktop.
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Drawing; | |
using MyLibrary; | |
namespace MagnaEngine | |
{ | |
public static class PngConverter | |
{ | |
public static void ConvertByteToPng(byte[] data) | |
{ | |
var w = CalcWidth(data); | |
var h = CalcHeight(data); | |
var image = ByteArrayToImage(data); | |
// ファイル名「tips.jpg」で保存 | |
image.Save(Utility.DesktopPath + "tips.png", System.Drawing.Imaging.ImageFormat.Png); | |
} | |
public static Image ByteArrayToImage(byte[] b) | |
{ | |
ImageConverter imgconv = new ImageConverter(); | |
Image img = (Image)imgconv.ConvertFrom(b); | |
return img; | |
} | |
private static int CalcWidth(byte[] _data) | |
{ | |
int pos = 16; | |
int width = 0; | |
for (int i = 0; i < 4; i++) | |
{ | |
width = width * 256 + _data[pos++]; | |
} | |
return width; | |
} | |
private static int CalcHeight(byte[] _data) | |
{ | |
int pos = 16; | |
int height = 0; | |
for (int i = 0; i < 4; i++) | |
{ | |
height = height * 256 + _data[pos++]; | |
} | |
return height; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment