| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 480 人关注过本帖
标题:内存法遇到的问题
只看楼主 加入收藏
lz521521
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-5-9
收藏
 问题点数:0 回复次数:0 
内存法遇到的问题
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace WindowsFormsApplication12
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string curFile;
        Bitmap curMap;
        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                curFile = openFileDialog1.FileName;
                curMap = (Bitmap)Image.FromFile(curFile);
 
            }
            Graphics g = this.CreateGraphics();
            Rectangle rect = new Rectangle(50, 50, curMap.Width, curMap.Height);
            g.DrawImage(curMap, rect);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Rectangle rect = new Rectangle(50,50, curMap.Width, curMap.Height);
            System.Drawing.Imaging.BitmapData bmpData = curMap.LockBits(rect,System.Drawing.Imaging.ImageLockMode.ReadWrite,curMap.PixelFormat);//总是提示着有错误的呢
            IntPtr ptr = bmpData.Scan0;
            int bytes = bmpData.Stride * bmpData.Height;
            byte[] rgbValues = new byte[bytes];
            System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
            double colorTemp = 0;
            for (int i = 0; i < bmpData.Height; i++)
            {
                for (int j = 0; j < bmpData.Width * 3; j += 3)
                {
                    colorTemp = rgbValues[i * bmpData.Stride + j + 2] * 0.299 + rgbValues[i * bmpData.Stride + j + 1] * 0.587 + rgbValues[i * bmpData.Stride + j] * 0.114;
                    rgbValues[i * bmpData.Stride + j] = rgbValues[i * bmpData.Stride + j + 1] = rgbValues[i * bmpData.Stride + j + 2] = (byte)colorTemp;
                    System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes);
                    curMap.UnlockBits(bmpData);
                }
            }
        }
    }
}
搜索更多相关主题的帖子: namespace 内存 private public 
2013-05-09 15:02
快速回复:内存法遇到的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025743 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved