社区
C#
帖子详情
Bitmap(INT,INT,INT,PixelFormat,BYTE*)这种方式创建的位图是创建了BYTE*的一个备份,还是基于BYTE*的呢。
laviewpbt
2012-08-28 11:10:45
如果我用这中方式创建了一个图像,然后释放了BYTE*所占用的内存,会对Bitmap有影响吗,期望有做过的朋友指点下。
...全文
137
4
打赏
收藏
Bitmap(INT,INT,INT,PixelFormat,BYTE*)这种方式创建的位图是创建了BYTE*的一个备份,还是基于BYTE*的呢。
如果我用这中方式创建了一个图像,然后释放了BYTE*所占用的内存,会对Bitmap有影响吗,期望有做过的朋友指点下。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
4 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
laviewpbt
2012-09-13
打赏
举报
回复
看看是不是还是404.
laviewpbt
2012-09-13
打赏
举报
回复
看看是不是还是404.
KingOfPorcupine
2012-08-29
打赏
举报
回复
vb 调用 getdibits 函数获得数组元素全部为0的问题
http://topic.csdn.net/u/20120824/19/cb61d023-55fa-4042-9fc2-5c33e23e967c.html?seed=1472340505&r=79535654#r_79535654
KingOfPorcupine
2012-08-29
打赏
举报
回复
楼主 我的问题你回答了1半的 能把剩下的一半全答了好么 新人不容易啊
楼主好人
楼主好人
楼主好人
楼主好人
楼主好人
C#中将
byte
数组转换为8bit灰度图像
C#中将
byte
数组转换为8bit灰度图像
Android Drawable、
Bitmap
、
byte
、灰度 转换
Android Drawable、
Bitmap
、
byte
、灰度 转换
C#生成单色
位图
的方法.zip_C# 单色
位图
_C# 单色
位图
_C# 图片转单色_c#单色
位图
使用C# 生成单色
位图
,并且为图片添加信息头
android
Bitmap
用法总结
android
Bitmap
用法总结
Bitmap
用法总结 1、Drawable →
Bitmap
public static
Bitmap
drawableTo
Bitmap
(Drawable drawable) {
Bitmap
bitmap
=
Bitmap
.create
Bitmap
( drawable.get
Int
rinsicWidth(), drawable.get
Int
rinsicHeight(), drawable.getOpacity() !=
Pixel
Format
.OPAQUE ?
Bitmap
.Config.ARGB_8888 :
Bitmap
.Config.RGB_565); Canvas canvas = new Canvas(
bitmap
); // canvas.set
Bitmap
(
bitmap
); drawable.setBounds(0, 0, drawable.get
Int
rinsicWidth(), drawable.get
Int
rinsicHeight()); drawable.draw(canvas); return
bitmap
; } 2、从资源中获取
Bitmap
Resources res=getResources();
Bitmap
bmp=
Bitmap
Factory.decodeResource(res, R.drawable.pic); 3、
Bitmap
→
byte
[] private
byte
[]
Bitmap
2
Byte
s(
Bitmap
bm){
Byte
ArrayOutputStream baos = new
Byte
ArrayOutputStream(); bm.compress(
Bitmap
.Compress
Format
.PNG, 100, baos); return baos.to
Byte
Array(); } 4、
byte
[] →
Bitmap
private
Bitmap
Byte
s2Bimap(
byte
[] b){ if(b.length!=0){ return
Bitmap
Factory.decode
Byte
Array(b, 0, b.length); } else { return null; } } 5、保存
bitmap
static boolean save
Bitmap
2file(
Bitmap
bmp,String filename){ Compress
Format
format
=
Bitmap
.Compress
Format
.JPEG;
int
quality = 100; OutputStream stream = null; try { stream = new FileOutputStream("/sdcard/" + filename); } catch (FileNotFoundException e) { // TODO Auto-generated catch block Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only. e.pr
int
StackTrace(); } return bmp.compress(
format
, quality, stream); } 6、将图片按自己的要求缩放 // 图片源
Bitmap
bm =
Bitmap
Factory.decodeStream(getResources() .openRawResource(R.drawable.dog)); // 获得图片的宽高
int
width = bm.getWidth();
int
height = bm.getHeight(); // 设置想要的大小
int
newWidth = 320;
int
newHeight = 480; // 计算缩放比例 float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; // 取得想要缩放的matrix参数 Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); // 得到新的图片
Bitmap
newbm =
Bitmap
.create
Bitmap
(bm, 0, 0, width, height, matrix, true); // 放在画布上 canvas.draw
Bitmap
(newbm, 0, 0, pa
int
); 相关知识链接:http://www.eoeandroid.com/thread-3162-1-1.html 7、
bitmap
的用法小结
Bitmap
Factory.Options option = new
Bitmap
Factory.Options(); option.inSampleSize = 2; //将图片设为原来宽高的1/2,防止内存溢出
Bitmap
bm =
Bitmap
Factory.decodeFile("",option);//文件流 URL url = new URL(""); InputStream is = url.openStream();
Bitmap
bm =
Bitmap
Factory.decodeStream(is); android:scaleType: android:scaleType是控制图片如何resized/moved来匹对ImageView的size。ImageView.ScaleType / android:scaleType值的意义区别: CENTER /center 按图片的原来size居中显示,当图片长/宽超过View的长/宽,则截取图片的居中部分 显示 CENTER_CROP / centerCrop 按比例扩大图片的size居中显示,使得图片长(宽)等于或大于View的长 (宽) CENTER_INSIDE / centerInside 将图片的内容完整居中显示,通过按比例缩小或原来的size使得图片 长/宽等于或小于View的长/宽 Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only. FIT_CENTER / fitCenter 把图片按比例扩大/缩小到View的宽度,居中显示 FIT_END / fitEnd 把图片按比例扩大/缩小到View的宽度,显示在View的下部分位置 FIT_START / fitStart 把图片按比例扩大/缩小到View的宽度,显示在View的上部分位置 FIT_XY / fitXY 把图片 不按比例 扩大/缩小到View的大小显示 MATRIX / matrix 用矩阵来绘制,动态缩小放大图片来显示。 //放大缩小图片 public static
Bitmap
zoom
Bitmap
(
Bitmap
bitmap
,
int
w,
int
h){
int
width =
bitmap
.getWidth();
int
height =
bitmap
.getHeight(); Matrix matrix = new Matrix(); float scaleWidht = ((float)w / width); float scaleHeight = ((float)h / height); matrix.postScale(scaleWidht, scaleHeight);
Bitmap
newbmp =
Bitmap
.create
Bitmap
(
bitmap
, 0, 0, width, height, matrix, true); return newbmp; } //将Drawable转化为
Bitmap
public static
Bitmap
drawableTo
Bitmap
(Drawable drawable){
int
width = drawable.get
Int
rinsicWidth();
int
height = drawable.get
Int
rinsicHeight();
Bitmap
bitmap
=
Bitmap
.create
Bitmap
(width, height, drawable.getOpacity() !=
Pixel
Format
.OPAQUE ?
Bitmap
.Config.ARGB_8888 :
Bitmap
.Config.RGB_565); Canvas canvas = new Canvas(
bitmap
); drawable.setBounds(0,0,width,height); drawable.draw(canvas); return
bitmap
; Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only. } //获得圆角图片的方法 public static
Bitmap
getRoundedCorner
Bitmap
(
Bitmap
bitmap
,float roundPx){
Bitmap
output =
Bitmap
.create
Bitmap
(
bitmap
.getWidth(),
bitmap
.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final
int
color = 0xff424242; final Pa
int
pa
int
= new Pa
int
(); final Rect rect = new Rect(0, 0,
bitmap
.getWidth(),
bitmap
.getHeight()); final RectF rectF = new RectF(rect); pa
int
.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); pa
int
.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, pa
int
); pa
int
.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.draw
Bitmap
(
bitmap
, rect, rect, pa
int
); return output; } //获得带倒影的图片方法 public static
Bitmap
createReflectionImageWithOrigin(
Bitmap
bitmap
){ final
int
reflectionGap = 4;
int
width =
bitmap
.getWidth();
int
height =
bitmap
.getHeight(); Matrix matrix = new Matrix(); matrix.preScale(1, -1);
Bitmap
reflectionImage =
Bitmap
.create
Bitmap
(
bitmap
, 0, height/2, width, height/2, matrix, false);
Bitmap
bitmap
WithReflection =
Bitmap
.create
Bitmap
(width, (height + height/2), Config.ARGB_8888); Canvas canvas = new Canvas(
bitmap
WithReflection); canvas.draw
Bitmap
(
bitmap
, 0, 0, null); Pa
int
deafalutPa
int
= new Pa
int
(); Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only. canvas.drawRect(0, height,width,height + reflectionGap, deafalutPa
int
); canvas.draw
Bitmap
(reflectionImage, 0, height + reflectionGap, null); Pa
int
pa
int
= new Pa
int
(); LinearGradient shader = new LinearGradient(0,
bitmap
.getHeight(), 0,
bitmap
WithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP); pa
int
.setShader(shader); // Set the Transfer mode to be porter duff and destination in pa
int
.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); // Draw a rectangle using the pa
int
with our linear gradient canvas.drawRect(0, height, width,
bitmap
WithReflection.getHeight() + reflectionGap, pa
int
); return
bitmap
WithReflection; } }
Android Drawable、
Bitmap
、
byte
、灰度 之间的转换
Android Drawable、
Bitmap
、
byte
、灰度 之间的转换
C#
111,126
社区成员
642,541
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章