社区
C#
帖子详情
如何在两个Bitmap之间复制图像?
limengchen
2002-11-26 04:20:39
将一个Bitmap对象中的一部分复制到另一个Bitmap对象的指定位置,并可以设置透明色?不会一个一个点拷贝吧!
...全文
752
16
打赏
收藏
如何在两个Bitmap之间复制图像?
将一个Bitmap对象中的一部分复制到另一个Bitmap对象的指定位置,并可以设置透明色?不会一个一个点拷贝吧!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
16 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
dy_2000_abc
2002-12-01
打赏
举报
回复
关键在这一句:Graphics g=Graphics.FromHwnd(pictureBox2.Handle);这样,在g上画的东西自然就显示在pictureBox2上了,pictureBox2.Image包含了后来画上去的东西。
limengchen
2002-12-01
打赏
举报
回复
to dy_2000_abc(芝麻开门):
那么如何实现我所说的功能呢?
dy_2000_abc
2002-12-01
打赏
举报
回复
我觉得你可能对Graphics的理解有误,Graphics不是图像对象,你不能在Graphics和Image之间进行转换。
limengchen
2002-12-01
打赏
举报
回复
我现在有几张图片(从文件加载的,因此可以为Image、Graphics、Bitmap或其它形式),想将上面的白色设置为透明色(目前是用Bitmap.MakeTransparent实现),合并(目前是用Graphics.DrawImage实现),然后在PictureBox中显示(PictureBox.Picture属性为Image对象)
不知谁有实现的方法
dy_2000_abc
2002-11-30
打赏
举报
回复
Graphics 类提供将对象绘制到显示设备的方法,Bitmap是用于处理由像素数据定义的图像的对象,你不能将Graphics转成Bitmap的,你试一试下面的语句,pictureBox2的图像将发生变化。
Graphics g=Graphics.FromHwnd(pictureBox2.Handle);
g.DrawImage(bm,0,0,70,70);
dy_2000_abc
2002-11-29
打赏
举报
回复
hope it will be helpful for you.
PictureBox pictureBox1=new PictureBox();
PictureBox pictureBox2=new PictureBox();
...
Bitmap bm=(Bitmap)pictureBox1.Image;
bm.MakeTransparent(bm.GetPixel(0,0));
Graphics g=Graphics.FromHwnd(pictureBox2.Handle);
g.DrawImage(bm,0,0,70,70);\\在特定位置,以特定大小画图
g.Dispose();
limengchen
2002-11-29
打赏
举报
回复
to dy_2000_abc(芝麻开门) :
你的方法只能将image转成bitmap,不能将graphics转成bitmap。
limengchen
2002-11-27
打赏
举报
回复
Sorry,是Graphics转换成Image怎么办?
limengchen
2002-11-27
打赏
举报
回复
但是Graphics转换成Bitmap怎么办?Graphics对象没有Clone方法。
yarshray
2002-11-26
打赏
举报
回复
image.clone();
limengchen
2002-11-26
打赏
举报
回复
to aspcn(飞刀) :
我已经找到那个方法了,叫MakeTransparent。但是,PictureBox.Image只接受Image对象,我怎样才能把一个Graphics对象在PictureBox中显示出来?
aspcn
2002-11-26
打赏
举报
回复
直接画上去就成了.
透明色.Bitmap中有一个方法,我忘记名字了:)
他有一个例子就是教你取点,然后设置透明..
你在帮助中,用"透明"搜索一下就知道了.
limengchen
2002-11-26
打赏
举报
回复
to all:
我现在用Graphics.DrawImage方法复制图像,但无法设置透明色,谁知道如何设置透明色?
qieyj
2002-11-26
打赏
举报
回复
楼上的代码很不错啊.同意,您仔细看看把
snewxf
2002-11-26
打赏
举报
回复
晕!怎么COPY了那么多代码:(55555555555
snewxf
2002-11-26
打赏
举报
回复
之是COP一个图像到剪贴版的例子:
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
int bitmapWidth = this.ClientRectangle.Width;
int bitmapHeight = button1.Top- 20 ;
bitmap = new Bitmap(bitmapWidth, bitmapHeight, this.CreateGraphics());
Graphics g = Graphics.FromImage(bitmap);
g.Clear(this.BackColor);
g.FillEllipse(new SolidBrush(Color.YellowGreen),5,5 ,bitmapWidth - 10, bitmapHeight - 10);
g.DrawRectangle(new Pen(Color.Black, 4.0f), 1, 1, bitmapWidth, bitmapHeight);
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(24, 216);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(104, 23);
this.button1.TabIndex = 0;
this.button1.Text = "copy to cipboard";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(160, 216);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(104, 23);
this.button2.TabIndex = 1;
this.button2.Text = "paste to cipboard data";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button2,
this.button1});
this.Name = "Form1";
this.Text = "Form1";
this.Resize += new System.EventHandler(this.Form1_Resize);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawImage(bitmap , new Rectangle(0,0, this.ClientRectangle.Width, button1.Top -20),0, 0,bitmap.Width, bitmap.Height, GraphicsUnit.Pixel);
}
private void button1_Click(object sender, System.EventArgs e)
{
try
{
Clipboard.SetDataObject(bitmap);
}
catch(Exception exce)
{
MessageBox.Show(exce.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void button2_Click(object sender, System.EventArgs e)
{
try
{
IDataObject dataObject = Clipboard.GetDataObject();
object data = dataObject.GetData(typeof(object));
if(data != null)
{
bitmap = (Bitmap)data;
this.Invalidate(this.ClientRectangle);
}
}
catch(Exception exce)
{
MessageBox.Show(exce.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void Form1_Resize(object sender, System.EventArgs e)
{
button1.Location = new Point(this.ClientRectangle.Width -150, ClientRectangle.Height-50);
button2.Location = new Point(this.ClientRectangle.Width -700, ClientRectangle.Height-50);
this.Invalidate(this.ClientRectangle);
}
}
}
你参考一下!
C++ 实现
两个
图片融合
CImageStatic显示位图类 获得图片像素,在重新融合一张图片。 bgbmp = &m_show1.m_bmp;
bitmap
= &m_show2.m_bmp; p
bitmap
= &m_show3.m_bmp;
bitmap
->Get
Bitmap
(&bmpX;); int
bitmap
Size1 = bmpX.bmHeight * bmpX.bmWidthBytes; BYTE* px=(BYTE *)GlobalAlloc(GPTR,
bitmap
Size1); dwValue =
bitmap
->Get
Bitmap
Bits(
bitmap
Size1, px); bgbmp->Get
Bitmap
(&bmpY;);
bitmap
Size = bmpY.bmHeight * bmpY.bmWidthBytes; BYTE* px1=(BYTE *)GlobalAlloc(GPTR,
bitmap
Size); dwValue2 = bgbmp->Get
Bitmap
Bits(
bitmap
Size,px1);
Bitmap
的
复制
和注意
Bitmap
是不能通过“ A = B ”来传递的,这样只是把B的引用给了A而已 之前做截图的时候就遇到过这个问题,但是没注意,想把截图获得的
bitmap
给ImageView显示,然后回收。发现报错后,就用“ = ”的方法新建了个A,同时回收B。发现还是报错,然后才想起来这个知识点。那么通过什么方法能够把
Bitmap
给
复制
过去呢? ps:这里也说一下,不要把
Bitmap
像我上面那样给ImageVi
android开发从入门到项目
1、课程采用Android Studio【以后简称as】开发,需要有java基础的同学才能看 需要设备电脑推荐 win10 + 手机推荐小米8 2、课程内容围绕着以下五点来讲四大组件(服务、广播、ContentProvider、页面容器)基础UI组件(ListView、ViewPager)异步任务机制(AsyncTask、Handler、线程池)布局优化(层级、绘制、碎片化处理)图片加载(
Bitmap
、缓冲区)3、项目的管理 git工具的使用 4、做项目,通过项目来提升自己 第一个项目【计算器】 5、做项目,第二个新项目【短信接收发送】写一个查话费的小软件
【Android笔记72】Android之
图像
处理相关的类(
Bitmap
)
Bitmap
是Android SDK中提供的一个用于
图像
处理的类,该类位于【android.graphics】包下,是一个final修饰的类,所以该类不可被继承。一个
Bitmap
对象就是一张
图像
、图片,也就是说,我们看见的
图像
图片都是被抽象成了一个
Bitmap
对象。使用
Bitmap
类可以对
图像
进行各种操作,例如:获取
图像
的基本信息、对
图像
进行
复制
、缩放、旋转、裁剪等等操作。
android
复制
bitmap
_Android JNI 之
Bitmap
操作
Android JNI 之
Bitmap
操作在 Android 中通过 JNI 去操作
Bitmap
。在 Android 通过 JNI 去调用
Bitmap
,通过 CMake 去编 so 动态链接库的话,需要添加 jnigraphics
图像
库。target_link_libraries(#Specifiesthetargetlibrary....
C#
110,534
社区成员
642,575
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章