Home > Net >  C # how to realize the transparency of the image edge
C # how to realize the transparency of the image edge

Time:05-25

WPF application, the.net Framework 4,
Want to make images around the edge of the transparent,
Found on the Internet an example on the android, but don't know how to convert c # version,
https://www.cnblogs.com/tangZH/archive/2018/03/15/8551632.html


The original

rendering

CodePudding user response:

Can try along with treatment, the edge pixels

CodePudding user response:

reference 1/f, e 90 response:
can try others processing, processing edge pixels for

Without this knowledge reserve

CodePudding user response:

WPF inside have a ready-made write code that I don't know but I know
 
Bitmap BMP="your image";
//use 32-bit argb mode locking picture
BitmapData bmpData=https://bbs.csdn.net/topics/bmp.LockBits (new Rectangle (Point. The Empty, BMP. Size), ImageLockMode. ReadWrite, PixelFormat. Format32bppArgb);
Byte [] byColor=new byte [bmpData Height * bmpData in Stride];
//bmpData Stride a line of pixels of the number of bytes occupied!=bmpData. Width * (digits/8) (not necessarily equal to Stride is four times as large as the memory alignment aligned)
//bmpData Scan0 pixel data in memory pointer
Marshal. Copy (bmpData Scan0, byColor, 0, byColor. Length);//to pixel data copies out
For (int y=0; Y & lt; BMP. Height; Y++) {
For (int x=0; X & lt; BMP. Width; X++) {
Byte bo yibo=byColor [y * bmpData Stride + (x * 3 + 0)];
Byte byG=byColor [y * bmpData Stride + (x * 3 + 0)];
Byte byR=byColor [y * bmpData Stride + (x * 3 + 0)];
Byte byA=byColor [y * bmpData Stride + (x * 3 + 0)];
//byA is transparent channel transparent you can set it to change the pixel value
//as to how to calculate and transparent edge radius value it depends on yourself lucky
}
}
Marshal. Copy (byColor, 0, bmpData Scan0, byColor. Length);//copy the pixel data back to
BMP. UnlockBits (bmpData);//restore image

CodePudding user response:

reference crystal_lz reply: 3/f
WPF inside have a ready-made write code that I don't know but I know
 
Bitmap BMP="your image";
//use 32-bit argb mode locking picture
BitmapData bmpData=https://bbs.csdn.net/topics/bmp.LockBits (new Rectangle (Point. The Empty, BMP. Size), ImageLockMode. ReadWrite, PixelFormat. Format32bppArgb);
Byte [] byColor=new byte [bmpData Height * bmpData in Stride];
//bmpData Stride a line of pixels of the number of bytes occupied!=bmpData. Width * (digits/8) (not necessarily equal to Stride is four times as large as the memory alignment aligned)
//bmpData Scan0 pixel data in memory pointer
Marshal. Copy (bmpData Scan0, byColor, 0, byColor. Length);//to pixel data copies out
For (int y=0; Y & lt; BMP. Height; Y++) {
For (int x=0; X & lt; BMP. Width; X++) {
Byte bo yibo=byColor [y * bmpData Stride + (x * 3 + 0)];
Byte byG=byColor [y * bmpData Stride + (x * 3 + 0)];
Byte byR=byColor [y * bmpData Stride + (x * 3 + 0)];
Byte byA=byColor [y * bmpData Stride + (x * 3 + 0)];
//byA is transparent channel transparent you can set it to change the pixel value
//as to how to calculate and transparent edge radius value it depends on yourself lucky
}
}
Marshal. Copy (byColor, 0, bmpData Scan0, byColor. Length);//copy the pixel data back to
BMP. UnlockBits (bmpData);//restore image

Byte bo yibo=byColor [y * bmpData Stride + (x * 3 + 0)];
Byte byG=byColor [y * bmpData Stride + (x * 3 + 1)];
Byte byR=byColor [y * bmpData Stride + (x * 3 + 2)];
Byte byA=byColor [y * bmpData Stride + (x * 3 + 3)];
Embarrassed,,,,,,,

CodePudding user response:

Look at this https://blog.csdn.net/zgke/article/details/4532275

Using the gradient transparent brush, direct pixels were provided

CodePudding user response:

refer to the second floor Dear200892 response:
Quote: reference 1/f, e 90 response:
can try others processing, processing edge pixels for

Without this knowledge reserve

CodePudding user response:

The
reference 4 floor crystal_lz reply:

Transparent color bo yibo, byG, byR, byA?

CodePudding user response:

reference 5 floor xuzuning reply:

This I copied to a test program, the size of the transparent area hasn't been changed,

CodePudding user response:

refer to 7th floor Dear200892 response:
Quote: refer to 4th floor crystal_lz response:

Transparent color bo yibo, byG, byR, byA?

it seems that you didn't seem to know what is A R G B,,,,,,,

CodePudding user response:

references 9 f crystal_lz response:

well

CodePudding user response:

I remember that there is a WPF properties of transparency, the gradient have to do is to change the value of this attribute
  •  Tags:  
  • C#
  • Related