vb.net Bitmap Drawing,bitmapdrawing

vb.net Bitmap Drawing,bitmapdrawing

Public Class Form1
 Dim BMP As New Drawing.Bitmap(640, 480)
 Dim GFX As Graphics = Graphics.FromImage(BMP)
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  FX.FillRectangle(Brushes.White, 0, 0, PictureBox1.Width, PictureBox1.Height)
  GFX.DrawLine(Pens.Red, 10, 10, 50, 50)
  GFX.DrawString("Robomatics", SystemFonts.DefaultFont, Brushes.Black, 60, 60)
  PictureBox1.Image = BMP
 End Sub
 Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
  BMP.SetPixel(MousePosition.X - Me.Location.X - PictureBox1.Location.X - 4, MousePosition.Y - Me.Location.Y - PictureBox1.Location.Y - 30, Color.Black)
  GFX.DrawString("Robomatics", SystemFonts.DefaultFont, Brushes.Black, MousePosition.X - Me.Location.X - PictureBox1.Location.X - 4, MousePosition.Y -  Me.Location.Y - PictureBox1.Location.Y - 30)
  PictureBox1.Image = BMP
 End Sub
End Class

 

Bitmap Drawing,bitmapdrawing Public Class
Form1Dim BMP As New Drawing.Bitmap(640, 480)Dim GFX As Graphics =
Graphics.FromImage(BMP)Private Sub Button1_Click(ByVal sender
A…

.net core的bitmap使用的是以下类库,但无法在linux运维

C# 使用System.Drawing.Bitmap有问题 5C
using System;
using System.Drawing;

怎么在自定义ImageView上Draw东西,然后拿走为Bitmap?
public class MainActivity extends AppCompatActivity {

原稿链接

namespace yingguang
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(“Hello World”);
Bitmap tempBmp;
}
}
}
Program.cs: error CS0246: 没能找到类型或命名空间名“Bitmap”(是不是贫乏using 指令或程序集援引?)
动用的是vscode 和 .Net core

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); View view= View.inflate(this,R.layout.activity_main,null); //布局参数 ViewGroup.LayoutParams layoutParams=new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); ImageView imageView=new ImageView; //设置布局参数 imageView.setLayoutParams(layoutParams); imageView.setBackgroundColor(Color.RED); //把textview加入RelativeLayout中 ((RelativeLayout)view).addView(imageView); //显示整个布局 setContentView; setContentView(new SmileyView;}

简介

自定义View最入眼的一片段便是钦赐义Draw。依据App供给自定义Draw可粗略可复杂。那篇教程包含了绝大好多常用的插座


在linux运维供给安装runtime.linux-x64.CoreCompat.System.Drawing

}

Override onDraw()

onDraw()是绘制自定义View中最重大的章程。onDraw()的方法的参数是Canvas,Canvas概念了一部分
绘制文字、线、 位图等格局。你能够采纳这么些办法成立和煦的UI。

 https://www.nuget.org/packages/runtime.linux-x64.CoreCompat.System.Drawing

class SmileyView extends View {
private Paint mCirclePaint;
private float mCenterX;
private float mCenterY;
private float mRadius;

Create Drawing Objects

Android图形系统将绘图分为两有个别:

  • 绘制什么:由 Canvas 处理。(What to draw)
  • 怎么绘制:由 Paint 处理。(How to draw)

比如:Canvas提供了主意绘制直线的点子,而Paint提供的措施能够设置直线的颜料。Canvas提供了艺术绘制矩形的法子,而Paint提供的章程能够设置是填写矩形的颜色或则不填充。一句话来讲:Canvas概念绘制到显示器上海体育场面片的形制,Paint概念了你绘制的各个造型的颜料、情势、字体等。

在起头绘制从前,你需求创建八个或三个Paint。上边的例证中在init()方法中开创,并在构造方法中调用:

private void init() { 
    mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);  
    mTextPaint.setColor(mTextColor);
    if (mTextHeight == 0) {       
          mTextHeight = mTextPaint.getTextSize();  
     } else {      
         mTextPaint.setTextSize(mTextHeight);  
     }   
    mPiePaint = new Paint(Paint.ANTI_ALIAS_FLAG);  
    mPiePaint.setStyle(Paint.Style.FILL); 
    mPiePaint.setTextSize(mTextHeight); 
    mShadowPaint = new Paint(0);  
    mShadowPaint.setColor(0xff101010); 
    mShadowPaint.setMaskFilter(new BlurMaskFilter(8,BlurMaskFilter.Blur.NORMAL));   
...

超前创立对象是贰个很首要的优化措施。Views会有时重绘,并且某些绘制的对象在初阶化时会占用非常多的财富。在onDraw()格局中创设对象会分明减弱应用的天性,何况会招致UI卡顿。

