chcę stworzyć obrazek, na którym mogę sobie rysować linie i generować tekst. Korzystam z klasy WriteableBitmap bo chyba tylko ona jest dostępna w Windows Store App do takich rzeczy ;/ Jednak mam problem, generowany przeze mnie obrazek jest w mega chujowej jakości. FontSize 10 nawet nie da się rozczytać ;o Domyslam się, że problem nie leży przy rysowaniu lub zapisywaniu tekstu na obrazku ale bardziej przy encodowaniu. Mój kod:
Kod :
public async Task SaveWriteableBitmap(WriteableBitmap WB, GfxFileFormat fileFormat, string fileName)
{
string FileName = string.Format("{0}.", fileName);
Guid BitmapEncoderGuid = BitmapEncoder.JpegEncoderId;
switch (fileFormat)
{
case GfxFileFormat.Jpeg:
FileName += "jpeg";
BitmapEncoderGuid = BitmapEncoder.JpegEncoderId;
break;
case GfxFileFormat.Png:
FileName += "png";
BitmapEncoderGuid = BitmapEncoder.PngEncoderId;
break;
case GfxFileFormat.Bmp:
FileName += "bmp";
BitmapEncoderGuid = BitmapEncoder.BmpEncoderId;
break;
case GfxFileFormat.Tiff:
FileName += "tiff";
BitmapEncoderGuid = BitmapEncoder.TiffEncoderId;
break;
case GfxFileFormat.Gif:
FileName += "gif";
BitmapEncoderGuid = BitmapEncoder.GifEncoderId;
break;
}
var file = await KnownFolders.DocumentsLibrary.CreateFileAsync(FileName, CreationCollisionOption.ReplaceExisting);
using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoderGuid, stream);
Stream pixelStream = WB.PixelBuffer.AsStream();
byte[] pixels = new byte[pixelStream.Length];
await pixelStream.ReadAsync(pixels, 0, pixels.Length);
encoder.SetPixelData(BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Premultiplied,
(uint)WB.PixelWidth,
(uint)WB.PixelHeight,
96.0,
96.0,
pixels);
await encoder.FlushAsync();
}
}
Zakładki