mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-19 14:53:50 +02:00
Upload screenshot to gallery
This commit is contained in:
@@ -66,6 +66,19 @@ namespace VRCX
|
||||
return text;
|
||||
}
|
||||
|
||||
public static string ReadPNGResolution(string path)
|
||||
{
|
||||
if (!File.Exists(path) || !IsPNGFile(path)) return null;
|
||||
|
||||
var png = File.ReadAllBytes(path);
|
||||
var existingpHYs = FindChunk(png, "IHDR");
|
||||
if (existingpHYs == null) return null;
|
||||
|
||||
var text = existingpHYs.GetResolution();
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified file is a PNG file. We do this by checking if the first 8 bytes in the file path match the PNG signature.
|
||||
/// </summary>
|
||||
@@ -358,10 +371,16 @@ namespace VRCX
|
||||
public string GetText(string keyword)
|
||||
{
|
||||
var offset = keywordEncoding.GetByteCount(keyword) + 5;
|
||||
// Read string from PNG chunk
|
||||
return Encoding.UTF8.GetString(ChunkDataBytes.ToArray(), offset, ChunkDataBytes.Count - offset);
|
||||
}
|
||||
|
||||
public string GetResolution()
|
||||
{
|
||||
var x = BitConverter.ToInt32(ChunkDataBytes.Take(4).Reverse().ToArray(), 0);
|
||||
var y = BitConverter.ToInt32(ChunkDataBytes.Skip(4).Take(4).Reverse().ToArray(), 0);
|
||||
return $"{x}x{y}";
|
||||
}
|
||||
|
||||
// Crc32 implementation from
|
||||
// https://web.archive.org/web/20150825201508/http://upokecenter.dreamhosters.com/articles/png-image-encoder-in-c/
|
||||
private static uint Crc32(byte[] stream, int offset, int length, uint crc)
|
||||
|
||||
Reference in New Issue
Block a user