 即使您的是.net
core2.0,那么是选取v2类库

 public SmileyView(Context context) { this(context, null);}public SmileyView(Context context, AttributeSet attrs) { this(context, attrs, 0);}public SmileyView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); initPaints();}private void initPaints() { mCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mCirclePaint.setStyle(Paint.Style.FILL); mCirclePaint.setColor(Color.YELLOW);} protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int w = MeasureSpec.getSize(widthMeasureSpec); int h = MeasureSpec.getSize(heightMeasureSpec); int size = Math.min; setMeasuredDimension(size, size); } protected void onSizeChanged(int w, int h, int oldw, int oldh) { mCenterX = w / 2f; mCenterY = h / 2f; mRadius = Math.min / 2f; }protected void onDraw(Canvas canvas) { canvas.drawCircle(mCenterX, mCenterY, mRadius, mCirclePaint); // draw eyes}

Handle Layout Events

为了能够准确的绘图自定义View,你供给通晓它的轻重。复杂的自定义View通常会凭仗它们的高低、形状及在显示器上的岗位举行数次搭架子计算。

虽然View提供了多数甩卖视图大小的方法,可是超越四分之二都不供给重写。如若自定义View没有须要调整它的深浅,你只要求重写onSizeChanged()

onSizeChanged()会在自定义View第3回棉被服装置了大小时调用,当自定义View的轻重发生转移时会再度调用。在onSizeChanged()中总括View的深浅、尺寸以及和自定义View大小相关的任何值,实际不是在每便绘制是都去计算。

亟需小心的是View的轻重包罗了padding值,在测算时毫无遗忘了处理padding值。

 // Account for padding       
float xpad = (float)(getPaddingLeft() + getPaddingRight());       
float ypad = (float)(getPaddingTop() + getPaddingBottom());       
// Account for the label       
if (mShowText) 
    xpad += mTextWidth;       
float ww = (float)w - xpad;       
float hh = (float)h - ypad;       
// Figure out how big we can make the pie.       
float diameter = Math.min(ww, hh);

要是您需求转移自定义View的轻重能够重写onMesure()

@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {   
    // Try for a width based on our minimum   
    int minw = getPaddingLeft() + getPaddingRight() + getSuggestedMinimumWidth();   
    int w = resolveSizeAndState(minw, widthMeasureSpec, 1);   
    // Whatever the width ends up being, ask for a height that would let the pie   
   // get as big as it can   
    int minh = MeasureSpec.getSize(w) - (int)mTextWidth + getPaddingBottom() + getPaddingTop();   
    int h = resolveSizeAndState(MeasureSpec.getSize(w) - (int)mTextWidth, heightMeasureSpec, 0);   
    setMeasuredDimension(w, h);
}

上边的代码有3个基本点:

  • 计算Padding
  • 使用resolveSizeAndState()获取终极的宽高值。resolveSizeAndState()由此将自定义View期望的分寸与onMeasure()MeasureSpec参数里的值相比较后,重临三个MeasureSpec值。
  • onMeasure()从不重返值,而是经过setMeasuredDimension()艺术将管理结果应用到View。必要求调用setMeasuredDimension(),不然会有运转时不当。

https://www.nuget.org/packages/CoreCompat.System.Drawing.v2

}

Draw!

protected void onDraw(Canvas canvas) {   
    super.onDraw(canvas);   
// Draw the shadow   
    canvas.drawOval(mShadowBounds,mShadowPaint);   
// Draw the label text         
    canvas.drawText(mData.get(mCurrentItem).mLabel, mTextX, mTextY, mTextPaint);   
 // Draw the pie slices   
    for (int i = 0; i < mData.size(); ++i) {       
        Item it = mData.get(i);       
        mPiePaint.setShader(it.mShader);       
        canvas.drawArc(mBounds, 360 - it.mEndAngle,  it.mEndAngle - it.mStartAngle,true, mPiePaint);  
    }   
// Draw the pointer   
    canvas.drawLine(mTextX, mPointerY, mPointerX, mPointerY, mTextPaint);   
    canvas.drawCircle(mPointerX, mPointerY, mPointerSize, mTextPaint);
}

下面那么些代码如何修改为在ImageView上展现画的圆,然后把ImageView转化成Bitmap?麻烦具体点,我小白

图片 1

 在centos运营时,始终提醒不能找到gdiplus.dll的借助项,用命令ldd libgdiplus.so,查看 libgdiplus.so的注重性文件,发掘centos缺乏libpcre.so.3文件,把这么些文件从ubunto
/lib64/x86_64-linux-gnu里面复制出来,放到centos
/lib64里面,大概放在你发程序的
runtimes\linux-x64\native 文件里也能够,问题消除

相关文章