我有一个位图,其尺寸比将要绘制到的画布的尺寸更大。任何人都可以建议一种将这个位图在画布上居中的方法,即位图的中心点应该与画布的中心点重叠吗?
我有一个应用程序,用户将一堆位图保存在 SD 卡上的文件夹中。我想添加一个功能,用户可以在其中将所述位图导出为 .gif 文件,该文件可以在文本消息中查看。我怎样才能做到这一点?
我不敢承认,我已经有一段时间没有使用 C++了,但我现在不得不使用了,而且我有点生疏了。
我需要一个位图,而且我确实关心性能,我的位图大小将不再是 25 位。
我正在考虑使用 unsigned int,但恐怕我不记得它是如何在 c/c++ 中
实现的 unsigned int 是作为常规二进制数实现的吗?
我也对位图的任何其他建议持开放态度。
在此先感谢您的帮助!
首先我调用 MediaStore.ACTION_IMAGE_CAPTURE 意图打开相机然后我从这个函数中获取保存的捕获图像路径。
private String getLastImageId(){
String[] imageColumns = { MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA };
String imageOrderBy = MediaStore.Images.Media._ID+" DESC";
Cursor imageCursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, imageColumns, null, null, imageOrderBy);
if(imageCursor.moveToFirst()){
int id = imageCursor.getInt(imageCursor.getColumnIndex(MediaStore.Images.Media._ID));
String fullPath = imageCursor.getString(imageCursor.getColumnIndex(MediaStore.Images.Media.DATA));
//imageCursor.close();
return fullPath;
}else{
return "";
}
}
Run Code Online (Sandbox Code Playgroud)
然后我将该路径作为参数传递给产品对象属性。将该对象添加到由自定义适配器显示的产品列表中。我在 listView 中显示产品标题和图片
在定制的适配器类中,我得到产品从它获取产品标题和路径从路径制作位图并将其分配给包含图像视图的产品持有人,第一张照片以这种方式工作很好,但在第二张照片上它给出了例外java.lang.outofmemory 我也试过给出的解决方案
java.lang.OutOfMemoryError:位图大小超出 VM 预算 - Android
在产品适配器中这样做
public class ProductAdopter extends ArrayAdapter<Product> {
Context context;
int layoutResourceId;
ArrayList<Product> data = null;
public ProductAdopter(Context context, int layoutResourceId, ArrayList<Product> product_data) {
// TODO Auto-generated constructor …Run Code Online (Sandbox Code Playgroud) 我正在尝试加载一个图像(PNG)到 ImageView。此 PNG 文件的文件大小为 390.6KB。
一旦我将此 PNG 文件解码为位图,位图大小> 9MB。但位图的宽度和高度分别为 1920 和 1280。
为什么位图的大小 > ( bitmap.width * bitmap.height )?9MB 对于我的应用程序来说已经很大了,它加载了许多像这样的其他图像。
当我尝试通过给出样本大小 (2/4) 来对该图像进行采样时,图像的宽度和高度随着位图的大小而变化。
如何在内存大小中缩放此图像,但保留图像的宽度和高度?
我正在寻找一种将位图图像包裹在画布周围的方法,以获得无限滚动效果。我在看 EaselJS 但干净的 javascript 代码也足够了。
现在我正在向左移动一个图像,当它达到某个标记时,它会自行重置。
来自动作脚本,有一个选项可以将位图的像素“包裹”到另一侧,从而永远不会真正替换图像,而是将像素包裹在图像内。这在带有画布的javascript中可能吗?
我目前的代码:
this.update = function() {
// super large graphic
_roadContainer.x -= 9;
if(_roadContainer.x < -291) _roadContainer.x = 0;
}
Run Code Online (Sandbox Code Playgroud) 我对新位图有问题,它说该参数无效。
Bitmap image = new Bitmap("..//..//images//brick.jpg");
Run Code Online (Sandbox Code Playgroud)
我的项目中有文件夹图像,其中包含brick.jpg. 在其他示例中,使用方法相同,但在这里我遇到了问题。
您知道发生了什么以及可能导致此问题的原因吗?
我正在使用图片尺寸类型 2^n。图片是4kb。这是一个 Visual Studio 项目,而不是一个 Web 应用程序。
这是一个运行时错误。
解决方案:
这对我有帮助,因为它在错误的地方 Console.WriteLine(new System.IO.FileInfo("..//..//images//brick.jpg").FullName);
谢谢
我的问题是如何将位图发送到 Whastapp 应用程序,我使用以下代码;
ImageView iv=(ImageView)view.findViewById(R.id.item_image);
Bitmap bitmap = ((BitmapDrawable)iv.getDrawable()).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
PackageInfo info=pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
//Check if package exists or not. If not then code
//in catch block will be called
waIntent.setPackage("com.whatsapp");
waIntent.setType("image/png");
waIntent.putExtra(Intent.ACTION_SEND, byteArray);
startActivity(Intent.createChooser(waIntent, "Share with"));
Run Code Online (Sandbox Code Playgroud)
但是那个代码不起作用。我的错误是什么?谢谢。
我的应用程序中出现“无法压缩回收的位图错误”。它发生picture.compress(Bitmap.CompressFormat.PNG, 90, fos);在我的代码中:
private void savePicture(byte[] data, String gameId, String folderName ) {
File pictureFile = getOutputMediaFile(gameId, folderName);
if (pictureFile == null){
Log.error("Error creating media file, check storage permissions.");
return;
}
Bitmap picture = BitmapFactory.decodeByteArray(data, 0, data.length);
picture = getResizedBitmap(picture, bitmapWidth, bitmapHeight);
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
picture.compress(Bitmap.CompressFormat.PNG, 90, fos);
fos.close();
picture.recycle();
Log.info(">>> CameraActivity: PICTURE SAVED!");
} catch (FileNotFoundException e) {
Log.error(LibUtil.getStackTrace(e));
} catch (IOException e) {
Log.error(LibUtil.getStackTrace(e));
}
}
public Bitmap getResizedBitmap(Bitmap bmp, int newWidth, …Run Code Online (Sandbox Code Playgroud) 我想brcc32使用32位位图编译资源文件,并且收到错误消息:Error: Invalid bitmap format。如果我将位图保存为24位格式,则可以成功编译该位图,但会失去透明度...确实不可能将透明位图作为资源使用,或者我错过了什么?