Hỏi đáp
Chia sẻ kiến thức, cùng nhau phát triển
Chào anh Long, anh cho em hỏi: Hiện em đang thử hiển thị 3 ảnh RGB lên WPF nhưng không được. Mong anh và mọi người giúp đỡ em
MainWindow.xaml:
MainWindow.xaml.cs:
Chào anh Long, anh cho em hỏi: Hiện em đang thử hiển thị 3 ảnh RGB lên WPF nhưng không được. Mong anh và mọi người giúp đỡ em
MainWindow.xaml:
<Window x:Class="Tách_hình_thành_3_kênh_màu_RGB.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Tách_hình_thành_3_kênh_màu_RGB"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="1000">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBlock Text="Hình gốc:" FontSize="20"></TextBlock>
<Image x:Name="ImgRoot" Stretch="Fill"></Image>
</StackPanel>
<StackPanel Grid.Column="1">
<TextBlock Text="Hình đỏ (RED):" FontSize="20"></TextBlock>
<Image x:Name="ImgRed" Stretch="Fill"></Image>
</StackPanel>
<StackPanel Grid.Column="2">
<TextBlock Text="Hình xanh lá (GREEN):" FontSize="20"></TextBlock>
<Image x:Name="ImgGreen" Stretch="Fill"></Image>
</StackPanel>
<StackPanel Grid.Column="3">
<TextBlock Text="Hình xanh nước biển (BLUE):" FontSize="20"></TextBlock>
<Image x:Name="ImgBlue" Stretch="Fill"></Image>
</StackPanel>
</Grid>
</Window>
12345678910111213141516171819202122232425262728293031323334
MainWindow.xaml.cs:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Tách_hình_thành_3_kênh_màu_RGB
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
string FileHinh = @"F:\Hình ảnh trên mạng\Hình ảnh trên mạng\Vương Vũ Tiệp\3.jpg";
ImgRoot.Source = new BitmapImage(new Uri(FileHinh));
Bitmap hinhgoc = new Bitmap(FileHinh);
Bitmap Red = new Bitmap(hinhgoc.Width, hinhgoc.Height);
Bitmap Green = new Bitmap(hinhgoc.Width, hinhgoc.Height);
Bitmap Blue = new Bitmap(hinhgoc.Width, hinhgoc.Height);
for (int x = 0; x < hinhgoc.Width; x++)
{
for (int y = 0; y < hinhgoc.Height; y++)
{
System.Drawing.Color pixel = hinhgoc.GetPixel(x, y);
byte R = pixel.R;
byte G = pixel.G;
byte B = pixel.B;
byte A = pixel.A;
Red.SetPixel(x, y, System.Drawing.Color.FromArgb(A, R, 0, 0));
Green.SetPixel(x, y, System.Drawing.Color.FromArgb(A, 0, G, 0));
Blue.SetPixel(x, y, System.Drawing.Color.FromArgb(A, 0, 0, B));
}
}
}
}
}
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
Để sử dụng tính năng này, Bạn cần đăng nhập bằng tài khoản Howkteam.
Đăng nhập
Để xem được nội dung và giúp Kteam duy trì hoạt động.
Bạn vui lòng tắt Adblock trên website howkteam.vn nhé!
rgb 1
rgb2