private void panel1_Paint(object sender, PaintEventArgs e)
{
Rectangle r1 = new Rectangle(0, 0, 100, 40);
Rectangle r2 = new Rectangle(14, 194, 100, 40);
e.Graphics.DrawImage(pic, r1, r2, GraphicsUnit.Pixel);
}

  

            #region 图片旋转函数
/// <summary>
/// 以逆时针为方向对图像进行旋转
/// </summary>
/// <param name="b">位图流</param>
/// <param name="angle">旋转角度[0,360](前台给的)</param>
/// <returns></returns>
public Bitmap Rotate(Bitmap b, int angle)
{
angle = angle % 360;
//弧度转换
double radian = angle * Math.PI / 180.0;
double cos = Math.Cos(radian);
double sin = Math.Sin(radian);
//原图的宽和高
int w = b.Width;
int h = b.Height;
int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin)));
int H = (int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos)));
//目标位图
Bitmap dsImage = new Bitmap(W, H);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//计算偏移量
Point Offset = new Point((W - w) / 2, (H - h) / 2);
//构造图像显示区域:让图像的中心与窗口的中心点一致
Rectangle rect = new Rectangle(Offset.X, Offset.Y, w, h);
Point center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
g.TranslateTransform(center.X, center.Y);
g.RotateTransform(360 - angle);
//恢复图像在水平和垂直方向的平移
g.TranslateTransform(-center.X, -center.Y);
g.DrawImage(b, rect);
//重至绘图的所有变换
g.ResetTransform();
g.Save();
g.Dispose();
//dsImage.Save("yuancd.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
return dsImage;
}
#endregion 图片旋转函数

  

