You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can someone tell me why the first image fails to encode in this code?
The other image works.
It is a webp image even though it says jpg in the url. But Skia should work with webp. And if I save it to a local file first and open it, it works fine. But I don't want to do that.
I have about 8 mill images (png, bmp, svg, jpeg, webp) that I need to convert to jpg. So you can understand why I don't want to save it locally first :)
So far it's only a problem with webp images.
Any ider how to make this work without saving locally first?
async Task Main()
{
await DownloadImage(@"http://hausfotos.atraveo.com/861000/h861758/original/h861758_5.jpg?20240715041037", @"D:\temp\test\failes.jpg");
await DownloadImage(@"http://hausfotos.atraveo.com/3484000/h3484313/original/h3484313_6.jpg?20240824131037", @"D:\temp\test\works.jpg");
await DownloadImageAndLoadLocal(@"http://hausfotos.atraveo.com/861000/h861758/original/h861758_5.jpg?20240715041037", @"D:\temp\test\failes.jpg", @"D:\temp\test\tempfile");
await DownloadImageAndLoadLocal(@"http://hausfotos.atraveo.com/3484000/h3484313/original/h3484313_6.jpg?20240824131037", @"D:\temp\test\works.jpg", @"D:\temp\test\tempfile");
}
private async Task DownloadImage(string url, string path)
{
var request = (HttpWebRequest)WebRequest.Create(url);
request.Accept = "image/*";
request.Headers.Add("accept-encoding", "gzip, deflate, br");
request.Timeout = 5000;
request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
using (var response = await request.GetResponseAsync().ConfigureAwait(false))
{
using (var responseStream = response.GetResponseStream())
{
var skiabitmap = SKBitmap.Decode(responseStream);
using (FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None))
{
skiabitmap.Encode(stream, SKEncodedImageFormat.Jpeg, 90);
}
}
}
}
private async Task DownloadImageAndLoadLocal(string url, string path, string tempLocation)
{
var request = (HttpWebRequest)WebRequest.Create(url);
request.Accept = "image/*";
request.Headers.Add("accept-encoding", "gzip, deflate, br");
request.Timeout = 5000;
request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
// Save file to temp
using (var response = await request.GetResponseAsync().ConfigureAwait(false))
{
using (var responseStream = response.GetResponseStream())
{
using (var fileStream = new FileStream(tempLocation, FileMode.Create, FileAccess.Write))
{
await responseStream.CopyToAsync(fileStream);
}
}
}
// Open file and save
using (var fs = File.Open(tempLocation, FileMode.Open))
{
var skiabitmap = SKBitmap.Decode(fs);
using (FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None))
{
skiabitmap.Encode(stream, SKEncodedImageFormat.Jpeg, 90);
}
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Can someone tell me why the first image fails to encode in this code?
The other image works.
It is a webp image even though it says jpg in the url. But Skia should work with webp. And if I save it to a local file first and open it, it works fine. But I don't want to do that.
I have about 8 mill images (png, bmp, svg, jpeg, webp) that I need to convert to jpg. So you can understand why I don't want to save it locally first :)
So far it's only a problem with webp images.
Any ider how to make this work without saving locally first?
Beta Was this translation helpful? Give feedback.
All reactions