I’m a newbie to dotnet, so sorry if this is a silly question.
I couldn’t find yet a solution, so I’d appreciate any hint.
There’s an open source program which get a png through http, first requests png format:
client.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "image/png");
and stores it as ByteArray:
image1 = await response.Content.ReadAsByteArrayAsync()
I’d want to to two modifications with this png as byte array:
- First, draw a grid every x pixels
- Second, load another png file to use as a background image, and merge them.
Then, replace the original ByteArray with the new ByteArray with these modifications.
I tried the easiest one, drawing the grid, using several ways, without success. I think the most correct one, despite it fails, is:
ImageSource image1_bitmap_frame = BitmapFrame.Create(new MemoryStream image1), BitmapCreateOptions.IgnoreImageCache, BitmapCacheOption.OnLoad);
WriteableBitmap combined_bitmap = new (image1.Clone());
// Draw a grid
for (int x = 0; x < combined_bitmap.PixelWidth; x +=50)
{
for (int y = 0; y < combined_bitmap.PixelHeight; y++)
{
combined_bitmap.SetPixel(x,y, Colors.Black);
}
}
But I get some errors:
- can’t convert System.Windows.Media.ImageSource to System.Windows.Media.Imaging.BitmapSource.
- there is no SetPoxel in WriteableBitmap
Could someone give me any hint about how to do this correctly?
Thanks in advance!
Carlos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.