<?php
/**
* This class can be used to get the most common colors in an image.
* It needs one parameter:
* $image - the filename of the image you want to process.
* Optional parameters:
*
* $count - how many colors should be returned. 0 mmeans all. default=20
* $reduce_brightness - reduce (not eliminate) brightness variants? default=true
* $reduce_gradients - reduce (not eliminate) gradient variants? default=true
* $delta - the amount of gap when quantizing color values.
* Lower values mean more accurate colors. default=16
*
* Author: Csongor Zalatnai
*
* Modified By: Kepler Gelotte - Added the gradient and brightness variation
* reduction routines. Kudos to Csongor for an excellent class. The original
* version can be found at:
*
* http://www.phpclasses.org/browse/package/3370.html
*
*/
class GetMostCommonColors
{
var $PREVIEW_WIDTH = 150;
var $PREVIEW_HEIGHT = 150; var $error; /**
* Returns the colors of the image in an array, ordered in descending order, where the keys are the colors, and the values are the count of the color.
*
* @return array
*/
function Get_Color( $img, $count=20, $reduce_brightness=true, $reduce_gradients=true, $delta=16 )
{
if (is_readable( $img ))
{
if ( $delta > 2 )
{
$half_delta = $delta / 2 - 1;
}
else
{
$half_delta = 0;
}
// WE HAVE TO RESIZE THE IMAGE, BECAUSE WE ONLY NEED THE MOST SIGNIFICANT COLORS.
$size = GetImageSize($img);
$scale = 1;
if ($size[0]>0)
$scale = min($this->PREVIEW_WIDTH/$size[0], $this->PREVIEW_HEIGHT/$size[1]);
if ($scale < 1)
{
$width = floor($scale*$size[0]);
$height = floor($scale*$size[1]);
}
else
{
$width = $size[0];
$height = $size[1];
}
$image_resized = imagecreatetruecolor($width, $height);
if ($size[2] == 1)
$image_orig = imagecreatefromgif($img);
if ($size[2] == 2)
$image_orig = imagecreatefromjpeg($img);
if ($size[2] == 3)
$image_orig = imagecreatefrompng($img);
// WE NEED NEAREST NEIGHBOR RESIZING, BECAUSE IT DOESN'T ALTER THE COLORS
imagecopyresampled($image_resized, $image_orig, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
$im = $image_resized;
$imgWidth = imagesx($im);
$imgHeight = imagesy($im);
$total_pixel_count = 0;
for ($y=0; $y < $imgHeight; $y++)
{
for ($x=0; $x < $imgWidth; $x++)
{
$total_pixel_count++;
$index = imagecolorat($im,$x,$y);
$colors = imagecolorsforindex($im,$index);
// ROUND THE COLORS, TO REDUCE THE NUMBER OF DUPLICATE COLORS
if ( $delta > 1 )
{
$colors['red'] = intval((($colors['red'])+$half_delta)/$delta)*$delta;
$colors['green'] = intval((($colors['green'])+$half_delta)/$delta)*$delta;
$colors['blue'] = intval((($colors['blue'])+$half_delta)/$delta)*$delta;
if ($colors['red'] >= 256)
{
$colors['red'] = 255;
}
if ($colors['green'] >= 256)
{
$colors['green'] = 255;
}
if ($colors['blue'] >= 256)
{
$colors['blue'] = 255;
} } $hex = substr("0".dechex($colors['red']),-2).substr("0".dechex($colors['green']),-2).substr("0".dechex($colors['blue']),-2); if ( ! isset( $hexarray[$hex] ) )
{
$hexarray[$hex] = 1;
}
else
{
$hexarray[$hex]++;
}
}
} // Reduce gradient colors
if ( $reduce_gradients )
{
// if you want to *eliminate* gradient variations use:
// ksort( &$hexarray );
arsort( &$hexarray, SORT_NUMERIC ); $gradients = array();
foreach ($hexarray as $hex => $num)
{
if ( ! isset($gradients[$hex]) )
{
$new_hex = $this->_find_adjacent( $hex, $gradients, $delta );
$gradients[$hex] = $new_hex;
}
else
{
$new_hex = $gradients[$hex];
} if ($hex != $new_hex)
{
$hexarray[$hex] = 0;
$hexarray[$new_hex] += $num;
}
}
} // Reduce brightness variations
if ( $reduce_brightness )
{
// if you want to *eliminate* brightness variations use:
// ksort( &$hexarray );
arsort( &$hexarray, SORT_NUMERIC ); $brightness = array();
foreach ($hexarray as $hex => $num)
{
if ( ! isset($brightness[$hex]) )
{
$new_hex = $this->_normalize( $hex, $brightness, $delta );
$brightness[$hex] = $new_hex;
}
else
{
$new_hex = $brightness[$hex];
} if ($hex != $new_hex)
{
$hexarray[$hex] = 0;
$hexarray[$new_hex] += $num;
}
}
} arsort( &$hexarray, SORT_NUMERIC ); // convert counts to percentages
foreach ($hexarray as $key => $value)
{
$hexarray[$key] = (float)$value / $total_pixel_count;
} if ( $count > 0 )
{
// only works in PHP5
// return array_slice( $hexarray, 0, $count, true ); $arr = array();
foreach ($hexarray as $key => $value)
{
if ($count == 0)
{
break;
}
$count--;
$arr[$key] = $value;
}
return $arr;
}
else
{
return $hexarray;
} }
else
{
$this->error = "Image ".$img." does not exist or is unreadable";
return false;
}
} function _normalize( $hex, $hexarray, $delta )
{
$lowest = 255;
$highest = 0;
$colors['red'] = hexdec( substr( $hex, 0, 2 ) );
$colors['green'] = hexdec( substr( $hex, 2, 2 ) );
$colors['blue'] = hexdec( substr( $hex, 4, 2 ) ); if ($colors['red'] < $lowest)
{
$lowest = $colors['red'];
}
if ($colors['green'] < $lowest )
{
$lowest = $colors['green'];
}
if ($colors['blue'] < $lowest )
{
$lowest = $colors['blue'];
} if ($colors['red'] > $highest)
{
$highest = $colors['red'];
}
if ($colors['green'] > $highest )
{
$highest = $colors['green'];
}
if ($colors['blue'] > $highest )
{
$highest = $colors['blue'];
} // Do not normalize white, black, or shades of grey unless low delta
if ( $lowest == $highest )
{
if ($delta <= 32)
{
if ( $lowest == 0 || $highest >= (255 - $delta) )
{
return $hex;
}
}
else
{
return $hex;
}
} for (; $highest < 256; $lowest += $delta, $highest += $delta)
{
$new_hex = substr("0".dechex($colors['red'] - $lowest),-2).substr("0".dechex($colors['green'] - $lowest),-2).substr("0".dechex($colors['blue'] - $lowest),-2); if ( isset( $hexarray[$new_hex] ) )
{
// same color, different brightness - use it instead
return $new_hex;
}
} return $hex;
} function _find_adjacent( $hex, $gradients, $delta )
{
$red = hexdec( substr( $hex, 0, 2 ) );
$green = hexdec( substr( $hex, 2, 2 ) );
$blue = hexdec( substr( $hex, 4, 2 ) ); if ($red > $delta)
{
$new_hex = substr("0".dechex($red - $delta),-2).substr("0".dechex($green),-2).substr("0".dechex($blue),-2);
if ( isset($gradients[$new_hex]) )
{
return $gradients[$new_hex];
}
}
if ($green > $delta)
{
$new_hex = substr("0".dechex($red),-2).substr("0".dechex($green - $delta),-2).substr("0".dechex($blue),-2);
if ( isset($gradients[$new_hex]) )
{
return $gradients[$new_hex];
}
}
if ($blue > $delta)
{
$new_hex = substr("0".dechex($red),-2).substr("0".dechex($green),-2).substr("0".dechex($blue - $delta),-2);
if ( isset($gradients[$new_hex]) )
{
return $gradients[$new_hex];
}
} if ($red < (255 - $delta))
{
$new_hex = substr("0".dechex($red + $delta),-2).substr("0".dechex($green),-2).substr("0".dechex($blue),-2);
if ( isset($gradients[$new_hex]) )
{
return $gradients[$new_hex];
}
}
if ($green < (255 - $delta))
{
$new_hex = substr("0".dechex($red),-2).substr("0".dechex($green + $delta),-2).substr("0".dechex($blue),-2);
if ( isset($gradients[$new_hex]) )
{
return $gradients[$new_hex];
}
}
if ($blue < (255 - $delta))
{
$new_hex = substr("0".dechex($red),-2).substr("0".dechex($green),-2).substr("0".dechex($blue + $delta),-2);
if ( isset($gradients[$new_hex]) )
{
return $gradients[$new_hex];
}
} return $hex;
}
}
?>

  

c# 如何显示图片指定位置的更多相关文章

