我正在尝试将我的Bitmap保存到MemoryStream - 这段代码有什么问题?为什么它让我争论?
private void insertBarCodesToPDF(Bitmap barcode)
{
.......
MemoryStream ms = new MemoryStream();
barcode.Save(ms, System.Drawing.Imaging.ImageFormat.MemoryBmp); //<----
byte [] qwe = ms.ToArray();
.......
}
Run Code Online (Sandbox Code Playgroud)
UPD: WordTest.FormTestWord.insertBarCodesToPDF(位图条形码)中的StackTrace System.Drawing.Image.Save(Stream stream,ImageCodecInfo encoder,EncoderParameters encoderParams)
Please help me out with this Android camera.
The error I get is below:
Unable to resume activity {..,CreatePropertyActivity5}: Failure delivering result ResultInfo{who=null, request=100, result=-1, data=null} to activity..: java.lang.NullPointer
Run Code Online (Sandbox Code Playgroud)
It also gives this warning which is strange since I compress the images:
W/OpenGLRenderer(10242): Bitmap too large to be uploaded into a texture (3264x2448, max=2048x2048)
Run Code Online (Sandbox Code Playgroud)
My app allows the user to select a photo from gallery or take one using camera. As u can figure out from the code there is …
在我的Android应用程序中,我有这个函数,通过画布从旧的位图创建一个新的位图.
private static Bitmap convert(Bitmap bitmap, Bitmap.Config config, int width, int height) {
Bitmap convertedBitmap = Bitmap.createBitmap(width, height, config);
Canvas canvas = new Canvas(convertedBitmap);
Paint paint = new Paint();
paint.setColor(Color.BLACK);
canvas.drawBitmap(bitmap, 0, 0, paint);
bitmap.recycle();
return convertedBitmap;
}
Run Code Online (Sandbox Code Playgroud)
问题是当我将旧位图绘制到画布上时,由于旧位图的尺寸大于画布,因此只有位图的左上部分会在画布上绘制.有没有一种方法可以让它在画布上绘制位图时,它会缩放位图,使其完全适合画布?
我不想使用调整位图的大小createScaledBitmap.有更快的方法吗?
或者我可以做,createScaledBitmap但同时让它变得可变吗?这就是我想要做的整体,调整大小并使其同时变得可变.
谢谢
我想在ImageView(144dp)中显示大位图,但质量不好。位图存储在我的可绘制资源中。
我可以完整显示位图吗?
xml布局:
<ImageView
android:layout_width="144dp"
android:layout_height="144dp"
android:src="@drawable/ic_add"/>
Run Code Online (Sandbox Code Playgroud)
我想要的是:
http://tinypic.com/r/2r7mtz4/8
是)我有的:
查看显示列表为空的大图像。
我从XML获取我的位图:
//Get bitmap from drawable
bd = (BitmapDrawable) view.getResources().getDrawable(R.drawable.backgrounds);
backgrounds = bd.getBitmap();
//Do required work with bitmap (Will just use a log statement here for testing
Log.v("NewTag","Testing: "+bd.getBitmap().getPixel(0, 0));
//Now recycle this large bitmap
bd.getBitmap.recycle();
bd=null;
backgrounds.recycle();
backgrounds=null;
Run Code Online (Sandbox Code Playgroud)
我第一次运行这段代码,一切都很好.但是,当我退出我的应用程序(使用后退键),然后重新启动应用程序,它可能会或可能不会工作.有时,我收到一个错误:
无法在回收的位图上调用getPixel()
为什么?我还没有回收它.或者更确切地说,似乎没有重新创建位图并记住上次回收.
如果我使用BitmapFactory来获取位图,则不会发生此问题(遗憾的是,我不能这样做,因为我必须从XML别名获取此特定位图).
在安装棒棒糖之前,这个工作正常(只要我有bd = null).
我已经连续两天遇到这个问题,所以如果有人能对它发光,我会非常感激.
编辑
我试过@aga建议不要回收/归零bd,但这没什么区别.一旦重新创建(再次,间歇性地),位图仍然"已经"被回收.
此外,当这样记录时:
Log.v("NewTag","Backgrounds: "+backgrounds);
Run Code Online (Sandbox Code Playgroud)
我注意到,当它失败时,记录的引用与前一次相同.所以.....

