bitmap

【Android】保存Bitmap到SD卡

ぃ、小莉子 提交于 2020-02-05 00:32:26
1.打开读写SD卡的权限 需要在AndroidManifest.xml加入如下代码: <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 第一种方法: public void saveBitmap(String bitName, Bitmap mBitmap) { File f = new File("/sdcard/" + bitName + ".png"); try { f.createNewFile(); } catch (IOException e) { Tools.ToastShort("在保存图片时出错:" + e.toString()); } FileOutputStream fOut = null; try { fOut = new FileOutputStream(f); } catch (FileNotFoundException e) { e.printStackTrace(); } mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut); try { fOut.flush(); }

Canvas 生成 bitmap

浪尽此生 提交于 2020-02-05 00:30:48
引用: http://wiseideal.iteye.com/blog/1175160 Java代码 int w = 320 ,h = 240 ; String mstrTitle = “感受Android带给我们的新体验”; Bitmap mbmpTest = Bitmap.createBitmap(w,h, Config.ARGB_8888); Canvas canvasTemp = new Canvas(mbmpTest); canvasTemp.drawColor(Color.WHITE); Paint p = new Paint(); String familyName = “宋体”; Typeface font = Typeface.create(familyName,Typeface.BOLD); p.setColor(Color.RED); p.setTypeface(font); p.setTextSize( 22 ); canvasTemp.drawText(mstrTitle, 0 , 100 ,p); 在canvas初始化的时候就传入了一个空的bitmap 最后canvas中绘画的内容都被绘制到了bitmap中,从而得到了我们需要的bitmap 来源: https://www.cnblogs.com/sode/archive/2012/03/08

android保存bitmap到sdcard

Deadly 提交于 2020-02-05 00:26:07
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { //判断sdcard是否存在和是否具有读写权限 try{ String sdcard_path = Environment.getExternalStorageDirectory().getCanonicalPath(); //取得sdcard的路径 File dir=new File(sdcard_path+"/xinyuelantu"); if(!dir.exists()){ //创建目录 dir.mkdir(); } dir=new File(sdcard_path+"/xinyuelantu/browser"); if(!dir.exists()){ dir.mkdir(); } dir=new File(sdcard_path+"/xinyuelantu/browser/favicon"); if(!dir.exists()){ dir.mkdir(); } Calendar calendar= Calendar.getInstance(); //获取当前时间作为图标名字 String year=calendar.get(Calendar.YEAR)+""; String month=calendar.get

android 保存Bitmap 到本地 哦

☆樱花仙子☆ 提交于 2020-02-05 00:24:30
public String saveImage(Bitmap bmp) { File appDir = new File(Environment.getExternalStorageDirectory(), "Boohee"); if (!appDir.exists()) { appDir.mkdir(); } String fileName = System.currentTimeMillis() + ".jpg"; File file = new File(appDir, fileName); try { FileOutputStream fos = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return file.getAbsolutePath();}用 Zxing 生成二维码 并保存到本地的时候 会看到保存本地的是一张黑色的图 但是用imageview 看到的正常的因为 imageview

图片裁剪功能的实现

馋奶兔 提交于 2020-02-04 23:49:01
概述 从4月初到5月份 ,差不多一个多月,终于把裁剪图片的功能码出来了,期间,解决了一个又来一个问题,好吧,问题总是会有的。 这里大致介绍这个裁剪功能技术点、主要难点,实现原理。 技术点 图片缩放、移动 裁剪区域预览 裁剪(包括越图片边界裁剪) 边界限制 主要难点 裁剪区域预览 裁剪 边界限制 实现原理 裁剪预览区域的实现 在我做过的项目中,就有使用过一些网络上开源的裁剪功能:半透明遮罩层的矩形预览框功能。它的实现原理是在裁剪预览区域外的地方填充了几个半透明的矩形框,进而实现了矩形裁剪预览框功能,如下图。 这种功能虽然可以实现预览功能,但是仅仅局限于当预览区外的地方可以通过规则的形状填充,如果是圆形的裁剪预览框,那么就没办法通过这种方式来实现了。 所以我们需要另外想过办法来实现圆形的预览框。在一开始的时候,我这边的思路是通过在半透明的遮罩层上镂空一个预览框。我们来试试在半透明的遮罩层上叠加一个透明的预览框。 public void onDraw(Canvas canvas){ //绘画半透明遮罩 canvas.drawColor(Color.parseColor("#90000000")); Paint paint = new Paint(); paint.setColor(Color.TRANSPARENT); paint.setStyle(Paint.Style.FILL);

Tiny Images, No Rotation, but still get OutOfMemoryError: bitmap size exceeds VM budget

倖福魔咒の 提交于 2020-02-04 11:42:50
问题 I've spent the morning reading through page after page of StackOverflow posts about this exact error, but the root cause of their problems always seems to be either 1) they have very large images which need to be down sampled or 2) they are suffering after one or more device rotations which cause the activity to be destroyed and recreated several times. I'm getting this error (only very rarely), but my app only allows portrait orientation so no rotations are possible and all of my images are

Tiny Images, No Rotation, but still get OutOfMemoryError: bitmap size exceeds VM budget

可紊 提交于 2020-02-04 11:42:06
问题 I've spent the morning reading through page after page of StackOverflow posts about this exact error, but the root cause of their problems always seems to be either 1) they have very large images which need to be down sampled or 2) they are suffering after one or more device rotations which cause the activity to be destroyed and recreated several times. I'm getting this error (only very rarely), but my app only allows portrait orientation so no rotations are possible and all of my images are

Why is copyPixelsFromBuffer giving incorrect color? setPixels is correct but slow

南楼画角 提交于 2020-02-02 11:31:08
问题 For my android app I am getting a ByteBuffer from native code. It contains the pixel color values to create a bitmap. Original image - I used copyPixelsFromBuffer on bitmap, but I am getting incorrect color on displaying the bitmap. Here is the code for this approach - Approach 1 ByteBuffer buffer = ... Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); buffer.rewind(); bitmap.copyPixelsFromBuffer(buffer); Approx. time - ~0.4 ms Result - Wrong colors - Approach 2

Waving text on canvas

走远了吗. 提交于 2020-02-02 06:39:51
问题 How could I make waving text on a canvas element similar to what is found on this page? 回答1: EDIT : @Ben, forget about the downvotes for no reason on your question, and... BE MY GUEST! :) I never coded with <canvas> before, it was very fun. At this point, there is no bilinear interpolation. I might rework it and add more bells and whistles. If you want to achieve such an effect in javascript, you'll effectively have to use the <canvas> tag. The principle consists in precalculating a

BMP保存成string再进行显示

∥☆過路亽.° 提交于 2020-02-01 05:55:38
ifstream in("c:\\Greenstone.bmp", ios::in|ios_base::binary); string s = string((istreambuf_iterator<char>(in)), istreambuf_iterator<char>()); TMemoryStream* ms = new TMemoryStream(); ms->Write(s.c_str(), s.length()); ms->Position = 0; in.close(); Graphics::TBitmap* bitmap = new Graphics::TBitmap(); bitmap->LoadFromStream(ms); this->Image1->Canvas->StretchDraw(Rect(0,0,this->Image1->Width, this->Image1->Height), bitmap); delete bitmap; bitmap = 0; delete ms; ms = 0; 来源: https://www.cnblogs.com/tianfu/archive/2009/11/11/1600907.html