我正在尝试在画布上开发一个应用程序,我在画布上绘制一个位图.绘制后,我试图转换为位图图像.
任何人都可以给我一个建议.
先感谢您.
我正在尝试使用以下函数将位图旋转90度.它的问题在于,当高度和宽度不相等时,它会切断部分图像.
注意returnBitmap width = original.height,它的height = original.width
任何人都可以帮我解决这个问题或指出我做错了什么?
private Bitmap rotateImage90(Bitmap b)
{
Bitmap returnBitmap = new Bitmap(b.Height, b.Width);
Graphics g = Graphics.FromImage(returnBitmap);
g.TranslateTransform((float)b.Width / 2, (float)b.Height / 2);
g.RotateTransform(90);
g.TranslateTransform(-(float)b.Width / 2, -(float)b.Height / 2);
g.DrawImage(b, new Point(0, 0));
return returnBitmap;
}
Run Code Online (Sandbox Code Playgroud) 我必须在热蓝牙打印机上打印一些数据,我正在这样做:
String message="abcdef any message 12345";
byte[] send;
send = message.getBytes();
mService.write(send);
Run Code Online (Sandbox Code Playgroud)
它适用于文本,但不适用于图像.我想我需要获取byte[]图像数据.我尝试以这种方式获取图像的数据:
Bitmap bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.qrcode);
ByteArrayOutputStream stream=new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream);
byte[] image=stream.toByteArray();
Run Code Online (Sandbox Code Playgroud)
不幸的是,打印机会打印出许多奇怪的字符(大约50厘米的纸张).我不知道如何打印图像.
我想尝试获取位图的像素,然后将其转换为a byte[]并发送它,但我不知道该怎么做.
谢谢
更新:
经过这么多时间,我这样做:我有一个名为print_image(String file)的方法,它获取我想要打印的图像的路径:
private void print_image(String file) {
File fl = new File(file);
if (fl.exists()) {
Bitmap bmp = BitmapFactory.decodeFile(file);
convertBitmap(bmp);
mService.write(PrinterCommands.SET_LINE_SPACING_24);
int offset = 0;
while (offset < bmp.getHeight()) {
mService.write(PrinterCommands.SELECT_BIT_IMAGE_MODE);
for (int x = 0; x < bmp.getWidth(); ++x) {
for (int k = 0; k < …Run Code Online (Sandbox Code Playgroud) 如何以编程方式将图像(位图)调整为800*480?我已经在我的应用程序中检索到了大约1MB的图片,我需要将其缩小到800*480我已经加载了该图片并对其进行了压缩但是我该如何缩小它:
ByteArrayOutputStream bos = new ByteArrayOutputStream(8192);
photo.compress(CompressFormat.JPEG, 25, bos);
Run Code Online (Sandbox Code Playgroud) 我选择了控制台应用程序作为我的C#项目.但似乎在Windows窗体项目下工作的导入似乎不适用于此.它表示绘图命名空间不存在.
using System.Drawing;
using System.Drawing.Imaging;
Run Code Online (Sandbox Code Playgroud)
我的问题是我需要有位图类.我正在尝试制作一个命令行应用程序,对图像进行位图操作.这就是为什么我没有选择我的项目作为Windows窗体的一个.
我有一个位图,我想通过编码到base64发送到服务器,但我不想压缩png或jpeg中的图像.
现在我以前做的是.
ByteArrayOutputStream byteArrayBitmapStream = new ByteArrayOutputStream();
bitmapPicture.compress(Bitmap.CompressFormat.PNG, COMPRESSION_QUALITY, byteArrayBitmapStream);
byte[] b = byteArrayBitmapStream.toByteArray();
//then simple encoding to base64 and off to server
encodedImage = Base64.encodeToString(b, Base64.NO_WRAP);
Run Code Online (Sandbox Code Playgroud)
现在我只是不想使用任何压缩,也不想从位图中使用任何格式简单的byte [],我可以编码并发送到服务器.
有什么指针吗?
我在Eclipse Memory Analyzer(也称为MAT)的帮助下分析了我的Android应用程序的内存使用情况.有时我可以找到奇怪的android.graphics.Bitmap类实例,利用大部分堆.问题是我找不到这个位图的来源,没有文件名,没有resourceID,什么都没有.我能找到的关于位图的所有信息如下:

mBuffer我假设有一个带有图像像素阵列的场.但它采用的是一些内部Android格式,而不是PNG.
问题:如何从内存转储中查看此位图表示的图像?
如果使用Windows 7,您可以理解为什么我试图在图像中找到主色.当您将鼠标悬停在任务栏中的程序上时,该特定程序的背景会根据图标中最主要的颜色而变化.我已经注意到其他程序中使用的这种技术,但是不能记住它们.
我可以看到这对我用于开发应用程序的一些UI技术很有用,我想知道如何从Android可绘制资源中找到最常见的颜色.
我有一个ImageView,我想用它rounded corners.
我用这个:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@null"/>
<stroke android:width="1dp"
android:color="#ff000000"/>
<corners android:radius="62px"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
并将此代码设置为我的imageview的背景.它可以工作,但我放在它上面的src图像ImageView是走出边界而不适应新的形状.
我该如何解决这个问题?
大多数时候,在Android上获取OOM是由于使用了太多位图和/或创建大位图.
最近我决定试用JNI,以便通过将数据本身存储在JNI端来避免OOM.
在与JNI搞砸了一段时间后,我在SO上创建了一些帖子,寻求帮助并分享我的知识,现在我决定与你分享更多代码.如果有人有兴趣阅读调查结果或做出贡献,这里有帖子:
这一次,我添加了存储,恢复,裁剪和旋转位图的功能.它应该很容易添加更多选项,如果其他人在这里将自己的代码添加到更有用的功能,我会很高兴.
所以我要展示的代码实际上是合并了我创造的所有东西.
Bitmap bitmap=BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
final int width=bitmap.getWidth(),height=bitmap.getHeight();
// store the bitmap in the JNI "world"
final JniBitmapHolder bitmapHolder=new JniBitmapHolder(bitmap);
// no need for the bitmap on the java "world", since the operations are done on the JNI "world"
bitmap.recycle();
// crop a center square from the bitmap, from (0.25,0.25) to (0.75,0.75) of the bitmap.
bitmapHolder.cropBitmap(width/4,height/4,width*3/4,height*3/4);
//rotate the bitmap:
bitmapHolder.rotateBitmapCcw90();
//get the output java bitmap , …Run Code Online (Sandbox Code Playgroud) java-native-interface android bitmap out-of-memory android-ndk
bitmap ×10
android ×8
bytearray ×2
c# ×2
android-ndk ×1
base64 ×1
colors ×1
drawable ×1
hprof ×1
imageview ×1
java ×1
memory-dump ×1
namespaces ×1