我正在绘制带边框的自定义背景(从TGraphicControl派生).在DrawBorderRect函数中绘制边框后,我返回"客户端"区域,并希望将来的绘制限制在这个新区域.如果我不使用ClipRgn,一切正常.
工作守则:
var
R : TRect;
begin;
R := GetClientRect; //(R -> 0, 0, 300, 200)
R := DrawBorderRect(R); //(R -> 20, 20, 280, 180)
Canvas.StretchDraw(R, FBitmap); //FBitmap is a 3 pixel x 3 pixel square
end;
Run Code Online (Sandbox Code Playgroud)
上面的代码给了我这个:
但是,我想使用ClipRgn,我尝试了以下内容.这次没有显示模式(但是,如果我单击该区域上的鼠标按钮,则模式显示.所以它正在工作,但由于某种原因会被覆盖?).
有问题的代码:
var
R : TRect;
ClientRegion: HRGN;
begin;
R := GetClientRect; //(R -> 0, 0, 300, 200)
R := DrawBorderRect(R); //(R -> 20, 20, 280, 180)
ClientRegion := CreateRectRgn(R.Left, R.top, R.Right, R.Bottom);
SelectClipRgn(Canvas.Handle, ClientRegion);
try
Canvas.StretchDraw(R, FBitmap); //FBitmap is a 3 …Run Code Online (Sandbox Code Playgroud) 我试图在Android中使用canvas.drawBitmap()方法绘制自定义视图.但是,如果我在本机JNI代码中执行此操作并且背景为黑色,我发现alpha通道将丢失.总结一下,案例是:
bitmap.setPixels()当背景为白色时,调用java 并在NDK中设置位图像素颜色,两个位图都正确显示bitmap.setPixels()当背景为黑色时,调用java 并在NDK中设置位图像素颜色,只有java API绘制的位图正确显示,用NDK绘制的位图丢失alpha通道问题是为什么白色背景上的结果可以,但在黑色背景上不行?我错过了什么或做错了吗?
布局XML文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/black"
android:orientation="horizontal"
android:padding="16dp" >
<com.example.android.TestView
android:id="@+id/testview1"
android:layout_width="320px"
android:layout_height="320px"
android:layout_margin="16dp" />
<com.example.android.TestView
android:id="@+id/testview2"
android:layout_width="320px"
android:layout_height="320px"
android:layout_margin="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="horizontal"
android:padding="16dp" >
<com.example.android.TestView
android:id="@+id/testview3"
android:layout_width="320px"
android:layout_height="320px"
android:layout_margin="16dp" />
<com.example.android.TestView
android:id="@+id/testview4"
android:layout_width="320px"
android:layout_height="320px"
android:layout_margin="16dp" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
MainActivity.java:
package com.example.android;
import com.example.android.R;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends …Run Code Online (Sandbox Code Playgroud) 我有以下简单的代码将剪贴板图像转换为bmp然后转换为png:
if Clipboard.HasFormat(CF_PICTURE) then
begin
bitmap := TBitmap.Create;
png := TPNGImage.Create;
try
bitmap.Assign(Clipboard);
bitmap.SaveToFile(ExtractFilePath(application.ExeName) + '\filename.bmp');
png.Draw(bitmap.Canvas, Rect(0, 0, bitmap.Width, bitmap.Height));
png.SaveToFile(extractfilepath(application.ExeName) + '\filename.png');
finally
bitmap.free;
png.free;
end;
end;
Run Code Online (Sandbox Code Playgroud)
虽然转换为bmp工作,我甚至可以在mspaint中打开它并查看其内容,转换为png失败,我有一个空白的png图像.我究竟做错了什么?
我用文本创建了一个位图,我可以在Imageview中查看它,但是当我保存位图时,我只得到一个黑色图像.我花了三个小时看类似的问题,但没有一个对我有用.这是代码.谢谢你的帮助.
public void createBitmap(){
Bitmap LabelBitmap;
FileOutputStream fos = null;
//create Text Bitmap
LabelBitmap = textAsBitmap(this,"BRO D 0813","fonts/arialbd.ttf", 4, Color.BLACK);
//load bitmap in to Imageview
ImageView myImageView = (ImageView) findViewById(R.id.imageView);
myImageView.setImageBitmap(LabelBitmap);
// save bitmap
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/myfolder");
myDir.mkdirs();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
LabelBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
if (!myDir.exists()) {
myDir.mkdir();
}
File myDirFile = new File(root +"/myfolder/mybitmap.jpg");
try {
if(myDirFile.exists()){
myDirFile.delete();
}
myDirFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
try { …Run Code Online (Sandbox Code Playgroud) 我在互联网上搜索了这个问题,我找不到任何好的东西.我确实在Android开发者网站上查看,但他们将URL中的图像加载到ImageView中.
这是我的代码:
Openfactsscreen活动:
public class Openfactsscreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_openfactsscreen);
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
ImageAdapter adapter = new ImageAdapter(this);
viewPager.setAdapter(adapter);
}
public void openmenu(View view){
Intent intent = new Intent(this, SendFact.class);
startActivity(intent); }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.openfactsscreen, menu);
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
ImageAdapter.java:
public class ImageAdapter extends PagerAdapter {
Context context;
private …Run Code Online (Sandbox Code Playgroud)