0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MAUI Tips - Skia利用時の注意点(画像縮小)

Posted at

概要

カメラで撮影した画像を編集するようなアプリを作成時に、
ちょっと困った話の備忘録

環境

Visual Studio for MAC
.NET MAUI
.NET 7

動作確認はAndroidタブレットとエミュレーターで確認。
他のOS向けビルドでは未確認。

現象

カメラで撮影した画像データを縮小させる処理を考える。
以下のようなソースコードを作成して実行してみたけど、
Downsize関数がNullを返してくる。

 public void SetImage(Stream stream)
{
    IImage image = SkiaImage.FromStream(stream, ImageFormat.Jpeg);
    IImage smallImage = image.Downsize(1024, false);
    // →smallImage1にはnullが代入される。
    //  元のimageも縮小されていなかった。

    //・・・・・・
}

Downsize関数の詳細はこちら
https://learn.microsoft.com/ja-jp/dotnet/api/microsoft.maui.graphics.skia.skiaimage.downsize

とりあえずの回避策

Microsoft.MAUI.GraphicsのIImageのDownsize関数は
正常に動作しているので、一旦こちらで縮小かけて、
SkiaImageのIImageに変換するという荒技で一旦実現。

public void SetImage(Stream stream)
{
    IImage temp = PlatformImage.FromStream(stream, ImageFormat.Jpeg);
    temp = temp.Downsize(1024, false);
    IImage image = SkiaImage.FromStream(temp.AsStream(), ImageFormat.Jpeg);

    //・・・・・・

}

Microsoft.MAUI.GraphicsのIImageから、
SkiaImageに直接変換してくれる処理は無いので、
Streamにして変換してみた・・・。

Microsoft.MAUI.GraphicsもSkiaも初めて使ったけど、
使い方が間違っているんだろうか・・・。
サンプルがかなり少なくて困る・・・。

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?