  1. img只显示图片一部分 或 css设置背景图片只显示图片指定区域

    17:14 2016/3/22img只显示图片一部分 或 css设置背景图片只显示图片指定区域 background-position: 100% 56%; 设置背景图片显示图片的哪个坐标区域,图片左 ...

  2. Android 如何动态添加 View 并显示在指定位置。

    引子 最近,在做产品的需求的时候,遇到 PM 要求在某个按钮上添加一个新手引导动画,引导用户去点击.作为 RD,我哗啦啦的就写好相关逻辑了.自测完成后,提测,PM Review 效果. 看完后,PM ...

  3. Java 替换word文档文字,指定位置插入图片

    先说下 需要的依赖包 <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ex ...

  4. (转载) popupWindow 指定位置上的显示

    popupWindow 指定位置上的显示 标签: androidpopupWindowpopupWindow具体位置放置 2014-07-09 16:23 1114人阅读 评论(0) 收藏 举报  分 ...

  5. C#全屏随机位置显示图片的小程序

    想法:将屏幕截图作为程序背景图,在之上弹出提示窗口,选择确定后进行定时图片随机位置显示.(支持ESC键退出) 需要添加的控件:Timer 需要修改的Form1属性为下图红色区域: 资源文件的添加:添加 ...

  6. $.messager.show扩展:指定位置显示

    扩展了个$.messager.showBySite,根据舍得的位置显示$.messager.show.代码如下: /** * 指定位置显示$.messager.show * options $.mes ...

  7. Qt 关于图片打开,另存为,保存到指定位置操作

    Qt 关于图片打开,另存为,保存到指定位置操作(转载) 在头文件mainwindow.h中先声明以下类: 1 #include <QImage> 2 #include <QPixma ...

  8. 解决使用 Eruda 绑定 dom 未在指定位置显示问题

    前言 开发项目中,使用到 Eruda 打印控制台信息显示 文档:https://github.com/liriliri/eruda 安装 Eruda npm install eruda --save ...

  9. Java Struts图片上传至指定文件夹并显示图片

    继上一次利用Servlet实现图片上传,这次利用基于MVC的Struts框架,封装了Servlet并简化了JSP页面跳转. JSP上传页面 上传一定要为form加上enctype="mult ...

随机推荐

  1. EJBCA于Linux安装在

    于windows为了测试安装,装在linuxserver因为CN使用ip需要重新加载.....再折腾.这里有一些地方需要注意 一.所需文件 内容准备不说,请参阅我在以前的文章<EJBCA于win ...

  2. JMS样本

    1.JMS它是一个制作AS提供Message服务.它接受由生成的消息(Message Provider)消息发出,并转发消息到消息消费者(Message  Consumer).2.JMS提供2的消息服 ...

  3. javascript系列之DOM(一)

    原文:javascript系列之DOM(一) DOM(document object moudle),文档对象模型.它是一个中立于语言的应用程序接口(API),允许程序访问并修改文档的结构,内容和样式 ...

  4. Android apk file

    apk file 事实上zip文件. 您可以使用unzip命令提取. unzip example1.apk -d ./example_dir tree . ├── AndroidManifest.xm ...

  5. PHP和MySQL Web开发 原书第4版 高清文字版,有目录,附带源码

    PHP和MySQL Web开发  原书第4版:http://yunpan.cn/QCWIS25zmYTAn  提取码 fd9b PHP和MySQL Web开发  原书第4版源码:http://yunp ...

  6. CSS3火焰文字特效制作教程

    原文:CSS3火焰文字特效制作教程 用一句很俗气的话概括这两天的情况就是:“最近很忙”,虽然手头上有不少很酷的HTML5和CSS3资源,但确实没时间将它们的实现过程写成教程分享给大家.今天刚完成了一个 ...

  7. Android开展Exception:ActivityNotFoundException: Unable to find explicit activity class

    project出现在一个以上的activity,不AndroidManifest.xml配置,在阅读的时候,你需要知道的配置activity,使用时间或忘记配置.流汗!配置activity后proje ...

  8. Android Bluetooth Stack: Bluedroid(五岁以下儿童):The analysis of A2DP Source

    1. A2DP Introduction The Advanced Audio Distribution Profile (A2DP) defines the protocols and proced ...

  9. java通过SVG导出图片

    import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; import ja ...

  10. CSS3实战开发: 纯CSS实现图片过滤分类显示特效

    原文:CSS3实战开发: 纯CSS实现图片过滤分类显示特效 各位网友大家好,今天我要带领大家开发一个纯CSS的图片分类显示的网址导航,单纯看标题大家可能有些困惑,依照以往惯例,我先给大家演示一下实际运 ...