В свойстве IDrawable Drawable MAUI.GraphicsView я хочу нарисовать часть изображения. Это субпрямоугольник исходного изображения.
Проблема: я не могу найти способ обрезать IImage, возвращаемый PlatformImage.FromStream(stream) ни рисовать только часть IImage, используя что-то вроде этой функции Skiasharp, но для Maui.GraphicsView:
public void DrawImage(SkiaSharp.SKImage image, SkiaSharp.SKRect source, SkiaSharp.SKRect dest);
Может ли кто-нибудь предложить способ достижения этой цели?
Для подробностей, вот код, который я хочу расширить: public class GraphicsDrawable : IDrawable
{
public double Scale { get; set; }
public Point Center { get; set; }
public Rect DisplayedRect { get; set; }
private Microsoft.Maui.Graphics.IImage image;
public GraphicsDrawable()
{
// Load image
Assembly assembly = GetType().GetTypeInfo().Assembly;
using (Stream stream = assembly.GetManifestResourceStream("BOBMaui.Resources.Images.bobstart.jpg"))
{
image = PlatformImage.FromStream(stream);
}
}
public void Draw(ICanvas canvas, RectF containerRect)
{
if (image != null)
{
// Anyway, the output will be displayed on containerRect size which is the full size of the container
// STEP 1 - Computes the clipping to apply to image
// Computes scaled size which is the size of the part of the image to be displayed
double scaledWidth = image.Width / Scale;
double scaledHeight = image.Height / Scale;
// Computes horizontal coordinates
double xCenterImageOUT = Center.X * image.Width;
double xLeft = Math.Max(0, xCenterImageOUT - scaledWidth/2); // May not be negative
double xRight = Math.Min(xCenterImageOUT + scaledWidth / 2, image.Width); // May not extend outside base image
if (xRight - xLeft < scaledWidth)
{
// One of the border was forced to 0 or image.Width
if (xLeft == 0) xRight = scaledWidth;
else xLeft = image.Width - scaledWidth;
}
// Computes vertical coordinates
double yCenterImageOUT = Center.Y * image.Height;
double yTop = Math.Max(0, yCenterImageOUT - scaledHeight / 2); // May not be negative
double yBottom = Math.Min(yCenterImageOUT + scaledHeight / 2, image.Height); // May not extend outside base image
if (yBottom - yTop < scaledHeight)
{
// One of the border was forced to 0 or image.Width
if (yTop == 0) yBottom = scaledHeight;
else yBottom = image.Height - scaledHeight;
}
// Define clipping rectangle
DisplayedRect = new Rect(xLeft, yTop, scaledWidth, scaledHeight);
// STEP 2 - Paint the canvas
// There is the problem - I need to crop the image before drawing it
// Sthg like: canvas.DrawImage(image, source: DisplayRect, dest: containerRect);
canvas.DrawImage(image, containerRect.X, containerRect.Y, containerRect.Width, containerRect.Height);
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/781 ... i-graphics
Как нарисовать часть изображения в Maui.Graphics ⇐ C#
Место общения программистов C#
1710840045
Гость
В свойстве IDrawable Drawable MAUI.GraphicsView я хочу нарисовать [b]часть[/b] изображения. Это субпрямоугольник исходного изображения.
Проблема: я не могу найти способ обрезать IImage, возвращаемый PlatformImage.FromStream(stream) ни рисовать только часть IImage, используя что-то вроде этой функции Skiasharp, но для Maui.GraphicsView:
public void DrawImage(SkiaSharp.SKImage image, SkiaSharp.SKRect source, SkiaSharp.SKRect dest);
Может ли кто-нибудь предложить способ достижения этой цели?
Для подробностей, вот код, который я хочу расширить: public class GraphicsDrawable : IDrawable
{
public double Scale { get; set; }
public Point Center { get; set; }
public Rect DisplayedRect { get; set; }
private Microsoft.Maui.Graphics.IImage image;
public GraphicsDrawable()
{
// Load image
Assembly assembly = GetType().GetTypeInfo().Assembly;
using (Stream stream = assembly.GetManifestResourceStream("BOBMaui.Resources.Images.bobstart.jpg"))
{
image = PlatformImage.FromStream(stream);
}
}
public void Draw(ICanvas canvas, RectF containerRect)
{
if (image != null)
{
// Anyway, the output will be displayed on containerRect size which is the full size of the container
// STEP 1 - Computes the clipping to apply to image
// Computes scaled size which is the size of the part of the image to be displayed
double scaledWidth = image.Width / Scale;
double scaledHeight = image.Height / Scale;
// Computes horizontal coordinates
double xCenterImageOUT = Center.X * image.Width;
double xLeft = Math.Max(0, xCenterImageOUT - scaledWidth/2); // May not be negative
double xRight = Math.Min(xCenterImageOUT + scaledWidth / 2, image.Width); // May not extend outside base image
if (xRight - xLeft < scaledWidth)
{
// One of the border was forced to 0 or image.Width
if (xLeft == 0) xRight = scaledWidth;
else xLeft = image.Width - scaledWidth;
}
// Computes vertical coordinates
double yCenterImageOUT = Center.Y * image.Height;
double yTop = Math.Max(0, yCenterImageOUT - scaledHeight / 2); // May not be negative
double yBottom = Math.Min(yCenterImageOUT + scaledHeight / 2, image.Height); // May not extend outside base image
if (yBottom - yTop < scaledHeight)
{
// One of the border was forced to 0 or image.Width
if (yTop == 0) yBottom = scaledHeight;
else yBottom = image.Height - scaledHeight;
}
// Define clipping rectangle
DisplayedRect = new Rect(xLeft, yTop, scaledWidth, scaledHeight);
// STEP 2 - Paint the canvas
// There is the problem - I need to crop the image before drawing it
// Sthg like: canvas.DrawImage(image, source: DisplayRect, dest: containerRect);
canvas.DrawImage(image, containerRect.X, containerRect.Y, containerRect.Width, containerRect.Height);
}
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/78174880/how-to-draw-part-of-image-in-maui-graphics[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия