@@ -171,7 +171,7 @@ Task<Pixbuf> LoadImageAsync(ImageSource imagesource, CancellationToken cancelati
171
171
172
172
public sealed class FileImageSourceHandler : IImageSourceHandler
173
173
{
174
- public Task < Pixbuf > LoadImageAsync (
174
+ public async Task < Pixbuf > LoadImageAsync (
175
175
ImageSource imagesource ,
176
176
CancellationToken cancelationToken = default ( CancellationToken ) ,
177
177
float scale = 1f )
@@ -188,12 +188,15 @@ public Task<Pixbuf> LoadImageAsync(
188
188
189
189
if ( File . Exists ( imagePath ) )
190
190
{
191
- image = new Pixbuf ( imagePath ) ;
191
+ await Device . InvokeOnMainThreadAsync ( ( ) =>
192
+ {
193
+ image = new Pixbuf ( imagePath ) ;
194
+ } ) ;
192
195
}
193
196
}
194
197
}
195
198
196
- return Task . FromResult ( image ) ;
199
+ return image ;
197
200
}
198
201
}
199
202
@@ -210,7 +213,12 @@ public sealed class StreamImagesourceHandler : IImageSourceHandler
210
213
. GetStreamAsync ( cancelationToken ) . ConfigureAwait ( false ) )
211
214
{
212
215
if ( streamImage != null )
213
- image = new Pixbuf ( streamImage ) ;
216
+ {
217
+ await Device . InvokeOnMainThreadAsync ( ( ) =>
218
+ {
219
+ image = new Pixbuf ( streamImage ) ;
220
+ } ) ;
221
+ }
214
222
}
215
223
216
224
return image ;
@@ -238,7 +246,10 @@ public async Task<Pixbuf> LoadImageAsync(
238
246
return null ;
239
247
}
240
248
241
- image = new Pixbuf ( streamImage ) ;
249
+ await Device . InvokeOnMainThreadAsync ( ( ) =>
250
+ {
251
+ image = new Pixbuf ( streamImage ) ;
252
+ } ) ;
242
253
}
243
254
244
255
return image ;
@@ -248,13 +259,13 @@ public async Task<Pixbuf> LoadImageAsync(
248
259
249
260
public sealed class FontImageSourceHandler : IImageSourceHandler
250
261
{
251
- public Task < Pixbuf > LoadImageAsync ( ImageSource imageSource ,
262
+ public async Task < Pixbuf > LoadImageAsync ( ImageSource imageSource ,
252
263
CancellationToken cancellationToken = new CancellationToken ( ) , float scale = 1 )
253
264
{
254
265
if ( ! ( imageSource is FontImageSource fontImageSource ) )
255
266
return null ;
256
267
257
- Pixbuf pixbuf ;
268
+ Pixbuf pixbuf = null ;
258
269
using ( var bmp = new Bitmap ( ( int ) fontImageSource . Size , ( int ) fontImageSource . Size ) )
259
270
{
260
271
using ( var g = Graphics . FromImage ( bmp ) )
@@ -270,11 +281,15 @@ public Task<Pixbuf> LoadImageAsync(ImageSource imageSource,
270
281
using ( var stream = new MemoryStream ( ) )
271
282
{
272
283
bmp . Save ( stream , ImageFormat . Jpeg ) ;
273
- pixbuf = new Pixbuf ( stream . ToArray ( ) ) ;
284
+ await Device . InvokeOnMainThreadAsync ( ( ) =>
285
+ {
286
+ pixbuf = new Pixbuf ( stream . ToArray ( ) ) ;
287
+ } ) ;
288
+
274
289
}
275
290
}
276
291
277
- return Task . FromResult ( pixbuf ) ;
292
+ return pixbuf ;
278
293
}
279
294
280
295
static FontFamily GetFontFamily ( FontImageSource fontImageSource )
0 commit comments